o
    çûõj¤8  ã                   @   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dIdd„ZdIdd„ZdIdd„Zde
fdd„ZdedB ddf‡ fdd„ZdIdd„ZdI‡ fdd„ZdJde
ddf‡ fdd„ZdId d!„Zefded"eddf‡ fd#d$„Z	dKd%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 d0e
d1e
d2e
d3edB d4ed5ed6ed7ed8eddfd9d:„Z dId;d<„Z!dId=d>„Z"dId?d@„Z#ededB fdAdB„ƒZ$e$j%d3edB ddfdCdB„ƒZ$dIdDdE„Z&dFe'ddfdGdH„Z(‡  Z)S )LÚResponseHandlerz8Helper class to adapt between Protocol and StreamReader.ÚloopÚreturnNc                 C   st   t j| |d d� t | |¡ d| _d | _d| _d | _d | _d | _d| _	d| _
t| _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Ú_payload_parser_failedr   Ú_read_bufsizeÚ_read_timeoutÚ_read_timeout_handleÚ_timeout_ceil_thresholdÚ_closedÚ_connection_lost_called)Úselfr   © r.   úG/opt/steambot/venv/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/   Úclosed5   s   zResponseHandler.closedc                 C   ó   | j S ©N)Ú	_upgradedr2   r.   r.   r/   ÚupgradedG   ó   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 r5   )	Úboolr   r    Úis_eofr6   Ú
_exceptionr"   Ú_bufferr%   r2   r.   r.   r/   Úshould_closeK   s   ÿþýüûùzResponseHandler.should_closec                 C   s
   d| _ d S ©NT)r   r2   r.   r.   r/   Úforce_closeW   s   
zResponseHandler.force_closec                 C   ó8   d | _ | j}|d ur| ¡  d | _d | _|  ¡  d S d S r5   )r;   Ú	transportÚcloser    Ú_drop_timeout©r-   rA   r.   r.   r/   rB   Z   ó   üzResponseHandler.closec                 C   r@   r5   )r;   rA   Úabortr    rC   rD   r.   r.   r/   rF   c   rE   zResponseHandler.abortc                 C   s   | j d uo
| j  ¡  S r5   )rA   Ú
is_closingr2   r.   r.   r/   Úis_connectedl   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| _d| _d| _tƒ  |¡ d S )NTzConnection lost: z#Response payload is not completed: z. F)r,   rC   r+   r   r   r   r"   r   Ú	ExceptionÚfeed_eofÚ_parserr    r	   r:   Ú
isinstanceÚOSErrorr   Úargsr
   r   r   r&   Ú_reading_pausedÚ_buffer_pausedÚsuperÚconnection_lost)	r-   rI   Úoriginal_connection_errorÚreraised_excÚconnection_closed_cleanlyÚuncompletedÚunderlying_excÚclient_payload_exc_msgÚunderlying_non_eof_exc©Ú	__class__r.   r/   rS   o   sx   
ÿû

ÿ

ÿÿÿý€ö

ÿýzResponseHandler.connection_lostc                 C   ó   |   ¡  d S r5   )rC   r2   r.   r.   r/   Úeof_received¼   s   zResponseHandler.eof_receivedc                    s   t ƒ  ¡  |  ¡  d S r5   )rR   Úpause_readingrC   r2   r[   r.   r/   r_   À   s   
zResponseHandler.pause_readingTÚresume_parserc                    s0   | j }tƒ  |¡ |r| js|  ¡  d S d S d S r5   )rP   rR   Úresume_readingrQ   Ú_reschedule_timeout)r-   r`   Ú
was_pausedr[   r.   r/   ra   Ä   s
   
ÿzResponseHandler.resume_readingc                 C   sf   | j r| j d}| _ |  |¡ t| j ƒot| j ƒ| jk}| jr%|s%|  ¡  | js+| jr1|  ¡  d S d S )Nr   )	r%   Údata_receivedr9   Úlenr'   rQ   Ú_resume_reading_for_bufferrP   rC   )r-   ÚdataÚstill_boundr.   r.   r/   Ú_drain_tailÌ   s   

ýzResponseHandler._drain_tailÚ	exc_causec                    s    d| _ |  ¡  tƒ  ||¡ d S r>   )r   rC   rR   r   )r-   rI   rj   r[   r.   r/   r   Ù   s   zResponseHandler.set_exceptionr   ÚpayloadÚdata_received_cbc                 C   s&   || _ || _|| _|  ¡  |  ¡  d S r5   )r    r"   r#   rC   ri   )r-   r   rk   rl   r.   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_headersro   rp   rq   rr   rs   rt   ru   rv   rw   rx   c       
         C   sH   || _ || _|| _|| _t| | j||t| ||||	|
d�| _|  ¡  d S )N)ro   Úpayload_exceptionÚresponse_with_bodyrq   rr   rv   rw   rx   )	r!   r'   r(   r*   r   r0   r	   rL   ri   )r-   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   r.   r.   r/   Úset_response_paramsõ   s$   õz#ResponseHandler.set_response_paramsc                 C   s"   | j d ur| j  ¡  d | _ d S d S r5   )r)   Úcancelr2   r.   r.   r/   rC     s   


þzResponseHandler._drop_timeoutc                 C   s>   | j }| jd ur| j ¡  |r| j || j¡| _d S d | _d S r5   )r(   r)   r|   r0   Ú
call_laterÚ_on_read_timeout)r-   Útimeoutr.   r.   r/   rb     s   


ÿ
z#ResponseHandler._reschedule_timeoutc                 C   r]   r5   )rb   r2   r.   r.   r/   Ústart_timeout+  s   zResponseHandler.start_timeoutc                 C   r4   r5   ©r(   r2   r.   r.   r/   rs   .  r8   zResponseHandler.read_timeoutc                 C   s
   || _ d S r5   r�   )r-   rs   r.   r.   r/   rs   2  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-   rI   r.   r.   r/   r~   6  s
   

ÿz ResponseHandler._on_read_timeoutrg   c              
   C   sÚ  | j rd S |r|  ¡  | jd ur.| jd ur|  ¡  | j |¡\}}|r,d | _d | _d| _ d S | js6| jd u rU|  j|7  _| j	sS| jrSt
| jƒ| jkrS|  ¡  |  ¡  d S z| j |¡\}}}W n< tyœ } z0| jd urr| j ¡  t|tƒsx‚ t|tƒrˆt|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 )NT)ÚcodeÚmessageÚheadersr   )r&   rb   r"   r#   Ú	feed_datar    r6   rL   r%   rQ   re   r'   Ú_pause_reading_for_bufferrC   ÚBaseExceptionrA   rB   rM   rJ   r   r‚   rƒ   r„   r   r=   r   r!   r   r   Úon_eofrd   )r-   rg   Úprotocol_errorÚ_Úmessagesr7   ÚtailrX   rI   rk   rƒ   r.   r.   r/   rd   <  sr   

ÿþ



ý€îÿzResponseHandler.data_received)r   N)Tr5   )*Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚasyncioÚAbstractEventLoopr   ÚpropertyÚFuturer3   r9   r7   r=   r?   rB   rF   rH   r‡   rS   r^   r_   ra   ri   r   r   r   r   rm   r   r   ÚfloatÚintr{   rC   rb   r€   rs   Úsetterr~   Úbytesrd   Ú__classcell__r.   r.   r[   r/   r      sœ    


		
M
ýþýüüþýü
ûôýüûúùø	÷
öõô
ó
%


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     "