o
    4˜Žjž1  ã                   @   s¾   d dl Z d dlmZ d dl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mZmZmZmZmZ ddlmZmZ dd	lmZ dd
lmZmZmZ G dd„ deeeeef  ƒZdS )é    N)Úsuppress)ÚAnyÚCallableé   )ÚBaseProtocol)ÚClientConnectionErrorÚClientOSErrorÚClientPayloadErrorÚServerDisconnectedErrorÚSocketTimeoutError)Ú_EXC_SENTINELÚDEFAULT_CHUNK_SIZEÚEMPTY_BODY_STATUS_CODESÚBaseTimerContextÚset_exceptionÚ
set_result)ÚHttpResponseParserÚRawResponseMessage)ÚHttpProcessingError)ÚEMPTY_PAYLOADÚ	DataQueueÚStreamReaderc                       sè  e Zd ZdZdejddfdd„Zeddejd B fdd„ƒZ	ede
fd	d
„ƒZede
fdd„ƒZdGdd„ZdGdd„ZdGdd„Zde
fdd„ZdedB ddf‡ fdd„ZdGdd„ZdG‡ fdd„ZdHde
ddf‡ fdd„Zefded eddf‡ fd!d"„Z	dId#ed$ed%eg df dB ddfd&d'„Zdd(d(dded)d*d*d+d,œ
d-edB d.e
d/e
d0e
d1edB d2ed3ed4ed5ed6eddfd7d8„ZdGd9d:„Z dGd;d<„Z!dGd=d>„Z"ededB fd?d@„ƒZ#e#j$d1edB ddfdAd@„ƒZ#dGdBdC„Z%dDe&ddfdEdF„Z'‡  Z(S )JÚResponseHandlerz8Helper class to adapt between Protocol and StreamReader.ÚloopÚreturnNc                 C   sh   t j| |d d� t | |¡ d| _d | _d| _d | _d | _d | _d| _	d | _
d | _d| _d | _d| _d S )N)r   ÚparserFó    é   )r   Ú__init__r   Ú_should_closeÚ_payloadÚ_skip_payloadÚ_payload_parserÚ_data_received_cbÚ_timerÚ_tailÚ_read_timeoutÚ_read_timeout_handleÚ_timeout_ceil_thresholdÚ_closedÚ_connection_lost_called)Úselfr   © r,   úQ/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/aiohttp/client_proto.pyr      s   
zResponseHandler.__init__c                 C   s"   | j du r| js| j ¡ | _ | j S )a6  Future that is set when the connection is closed.

        This property returns a Future that will be completed when the connection
        is closed. The Future is created lazily on first access to avoid creating
        futures that will never be awaited.

        Returns:
            - A Future[None] if the connection is still open or was closed after
              this property was accessed
            - None if connection_lost() was already called before this property
              was ever accessed (indicating no one is waiting for the closure)
        N)r)   r*   Ú_loopÚcreate_future©r+   r,   r,   r-   Úclosed3   s   zResponseHandler.closedc                 C   ó   | j S ©N)Ú	_upgradedr0   r,   r,   r-   ÚupgradedE   ó   zResponseHandler.upgradedc                 C   sF   t | jp!| jd uo| j ¡  p!| jp!| jd up!| jd up!| jp!| jƒS r3   )	Úboolr   r    Úis_eofr4   Ú
_exceptionr"   Ú_bufferr%   r0   r,   r,   r-   Úshould_closeI   s   ÿþýüûùzResponseHandler.should_closec                 C   s
   d| _ d S ©NT)r   r0   r,   r,   r-   Úforce_closeU   s   
zResponseHandler.force_closec                 C   ó8   d | _ | j}|d ur| ¡  d | _d | _|  ¡  d S d S r3   )r9   Ú	transportÚcloser    Ú_drop_timeout©r+   r?   r,   r,   r-   r@   X   ó   üzResponseHandler.closec                 C   r>   r3   )r9   r?   Úabortr    rA   rB   r,   r,   r-   rD   a   rC   zResponseHandler.abortc                 C   s   | j d uo
| j  ¡  S r3   )r?   Ú
is_closingr0   r,   r,   r-   Úis_connectedj   s   zResponseHandler.is_connectedÚexcc           	   
      sš  d| _ |  ¡  |}|}|d u }| jd ur/|rt| jd ƒ n|d us#J ‚t| jtd|›�ƒ|ƒ | jd urMttƒ� | j 	¡  W d   ƒ n1 sHw   Y  d }| j
d urŠz| j
 	¡ }W n. ty‰ } z"| jd urd|›�}|sv|›d|›�}t| jt|ƒ|ƒ W Y d }~nd }~ww |  ¡ s¶t|tƒr˜t|jŽ }|ržt|ƒ}|r¢tn|}|d usªJ ‚|d us°J ‚|  ||¡ d| _d | _
d | _d | _d| _tƒ  |¡ d S )NTzConnection lost: z#Response payload is not completed: z. F)r*   rA   r)   r   r   r   r"   r   Ú	ExceptionÚfeed_eofÚ_parserr    r	   r8   Ú
isinstanceÚOSErrorr   Úargsr
   r   r   Ú_reading_pausedÚsuperÚconnection_lost)	r+   rG   Úoriginal_connection_errorÚreraised_excÚconnection_closed_cleanlyÚuncompletedÚunderlying_excÚclient_payload_exc_msgÚunderlying_non_eof_exc©Ú	__class__r,   r-   rP   m   st   
ÿû

ÿ

ÿÿÿý€ö

ÿýzResponseHandler.connection_lostc                 C   ó   |   ¡  d S r3   )rA   r0   r,   r,   r-   Úeof_received¸   s   zResponseHandler.eof_receivedc                    s   t ƒ  ¡  |  ¡  d S r3   )rO   Úpause_readingrA   r0   rX   r,   r-   r\   ¼   s   
zResponseHandler.pause_readingTÚresume_parserc                    s&   | j }tƒ  |¡ |r|  ¡  d S d S r3   )rN   rO   Úresume_readingÚ_reschedule_timeout)r+   r]   Ú
was_pausedrX   r,   r-   r^   À   s
   ÿzResponseHandler.resume_readingÚ	exc_causec                    s    d| _ |  ¡  tƒ  ||¡ d S r<   )r   rA   rO   r   )r+   rG   ra   rX   r,   r-   r   Æ   s   zResponseHandler.set_exceptionr   ÚpayloadÚdata_received_cbc                 C   s@   || _ || _|| _|  ¡  | jr| jd}| _|  |¡ d S d S )Nr   )r    r"   r#   rA   r%   Údata_received)r+   r   rb   rc   Údatar,   r,   r-   Ú
set_parserÏ   s   þzResponseHandler.set_parserFr   iþ  é€   )
ÚtimerÚskip_payloadÚread_until_eofÚauto_decompressÚread_timeoutÚread_bufsizeÚtimeout_ceil_thresholdÚmax_line_sizeÚmax_field_sizeÚmax_headersrh   ri   rj   rk   rl   rm   rn   ro   rp   rq   c       
         C   s\   || _ || _|| _t| | j||t| ||||	|
d�| _| jr,| jd}| _|  |¡ d S d S )N)rh   Úpayload_exceptionÚresponse_with_bodyrj   rk   ro   rp   rq   r   )	r!   r&   r(   r   r.   r	   rJ   r%   rd   )r+   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   re   r,   r,   r-   Úset_response_paramsä   s(   õþz#ResponseHandler.set_response_paramsc                 C   s"   | j d ur| j  ¡  d | _ d S d S r3   )r'   Úcancelr0   r,   r,   r-   rA   
  s   


þzResponseHandler._drop_timeoutc                 C   s>   | j }| jd ur| j ¡  |r| j || j¡| _d S d | _d S r3   )r&   r'   ru   r.   Ú
call_laterÚ_on_read_timeout)r+   Útimeoutr,   r,   r-   r_     s   


ÿ
z#ResponseHandler._reschedule_timeoutc                 C   rZ   r3   )r_   r0   r,   r,   r-   Ústart_timeout  s   zResponseHandler.start_timeoutc                 C   r2   r3   ©r&   r0   r,   r,   r-   rl     r6   zResponseHandler.read_timeoutc                 C   s
   || _ d S r3   rz   )r+   rl   r,   r,   r-   rl   "  s   
c                 C   s0   t dƒ}|  |¡ | jd urt| j|ƒ d S d S )Nz#Timeout on reading data from socket)r   r   r    )r+   rG   r,   r,   r-   rw   &  s
   

ÿz ResponseHandler._on_read_timeoutre   c           
   
   C   s¬  |r|   ¡  | jd ur-| jd ur|  ¡  | j |¡\}}|r+d | _d | _|r+|  |¡ d S | js5| jd u r>|  j|7  _d S z| j |¡\}}}W n< t	y… } z0| j
d ur[| j
 ¡  t|tƒsa‚ t|tƒrqt|j|j|jd�}ntƒ }|  ||¡ W Y d }~d S d }~ww || _d }|D ]&\}	}|	jr—d| _|| _| js¢|	jtv r«|  |	tfd¡ q�|  |	|fd¡ q�|d urÇ|turÃ| | j¡ n|  ¡  |rÒ|rÔ|  |¡ d S d S d S )N)ÚcodeÚmessageÚheadersTr   )r_   r"   r#   Ú	feed_datar    rd   r4   rJ   r%   ÚBaseExceptionr?   r@   rK   rH   r   r{   r|   r}   r   r;   r   r!   r   r   Úon_eofrA   )
r+   re   ÚeofÚtailÚmessagesr5   rU   rG   rb   r|   r,   r,   r-   rd   ,  sb   






ý€îÿzResponseHandler.data_received)r   N)Tr3   ))Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚasyncioÚAbstractEventLoopr   ÚpropertyÚFuturer1   r7   r5   r;   r=   r@   rD   rF   r   rP   r[   r\   r^   r   r   r   r   rf   r   r   ÚfloatÚintrt   rA   r_   ry   rl   Úsetterrw   Úbytesrd   Ú__classcell__r,   r,   rX   r-   r      sš    


		
K	ýþýüüþýü
ûôýüûúùø	÷
öõô
ó
&


r   ) rˆ   Ú
contextlibr   Útypingr   r   Úbase_protocolr   Úclient_exceptionsr   r   r	   r
   r   Úhelpersr   r   r   r   r   r   Úhttpr   r   Úhttp_exceptionsr   Ústreamsr   r   r   Útupler   r,   r,   r,   r-   Ú<module>   s     "