Viewing File: /opt/alt/python35/lib64/python3.5/site-packages/aiohttp/__pycache__/streams.cpython-35.opt-1.pyc



Z?A@sddlZddlZddlmZmZddlmZddddd	fZd
dZGddde	Z
Gd
ddZGdddeZGdddZ
Gddde
ZGddde
ZeZGdddZGdd	d	eZdS)N)
set_exception
set_result)internal_logger
EMPTY_PAYLOAD	EofStreamStreamReader	DataQueueFlowControlDataQueuec@seZdZdZdS)rzeof stream indication.N)__name__
__module____qualname____doc__rr/streams.pyrsc@s4eZdZddZddZddZdS)AsyncStreamIteratorcCs
||_dS)N)	read_func)selfrrrr__init__szAsyncStreamIterator.__init__cCs|S)Nr)rrrr	__aiter__szAsyncStreamIterator.__aiter__csFy|jIdH}Wntk
r/tYnX|dkrBt|S)N)rrStopAsyncIteration)rrvrrr	__anext__s
zAsyncStreamIterator.__anext__N)r
rrrrrrrrrrsrc@seZdZddZdS)ChunkTupleAsyncStreamIteratorcs'|jIdH}|dkr#t|S)NrF)rF)rr)rrrrrr&sz'ChunkTupleAsyncStreamIterator.__anext__N)r
rrrrrrrr%src@s@eZdZddZddZddZddZd	S)
AsyncStreamReaderMixincCs
t|jS)N)rreadline)rrrrr/sz AsyncStreamReaderMixin.__aiter__cstfddS)zzReturns an asynchronous iterator that yields chunks of size n.

        Python-3.5 available for Python 3.5+ only
        cs
jS)N)readr)nrrr<lambda>7sz5AsyncStreamReaderMixin.iter_chunked.<locals>.<lambda>)r)rr r)r rriter_chunked2sz#AsyncStreamReaderMixin.iter_chunkedcCs
t|jS)zReturns an asynchronous iterator that yields all the available
        data as soon as it is received

        Python-3.5 available for Python 3.5+ only
        )rreadany)rrrriter_any9szAsyncStreamReaderMixin.iter_anycCs
t|jS)a
Returns an asynchronous iterator that yields chunks of data
        as they are received by the server. The yielded objects are tuples
        of (bytes, bool) as returned by the StreamReader.readchunk method.

        Python-3.5 available for Python 3.5+ only
        )r	readchunk)rrrriter_chunksAsz"AsyncStreamReaderMixin.iter_chunksN)r
rrrr"r$r&rrrrr-src@s?eZdZdZdZdeddddddZd	d
ZddZd
dZ	ddZ
ddZddZddZ
ddZddZdddZddZdd Zd!d"Zd#d$Zd4d&d'Zd(d)Zd*d+Zd,d-Zd5d.d/Zd0d1Zd2d3ZdS)6ra*An enhancement of asyncio.StreamReader.

    Supports asynchronous iteration by line, chunk or as available::

        async for line in reader:
            ...
        async for chunk in reader.iter_chunked(1024):
            ...
        async for slice in reader.iter_any():
            ...

    rlimittimerNloopcCs||_||_|d|_|dkr7tj}||_d|_d|_d|_t	j
|_d|_d|_
d|_d|_d|_||_g|_dS)NrrF)	_protocol
_low_water_high_waterasyncioZget_event_loop_loop_size_cursor_http_chunk_splitscollectionsdeque_buffer_buffer_offset_eof_waiter_eof_waiter
_exception_timer_eof_callbacks)rprotocolr'r(r)rrrr[s"		
										zStreamReader.__init__cCs|jjg}|jr,|jd|j|jrB|jd|jtkrn|jd|j|jf|jr|jd|j|j	r|jd|j	ddj
|S)Nz%d byteseofzlow=%d high=%dzw=%rze=%rz<%s> )	__class__r
r/appendr6r+
DEFAULT_LIMITr,r7r9join)rinforrr__repr__os		
		zStreamReader.__repr__cCs|jS)N)r9)rrrr	exception}szStreamReader.exceptioncCsp||_|jj|j}|dk	rAd|_t|||j}|dk	rlt||d|_dS)N)r9r;clearr7rr8)rexcwaiterrrrrs	
		
	
zStreamReader.set_exceptioncCsM|jr9y|WqItk
r5tjdYqIXn|jj|dS)NzException in eof callback)r6	ExceptionrrEr;r@)rcallbackrrron_eofs	
zStreamReader.on_eofcCsd|_|j}|dk	r4d|_t|d|j}|dk	r_d|_t|dx>|jD]3}y|Wqitk
rtjdYqiXqiW|jjdS)NTzException in eof callback)	r6r7rr8r;rIrrErF)rrHcbrrrfeed_eofs			
		

zStreamReader.feed_eofcCs|jS)z&Return True if  'feed_eof' was called.)r6)rrrris_eofszStreamReader.is_eofcCs|jo|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)r6r4)rrrrat_eofszStreamReader.at_eofcs@|jr
dS|jj|_z|jIdHWdd|_XdS)N)r6r.
create_futurer8)rrrrwait_eofs	zStreamReader.wait_eofcCs|s
dS|jr=|jd|jd|jd<d|_|jt|7_|jt|8_|jj|d|_dS)zN rollback reading some data from stream, inserting it to buffer head.
        Nr)r5r4r/lenr0
appendleftZ_eof_counter)rdatarrrunread_datas	!	zStreamReader.unread_datacCs|s
dS|jt|7_|jj||jt|7_|j}|dk	rod|_t|d|j|jkr|jj	r|jj
dS)NF)r/rRr4r@total_bytesr7rr,r*_reading_paused
pause_reading)rrTsizerHrrr	feed_datas		

zStreamReader.feed_datacCs|jdkrg|_dS)N)r1)rrrrbegin_http_chunk_receivingsz'StreamReader.begin_http_chunk_receivingcCsR|jdkrtd|js;|jd|jkrN|jj|jdS)NzFCalled end_chunk_receiving without calling begin_chunk_receiving firstr)r1RuntimeErrorrVr@)rrrrend_http_chunk_receivings

z%StreamReader.end_http_chunk_receivingcsy|jdk	rtd||jj}|_z3|jr^|j|IdHWdQRXn	|IdHWdd|_XdS)NzH%s() called while another coroutine is already waiting for incoming data)r7r]r.rPr:)r	func_namerHrrr_waits
	

zStreamReader._waitcs|jdk	r|jg}d}d}x|rx|jr|r|j}|jdjd|d}|j|r||nd	}|j||t|7}|rd}||jkr6tdq6W|j	rP|r-|j
dIdHq-Wdj|S)
NrTs
rFzLine is too longrrr\)r9r4r5find_read_nowait_chunkr@rRr,
ValueErrorr6r`rB)rlineZ	line_sizeZ
not_enoughoffsetZicharrTrrrrs*			
	zStreamReader.readlinercs|jdk	r|j|s"dS|dkrmg}x)|jIdH}|sOP|j|q7Wdj|S|jr|jr|jdIdH|j|S)Nrrr)r9r#r@rBr4r6r`_read_nowait)rr blocksblockrrrrs	
zStreamReader.readcsK|jdk	r|j|jr>|jr>|jdIdH|jdS)Nr#rr\)r9r4r6r`rf)rrrrr#Cs
	zStreamReader.readanycs|jdk	r|j|jrw|jrw|jre|j|jdkre|jdd|_dS|jdIdH|jsd	S|jdk	rxY|jr|jd}|jdd|_||jkr|j||jdfSqW|jd
dfS|jddfSdS)zReturns a tuple of (data, end_of_http_chunk). When chunked transfer
        encoding is used, end_of_http_chunk is a boolean indicating if the end
        of the data corresponds to the end of a HTTP chunk , otherwise it is
        always False.
        NrrrTr%F)rT)rFr\r\)r9r4r6r1r0r`rfrb)rposrrrr%Ls$			
zStreamReader.readchunkcs|jdk	r|jg}xu|dkr|j|IdH}|sudj|}tjj|t|||j||t|8}q!Wdj|S)Nrr)r9rrBr-streamsIncompleteReadErrorrRr@)rr rgrhpartialrrrreadexactlyjs		
zStreamReader.readexactlycCsJ|jdk	r|j|jr=|jjr=td|j|S)Nz9Called while some coroutine is waiting for incoming data.)r9r7doner]rf)rr rrrread_nowaitzs		zStreamReader.read_nowaitcCs|jd}|j}|dkr^t|||kr^||||}|j|7_n>|r|jj||d}d|_n|jj}|jt|8_|jt|7_|j|jkr|jjr|jj	|S)Nrrr\)
r4r5rRpopleftr/r0r+r*rWresume_reading)rr Zfirst_bufferrerTrrrrbs
	"

zStreamReader._read_nowait_chunkcCsrg}xR|jrZ|j|}|j||dkr	|t|8}|dkr	Pq	W|rndj|SdS)Nrrrr\)r4rbr@rRrB)rr Zchunkschunkrrrrfs
zStreamReader._read_nowaitr\r\)r
rrrrVrArrDrErrKrMrNrOrQrUrZr[r^r`rrr#r%rmrorbrfrrrrrKs2	%	c@seZdZddZddZddZddZd	d
ZddZd
dZ	ddZ
ddZdddZddZ
ddZddZddZdS) EmptyStreamReadercCsdS)Nr)rrrrrEszEmptyStreamReader.exceptioncCsdS)Nr)rrGrrrrszEmptyStreamReader.set_exceptioncCs1y|Wntk
r,tjdYnXdS)NzException in eof callback)rIrrE)rrJrrrrKs
zEmptyStreamReader.on_eofcCsdS)Nr)rrrrrMszEmptyStreamReader.feed_eofcCsdS)NTr)rrrrrNszEmptyStreamReader.is_eofcCsdS)NTr)rrrrrOszEmptyStreamReader.at_eofcsdS)Nr)rrrrrQszEmptyStreamReader.wait_eofcCsdS)Nr)rrTrrrrZszEmptyStreamReader.feed_datacsdS)Nrr)rrrrrszEmptyStreamReader.readlinercsdS)Nrr)rr rrrrszEmptyStreamReader.readcsdS)Nrr)rrrrr#szEmptyStreamReader.readanycsdS)NrF)rFr)rrrrr%szEmptyStreamReader.readchunkcstjjd|dS)Nr)r-rjrk)rr rrrrmszEmptyStreamReader.readexactlycCsdS)Nrr)rrrrroszEmptyStreamReader.read_nowaitNr\)r
rrrErrKrMrNrOrQrZrrr#r%rmrorrrrrssrsc@seZdZdZddddZddZdd	Zd
dZdd
ZddZ	dddZ
ddZddZddZ
dS)r	z>DataQueue is a general-purpose blocking queue with one reader.r)NcCs@||_d|_d|_d|_d|_tj|_dS)NFr)r.r6r7r9r/r2r3r4)rr)rrrrs					zDataQueue.__init__cCs
t|jS)N)rRr4)rrrr__len__szDataQueue.__len__cCs|jS)N)r6)rrrrrNszDataQueue.is_eofcCs|jo|jS)N)r6r4)rrrrrOszDataQueue.at_eofcCs|jS)N)r9)rrrrrEszDataQueue.exceptioncCsAd|_||_|j}|dk	r=t||d|_dS)NT)r6r9r7r)rrGrHrrrrs			
zDataQueue.set_exceptionrcCsT|j|7_|jj||f|j}|dk	rPd|_t|ddS)NT)r/r4r@r7r)rrTrYrHrrrrZs		zDataQueue.feed_datacCs8d|_|j}|dk	r4d|_t|ddS)NTF)r6r7r)rrHrrrrMs
			zDataQueue.feed_eofcs|jrc|jrc|jj|_y|jIdHWn*tjtjfk
rbd|_YnX|jr|jj\}}|j	|8_	|S|j
dk	r|j
ntdS)N)r4r6r.rPr7r-CancelledErrorTimeoutErrorrpr/r9r)rrTrYrrrrs		zDataQueue.readcCs
t|jS)N)rr)rrrrr$szDataQueue.__aiter__)r
rrrrrtrNrOrErrZrMrrrrrrr	s		csXeZdZdZdeddfddZfddZfd	d
ZS)r
zgFlowControlDataQueue resumes and pauses an underlying stream.

    It is a destination for parsed data.r'r)Ncs-tjd|||_|d|_dS)Nr)r)superrr*_limit)rr<r'r))r?rrr-s	zFlowControlDataQueue.__init__csCtj|||j|jkr?|jjr?|jjdS)N)rwrZr/rxr*rWrX)rrTrY)r?rrrZ3szFlowControlDataQueue.feed_datacsIztjIdHSWd|j|jkrD|jjrD|jjXdS)N)rwrr/rxr*rWrq)r)r?rrr9szFlowControlDataQueue.read)r
rrrrArrZrrr)r?rr
(s)r-r2Zhelpersrrlogr__all__rArIrrrrrrsrr	r
rrrr<module>s 	
b0	I
Back to Directory File Manager