a
    `g9W                     @   s$  U d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ dZedZG d	d
 d
eZG dd dee ZG dd dZG dd dZG dd deZG dd deZe Z ee e!d< G dd dee Z"G dd de"e Z#dS )    N)		AwaitableCallableDequeFinalGenericListOptionalTupleTypeVar   )BaseProtocol)_EXC_SENTINELBaseTimerContext	TimerNoopset_exception
set_result)internal_logger)EMPTY_PAYLOAD	EofStreamStreamReader	DataQueue_Tc                   @   s   e Zd ZdZdS )r   zeof stream indication.N)__name__
__module____qualname____doc__ r   r   ]/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/aiohttp/streams.pyr   $   s   r   c                   @   sH   e Zd ZdZeg ee f ddddZdddd	Zedd
dZ	dS )AsyncStreamIterator	read_funcN)r    returnc                 C   s
   || _ d S Nr   )selfr    r   r   r   __init__,   s    zAsyncStreamIterator.__init__zAsyncStreamIterator[_T]r!   c                 C   s   | S r"   r   r#   r   r   r   	__aiter__/   s    zAsyncStreamIterator.__aiter__c                    s:   z|   I d H }W n ty(   tY n0 |dkr6t|S N    )r    r   StopAsyncIterationr#   rvr   r   r   	__anext__2   s    
zAsyncStreamIterator.__anext__)
r   r   r   	__slots__r   r   r   r$   r'   r-   r   r   r   r   r   (   s   r   c                   @   sD   e Zd ZdZdddddZd ddd	Zeeef dd
dZ	dS )ChunkTupleAsyncStreamIterator_streamr   N)streamr!   c                 C   s
   || _ d S r"   r0   )r#   r2   r   r   r   r$   @   s    z&ChunkTupleAsyncStreamIterator.__init__r%   c                 C   s   | S r"   r   r&   r   r   r   r'   C   s    z'ChunkTupleAsyncStreamIterator.__aiter__c                    s    | j  I d H }|dkrt|S )Nr)   F)r1   	readchunkr*   r+   r   r   r   r-   F   s    z'ChunkTupleAsyncStreamIterator.__anext__)
r   r   r   r.   r$   r'   r	   bytesboolr-   r   r   r   r   r/   <   s   r/   c                   @   sV   e Zd ZdZee dddZeee dddZee ddd	Z	e
dd
dZdS )AsyncStreamReaderMixinr   r%   c                 C   s
   t | jS r"   )r   readliner&   r   r   r   r'   Q   s    z AsyncStreamReaderMixin.__aiter__nr!   c                    s   t  fddS )z>Returns an asynchronous iterator that yields chunks of size n.c                      s
     S r"   )readr   r:   r#   r   r   <lambda>V   r)   z5AsyncStreamReaderMixin.iter_chunked.<locals>.<lambda>)r   r#   r:   r   r<   r   iter_chunkedT   s    z#AsyncStreamReaderMixin.iter_chunkedc                 C   s
   t | jS )z3Yield all available data as soon as it is received.)r   readanyr&   r   r   r   iter_anyX   s    zAsyncStreamReaderMixin.iter_anyc                 C   s   t | S )zYield 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.
        )r/   r&   r   r   r   iter_chunks\   s    z"AsyncStreamReaderMixin.iter_chunksN)r   r   r   r.   r   r5   r'   intr?   rA   r/   rB   r   r   r   r   r7   M   s
   r7   c                   @   s  e Zd ZdZdZdddeeee ee	j
 ddddZedd	d
Zeeef dddZee dddZefeeddddZeg df ddddZddddZedddZedddZddddZeddddZdAeedd!d"d#Zddd$d%Zddd&d'Zedd(d)d*Z edd+d,Z!dBeed.d/d0Z"dCeed2d3d4Z#edd5d6Z$eeef dd7d8Z%eed2d9d:Z&dDeed2d;d<Z'eed2d=d>Z(eed2d?d@Z)dS )Er   a*  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():
            ...

    )	_protocol
_low_water_high_water_loop_size_cursor_http_chunk_splits_buffer_buffer_offset_eof_waiter_eof_waiter
_exception_timer_eof_callbacks_eof_countertotal_bytesN)timerloop)protocollimitrU   rV   r!   c                C   s   || _ || _|d | _|d u r&t }|| _d| _d| _d | _t	
 | _d| _d| _d | _d | _d | _|d u rtt n|| _g | _d| _d| _d S )N   r   F)rD   rE   rF   asyncioget_event_looprG   rH   rI   rJ   collectionsdequerK   rL   rM   rN   rO   rP   r   rQ   rR   rS   rT   )r#   rW   rX   rU   rV   r   r   r   r$      s&    

zStreamReader.__init__r%   c                 C   s   | j jg}| jr |d| j  | jr0|d | jdkrP|d| j| jf  | jrf|d| j  | jr||d| j  dd	| S )	Nz%d byteseofi   zlow=%d high=%dzw=%rze=%r<%s> )
	__class__r   rH   appendrM   rE   rF   rN   rP   join)r#   infor   r   r   __repr__   s    


zStreamReader.__repr__c                 C   s   | j | jfS r"   )rE   rF   r&   r   r   r   get_read_buffer_limits   s    z#StreamReader.get_read_buffer_limitsc                 C   s   | j S r"   rP   r&   r   r   r   	exception   s    zStreamReader.exceptionexc	exc_causer!   c                 C   sT   || _ | j  | j}|d ur0d | _t||| | j}|d urPd | _t||| d S r"   )rP   rR   clearrN   r   rO   r#   rj   rk   waiterr   r   r   r      s    
zStreamReader.set_exceptioncallbackr!   c                 C   s@   | j r0z
|  W q< ty,   td Y q<0 n| j| d S NException in eof callback)rM   	Exceptionr   rh   rR   rb   r#   rp   r   r   r   on_eof   s    
zStreamReader.on_eofc              	   C   s   d| _ | j}|d ur$d | _t|d  | j}|d urBd | _t|d  | jjrT| j  | jD ],}z
|  W qZ ty   t	
d Y qZ0 qZ| j  d S )NTrr   )rM   rN   r   rO   rD   _reading_pausedresume_readingrR   rs   r   rh   rl   )r#   rn   cbr   r   r   feed_eof   s"    




zStreamReader.feed_eofc                 C   s   | j S )z&Return True if  'feed_eof' was called.rM   r&   r   r   r   is_eof   s    zStreamReader.is_eofc                 C   s   | j o| j S )z=Return True if the buffer is empty and 'feed_eof' was called.rM   rK   r&   r   r   r   at_eof   s    zStreamReader.at_eofc                    sH   | j r
d S | jd u sJ | j | _z| jI d H  W d | _nd | _0 d S r"   )rM   rO   rG   create_futurer&   r   r   r   wait_eof   s    zStreamReader.wait_eof)datar!   c                 C   sx   t jdtdd |sdS | jr>| jd | jd | jd< d| _|  jt|7  _|  jt|8  _| j| d| _	dS )zDrollback reading some data from stream, inserting it to buffer head.zJunread_data() is deprecated and will be removed in future releases (#3260)rY   )
stacklevelNr   )
warningswarnDeprecationWarningrL   rK   rH   lenrI   
appendleftrS   )r#   r   r   r   r   unread_data   s    zStreamReader.unread_datar   r   sizer!   c                 C   s   | j rJ d|sd S t|}|  j|7  _| j| |  j|7  _| j}|d urdd | _t|d  | j| jkr| j	j
s| j	  d S )Nzfeed_data after feed_eof)rM   r   rH   rK   rb   rT   rN   r   rF   rD   rv   pause_reading)r#   r   r   data_lenrn   r   r   r   	feed_data  s    
zStreamReader.feed_datac                 C   s"   | j d u r| jrtdg | _ d S )Nz@Called begin_http_chunk_receiving when some data was already fed)rJ   rT   RuntimeErrorr&   r   r   r   begin_http_chunk_receiving$  s    
z'StreamReader.begin_http_chunk_receivingc                 C   sd   | j d u rtd| j r"| j d nd}| j|kr4d S | j | j | j}|d ur`d | _t|d  d S )NzFCalled end_chunk_receiving without calling begin_chunk_receiving firstr   )rJ   r   rT   rb   rN   r   )r#   posrn   r   r   r   end_http_chunk_receiving,  s    


z%StreamReader.end_http_chunk_receiving)	func_namer!   c                    s~   | j jstd| jd ur&td| | j  }| _z:| j |I d H  W d    n1 s^0    Y  W d | _nd | _0 d S )NzConnection closed.zH%s() called while another coroutine is already waiting for incoming data)rD   	connectedr   rN   rG   r~   rQ   )r#   r   rn   r   r   r   _waitJ  s    
*zStreamReader._waitc                    s   |   I d H S r"   )	readuntilr&   r   r   r   r8   _  s    zStreamReader.readline   
)	separatorr!   c           	         s   t |}|dkrtd| jd ur(| jd}d}d}|r| jr|r| j}| jd ||d }| |rv|| | d nd}||7 }|t |7 }|rd}|| jkr8tdq8| jrq|r4| 	d	I d H  q4|S )
Nr   z,Separator should be at least one-byte stringr)   Tr   r   FzChunk too bigr   )
r   
ValueErrorrP   rK   rL   find_read_nowait_chunkrF   rM   r   )	r#   r   seplenchunk
chunk_sizeZ
not_enoughoffsetZicharr   r   r   r   r   b  s4    



zStreamReader.readuntilr   r9   c                    s   | j d ur| j | jrF| jsFt| ddd | _| jdkrFtjddd |sNdS |dk rg }|  I d H }|snqz|| qZd	|S | js| js| 
d	I d H  q| |S )
NrS   r   r      zEMultiple access to StreamReader in eof state, might be infinite loop.T)
stack_infor)   r;   )rP   rM   rK   getattrrS   r   warningr@   rb   rc   r   _read_nowait)r#   r:   blocksblockr   r   r   r;     s*    


zStreamReader.readc                    s8   | j d ur| j | js.| js.| dI d H  q| dS )Nr@   r   )rP   rK   rM   r   r   r&   r   r   r   r@     s
    
zStreamReader.readanyc                    s   | j dur| j | jrZ| jd}|| jkr0dS || jkrN| || j dfS td q| jrn| ddfS | j	rxdS | 
d	I dH  q dS )
a  Returns 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.
        Nr   r)   TTzESkipping HTTP chunk end due to data consumption beyond chunk boundaryr   Fr3   r4   )rP   rJ   poprI   r   r   r   rK   r   rM   r   )r#   r   r   r   r   r4     s     	


zStreamReader.readchunkc                    sp   | j d ur| j g }|dkrf| |I d H }|sNd|}t|t|| || |t|8 }qd|S )Nr   r)   )rP   r;   rc   rZ   IncompleteReadErrorr   rb   )r#   r:   r   r   partialr   r   r   readexactly  s    


zStreamReader.readexactlyc                 C   s2   | j d ur| j | jr(| j s(td| |S )Nz9Called while some coroutine is waiting for incoming data.)rP   rN   doner   r   r>   r   r   r   read_nowait  s    
zStreamReader.read_nowaitc                 C   s   | j d }| j}|dkrHt|| |krH||||  }|  j|7  _n,|rj| j   ||d  }d| _n
| j  }t|}|  j|8  _|  j|7  _| j}|r|d | jk r|d q| j| jk r| j	j
r| j	  |S )Nr   r   )rK   rL   r   popleftrH   rI   rJ   r   rE   rD   rv   rw   )r#   r:   Zfirst_bufferr   r   r   Zchunk_splitsr   r   r   r     s&    



zStreamReader._read_nowait_chunkc                 C   sZ   | j   g }| jrH| |}|| |dkr|t|8 }|dkrqHq|rVd|S dS )z6Read not more than n bytes, or whole buffer if n == -1r   r   r)   )rQ   Zassert_timeoutrK   r   rb   r   rc   )r#   r:   chunksr   r   r   r   r     s    


zStreamReader._read_nowait)r   )r   )r   )r   )*r   r   r   r   r.   r   rC   r   r   rZ   AbstractEventLoopr$   strre   r	   rf   BaseExceptionrh   r   r   r   ru   ry   r6   r{   r}   r   r5   r   r   r   r   r   r8   r   r;   r@   r4   r   r   r   r   r   r   r   r   r   e   sN   	$*"r   c                   @   s  e Zd ZdZddddZedddZee ddd	Z	e
feedd
ddZeg df ddddZddddZedddZedddZddddZd*eeddddZedddZd+eedd d!Zedd"d#Zeeef dd$d%Zeedd&d'Zd,eedd(d)ZdS )-EmptyStreamReader_read_eof_chunkNr%   c                 C   s   d| _ d| _d S )NFr   )r   rT   r&   r   r   r   r$   ,  s    zEmptyStreamReader.__init__c                 C   s   d| j j S )Nr_   )ra   r   r&   r   r   r   re   0  s    zEmptyStreamReader.__repr__c                 C   s   d S r"   r   r&   r   r   r   rh   3  s    zEmptyStreamReader.exceptionri   c                 C   s   d S r"   r   )r#   rj   rk   r   r   r   r   6  s    zEmptyStreamReader.set_exceptionro   c                 C   s,   z
|  W n t y&   td Y n0 d S rq   )rs   r   rh   rt   r   r   r   ru   =  s    
zEmptyStreamReader.on_eofc                 C   s   d S r"   r   r&   r   r   r   ry   C  s    zEmptyStreamReader.feed_eofc                 C   s   dS NTr   r&   r   r   r   r{   F  s    zEmptyStreamReader.is_eofc                 C   s   dS r   r   r&   r   r   r   r}   I  s    zEmptyStreamReader.at_eofc                    s   d S r"   r   r&   r   r   r   r   L  s    zEmptyStreamReader.wait_eofr   )r   r:   r!   c                 C   s   d S r"   r   )r#   r   r:   r   r   r   r   O  s    zEmptyStreamReader.feed_datac                    s   dS r(   r   r&   r   r   r   r8   R  s    zEmptyStreamReader.readliner   r9   c                    s   dS r(   r   r>   r   r   r   r;   U  s    zEmptyStreamReader.readc                    s   dS r(   r   r&   r   r   r   r@   Z  s    zEmptyStreamReader.readanyc                    s   | j sd| _ dS dS )NTr3   r   r   r&   r   r   r   r4   ]  s    zEmptyStreamReader.readchunkc                    s   t d|d S r(   )rZ   r   r>   r   r   r   r   d  s    zEmptyStreamReader.readexactlyc                 C   s   dS r(   r   r>   r   r   r   r   g  s    zEmptyStreamReader.read_nowait)r   )r   )r   )r   r   r   r.   r$   r   re   r   r   rh   r   r   r   ru   ry   r6   r{   r}   r   r5   rC   r   r8   r;   r@   r	   r4   r   r   r   r   r   r   r   (  s,   r   r   c                   @   s   e Zd ZdZejddddZedddZe	dd	d
Z
e	dddZee dddZefeeddddZdeeddddZddddZedddZee dddZdS )r   z>DataQueue is a general-purpose blocking queue with one reader.N)rV   r!   c                 C   s&   || _ d| _d | _d | _t | _d S )NF)rG   rM   rN   rP   r\   r]   rK   )r#   rV   r   r   r   r$   q  s
    zDataQueue.__init__r%   c                 C   s
   t | jS r"   )r   rK   r&   r   r   r   __len__x  s    zDataQueue.__len__c                 C   s   | j S r"   rz   r&   r   r   r   r{   {  s    zDataQueue.is_eofc                 C   s   | j o| j S r"   r|   r&   r   r   r   r}   ~  s    zDataQueue.at_eofc                 C   s   | j S r"   rg   r&   r   r   r   rh     s    zDataQueue.exceptionri   c                 C   s0   d| _ || _| j }d ur,d | _t||| d S r   )rM   rP   rN   r   rm   r   r   r   r     s
    zDataQueue.set_exceptionr   r   c                 C   s2   | j ||f | j }d ur.d | _t|d  d S r"   )rK   rb   rN   r   )r#   r   r   rn   r   r   r   r     s    zDataQueue.feed_datac                 C   s(   d| _ | j }d ur$d | _t|d  d S r   )rM   rN   r   )r#   rn   r   r   r   ry     s    zDataQueue.feed_eofc              	      s   | j sV| jsV| jrJ | j | _z| jI d H  W n" tjtjfyT   d | _ Y n0 | j rn| j  \}}|S | j	d ur~| j	t
d S r"   )rK   rM   rN   rG   r~   rZ   CancelledErrorTimeoutErrorr   rP   r   )r#   r   _r   r   r   r;     s    

zDataQueue.readc                 C   s
   t | jS r"   )r   r;   r&   r   r   r   r'     s    zDataQueue.__aiter__)r   )r   r   r   r   rZ   r   r$   rC   r   r6   r{   r}   r   r   rh   r   r   r   r   ry   r;   r   r'   r   r   r   r   r   n  s    r   c                       sT   e Zd ZdZeeejdd fddZde	edd fdd	Z
e	d
ddZ  ZS )FlowControlDataQueuezFlowControlDataQueue resumes and pauses an underlying stream.

    It is a destination for parsed data.

    This class is deprecated and will be removed in version 4.0.
    N)rW   rX   rV   r!   c                   s(   t  j|d d| _|| _|d | _d S )N)rV   r   rY   )superr$   rH   rD   _limit)r#   rW   rX   rV   ra   r   r   r$     s    zFlowControlDataQueue.__init__r   r   c                    s>   t  || |  j|7  _| j| jkr:| jjs:| j  d S r"   )r   r   rH   r   rD   rv   r   r#   r   r   r   r   r   r     s    zFlowControlDataQueue.feed_datar%   c              	      s   | j sV| jsV| jrJ | j | _z| jI d H  W n" tjtjfyT   d | _ Y n0 | j r| j  \}}|  j	|8  _	| j	| j
k r| jjr| j  |S | jd ur| jtd S r"   )rK   rM   rN   rG   r~   rZ   r   r   r   rH   r   rD   rv   rw   rP   r   r   r   r   r   r;     s"    


zFlowControlDataQueue.read)r   )r   r   r   r   r   rC   rZ   r   r$   r   r   r;   __classcell__r   r   r   r   r     s   r   )$rZ   r\   r   typingr   r   r   r   r   r   r   r	   r
   Zbase_protocolr   helpersr   r   r   r   r   logr   __all__r   rs   r   r   r/   r7   r   r   r   __annotations__r   r   r   r   r   r   <module>   s(   
,   FCA