U '7`2P@s8ddlZddlZddlZddlmZmZmZmZmZm Z m Z ddl m Z ddl mZmZmZddlmZzddlmZWn ek rddlmZYnXdZe d ZGd d d eZGd d d eeZGdddZGdddZGdddeZGdddeZeZGdddeeZ Gddde eZ!dS)N) AwaitableCallableGenericListOptionalTupleTypeVar) BaseProtocol)BaseTimerContext set_exception set_result)internal_logger)Deque) EMPTY_PAYLOAD EofStream StreamReader DataQueueFlowControlDataQueue_Tc@seZdZdZdS)rzeof stream indication.N)__name__ __module__ __qualname____doc__rrB/opt/alt/python38/lib64/python3.8/site-packages/aiohttp/streams.pyrsrc@sDeZdZegeefddddZddddZedd d ZdS) AsyncStreamIteratorN) read_funcreturncCs ||_dSN)r)selfrrrr__init__szAsyncStreamIterator.__init__zAsyncStreamIterator[_T]rcCs|Srrr rrr __aiter__"szAsyncStreamIterator.__aiter__cs<z|IdH}Wntk r*tYnX|dkr8t|SN)rrStopAsyncIterationr rvrrr __anext__%s zAsyncStreamIterator.__anext__) rrrrrrr!r$r*rrrrrsrc@s@eZdZdddddZddddZeeefdd d ZdS) ChunkTupleAsyncStreamIteratorrN)streamrcCs ||_dSr)_stream)r r,rrrr!0sz&ChunkTupleAsyncStreamIterator.__init__r"cCs|Srrr#rrrr$3sz'ChunkTupleAsyncStreamIterator.__aiter__cs |jIdH}|dkrt|S)Nr&F)r- readchunkr'r(rrrr*6sz'ChunkTupleAsyncStreamIterator.__anext__) rrrr!r$rbytesboolr*rrrrr+/sr+c@sReZdZeedddZeeedddZeedddZe dd d Z d S) AsyncStreamReaderMixinr"cCs t|jSr)rreadliner#rrrr$>sz AsyncStreamReaderMixin.__aiter__nrcstfddS)zzReturns an asynchronous iterator that yields chunks of size n. Python-3.5 available for Python 3.5+ only cs Sr)readrr5r rrFr&z5AsyncStreamReaderMixin.iter_chunked..)rr r5rr7r iter_chunkedAsz#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 )rreadanyr#rrriter_anyHszAsyncStreamReaderMixin.iter_anycCst|S)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+r#rrr iter_chunksPsz"AsyncStreamReaderMixin.iter_chunksN) rrrrr0r$intr:r<r+r=rrrrr2=sr2c@seZdZdZdZdddeeeeee j ddddZ e dd d Z eeefdd d Zeedd dZeddddZegdfddddZddddZedddZedddZddddZeddddZdeed-d6d7Z%eed-d8d9Z&eed-d:d;Z'dS)?ra*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(): ... rN)timerloop)protocollimitr?r@rcCsv||_||_|d|_|dkr&t}||_d|_d|_d|_t |_ d|_ d|_ d|_d|_d|_||_g|_dS)NrF) _protocol _low_water _high_waterasyncioZget_event_loop_loop_size_cursor_http_chunk_splits collectionsdeque_buffer_buffer_offset_eof_waiter _eof_waiter _exception_timer_eof_callbacks)r rArBr?r@rrrr!js"  zStreamReader.__init__r"cCs|jjg}|jr |d|j|jr0|d|jdkrP|d|j|jf|jrf|d|j|jr||d|jdd |S) Nz%d byteseofizlow=%d high=%dzw=%rze=%rz<%s> ) __class__rrIappendrPrErFrQrSjoin)r inforrr__repr__s   zStreamReader.__repr__cCs |j|jfSr)rErFr#rrrget_read_buffer_limitssz#StreamReader.get_read_buffer_limitscCs|jSrrSr#rrr exceptionszStreamReader.exceptionexcrcCsP||_|j|j}|dk r.d|_t|||j}|dk rLd|_t||dSr)rSrUclearrQr rRr rawaiterrrrr s  zStreamReader.set_exceptioncallbackrcCsB|jr2z |Wq>tk r.tdYq>Xn |j|dSNException in eof callback)rP Exceptionrr_rUrYr rfrrron_eofs  zStreamReader.on_eofc Csd|_|j}|dk r$d|_t|d|j}|dk rBd|_t|d|jD].}z |WqHtk rttdYqHXqH|jdS)NTrh) rPrQr rRrUrirr_rb)r rdcbrrrfeed_eofs    zStreamReader.feed_eofcCs|jS)z&Return True if 'feed_eof' was called.rPr#rrris_eofszStreamReader.is_eofcCs|jo |j S)z=Return True if the buffer is empty and 'feed_eof' was called.rPrNr#rrrat_eofszStreamReader.at_eofcsB|jr dS|jdkst|j|_z|jIdHW5d|_XdSr)rPrRAssertionErrorrH create_futurer#rrrwait_eofs zStreamReader.wait_eof)datarcCsxtjdtdd|sdS|jr>|jd|jd|jd<d|_|jt|7_|jt|8_|j|d|_ dS)zDrollback reading some data from stream, inserting it to buffer head.zJunread_data() is deprecated and will be removed in future releases (#3260)rC) stacklevelNr) warningswarnDeprecationWarningrOrNrIlenrJ appendleft _eof_counter)r rurrr unread_datas zStreamReader.unread_datarusizercCs|jrtd|sdS|jt|7_|j||jt|7_|j}|dk rdd|_t|d|j|j kr|j j s|j dS)Nzfeed_data after feed_eof) rPrrrIrzrNrY total_bytesrQr rFrD_reading_paused pause_readingr rurrdrrr feed_datas  zStreamReader.feed_datacCs"|jdkr|jrtdg|_dS)Nz?Called begin_http_chunk_receiving whensome data was already fed)rKr RuntimeErrorr#rrrbegin_http_chunk_receivings  z'StreamReader.begin_http_chunk_receivingcCsd|jdkrtd|jr"|jdnd}|j|kr4dS|j|j|j}|dk r`d|_t|ddS)NzFCalled end_chunk_receiving without calling begin_chunk_receiving firstr)rKrrrYrQr )r posrdrrrend_http_chunk_receivings   z%StreamReader.end_http_chunk_receiving) func_namerc sf|jdk rtd||j}|_z2|jrL|j|IdHW5QRXn |IdHW5d|_XdS)NzH%s() called while another coroutine is already waiting for incoming data)rQrrHrsrT)r rrdrrr_wait#s zStreamReader._waitcs|jdk r|jg}d}d}|r|jr|r|j}|jdd|d}||rV||nd}|||t|7}|rzd}||jkr tdq |j rq|r| dIdHqd |S) NrT r rFzLine is too longr3r&) rSrNrOfind_read_nowait_chunkrYrzrF ValueErrorrPrrZ)r lineZ line_sizeZ not_enoughoffsetZicharrurrrr38s*      zStreamReader.readlinerr4cs|jdk r|j|jrF|jsFt|ddd|_|jdkrFtjddd|sNdS|dkrg}|IdH}|snqz||qZd |S|js|js| d IdHq| |S) Nr|rr zEMultiple access to StreamReader in eof state, might be infinite loop.T)Z stack_infor&r6) rSrPrNgetattrr|rwarningr;rYrZr _read_nowait)r r5blocksblockrrrr6Vs*      zStreamReader.readcs8|jdk r|j|js.|js.|dIdHq|dS)Nr;r)rSrNrPrrr#rrrr;s   zStreamReader.readanycs|jdk r|j|jrZ|jd}||jkr0dS||jkrN|||jdfStdq|jrn|ddfS|j rxdS| d IdHqdS) 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. Nrr&TTzESkipping HTTP chunk end due to data consumption beyond chunk boundaryrFr.r/) rSrKpoprJrrrrNrrPr)r rrrrr/s     zStreamReader.readchunkcsp|jdk r|jg}|dkrf||IdH}|sNd|}t|t|||||t|8}qd|S)Nrr&)rSr6rZrGIncompleteReadErrorrzrY)r r5rrpartialrrr readexactlys   zStreamReader.readexactlycCs2|jdk r|j|jr(|js(td||S)Nz9Called while some coroutine is waiting for incoming data.)rSrQZdonerrr9rrr read_nowaits zStreamReader.read_nowaitcCs|jd}|j}|dkrHt|||krH||||}|j|7_n,|rj|j||d}d|_n |j}|jt|8_|jt|7_|j}|r|d|jkr|dq|j|jkr|j j r|j |S)Nrr) rNrOrzpopleftrIrJrKrrErDrresume_reading)r r5Z first_bufferrruZ chunk_splitsrrrrs$      zStreamReader._read_nowait_chunkcCsPg}|jr>||}|||dkr|t|8}|dkrq>q|rLd|SdS)z8 Read not more than n bytes, or whole buffer if n == -1 rrr&)rNrrYrzrZ)r r5Zchunkschunkrrrrs   zStreamReader._read_nowait)r)r)r)(rrrrrr r>rr rGAbstractEventLoopr!strr\rr] BaseExceptionr_r rrkrmr1rorqrtr0r}rrrrr3r6r;r/rrrrrrrrrZsB    *  rc@seZdZeedddZeddddZegdfddd d Zddd d Z e dd dZ e dddZ ddddZ d%eeddddZedddZd&eedddZedddZeee fddd Zeedd!d"Zedd#d$ZdS)'EmptyStreamReaderr"cCsdSrrr#rrrr_szEmptyStreamReader.exceptionNr`cCsdSrr)r rarrrr szEmptyStreamReader.set_exceptionrecCs.z |Wntk r(tdYnXdSrg)rirr_rjrrrrks zEmptyStreamReader.on_eofcCsdSrrr#rrrrmszEmptyStreamReader.feed_eofcCsdSNTrr#rrrroszEmptyStreamReader.is_eofcCsdSrrr#rrrrqszEmptyStreamReader.at_eofcsdSrrr#rrrrt szEmptyStreamReader.wait_eofr)rur5rcCsdSrr)r rur5rrrr szEmptyStreamReader.feed_datacsdSr%rr#rrrr3szEmptyStreamReader.readlinerr4csdSr%rr9rrrr6szEmptyStreamReader.readcsdSr%rr#rrrr;szEmptyStreamReader.readanycsdS)Nrrr#rrrr/szEmptyStreamReader.readchunkcstd|dSr%)rGrr9rrrrszEmptyStreamReader.readexactlycCsdSr%rr#rrrrszEmptyStreamReader.read_nowait)r)r)rrrrrr_r rrkrmr1rorqrtr0r>rr3r6r;rr/rrrrrrrsrc@seZdZdZejddddZedddZe dd d Z e dd d Z e e dd dZe ddddZdeeddddZddddZedddZeedddZdS)rz>DataQueue is a general-purpose blocking queue with one reader.N)r@rcCs,||_d|_d|_d|_d|_t|_dS)NFr)rHrPrQrSrIrLrMrN)r r@rrrr!)s zDataQueue.__init__r"cCs t|jSr)rzrNr#rrr__len__1szDataQueue.__len__cCs|jSrrnr#rrrro4szDataQueue.is_eofcCs|jo |j Srrpr#rrrrq7szDataQueue.at_eofcCs|jSrr^r#rrrr_:szDataQueue.exceptionr`cCs.d|_||_|j}|dk r*d|_t||dSr)rPrSrQr rcrrrr =s zDataQueue.set_exceptionrr~cCs@|j|7_|j||f|j}|dk rrr1rorqrrr_r rrrmr6rr$rrrrr&s  rcsXeZdZdZeeejddfdd Zd e eddfdd Z e d fd d Z Z S)rzgFlowControlDataQueue resumes and pauses an underlying stream. It is a destination for parsed data.N)rArBr@rcs"tj|d||_|d|_dS)N)r@rC)superr!rD_limit)r rArBr@rXrrr!tszFlowControlDataQueue.__init__rr~cs0t|||j|jkr,|jjs,|jdSr)rrrIrrDrrrrrrr|szFlowControlDataQueue.feed_datar"cs:ztIdHWS|j|jkr4|jjr4|jXdSr)rIrrDrrrr6r#rrrr6szFlowControlDataQueue.read)r) rrrrr r>rGrr!rrr6 __classcell__rrrrrosr)"rGrLrwtypingrrrrrrrZ base_protocolr Zhelpersr r r logrr ImportErrorZtyping_extensions__all__rrirrr+r2rrrrrrrrrs0$  /I