a
    &h!                     @   s   d dl Z d dlmZ d dlmZmZmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZ ddlmZ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OptionalTuple   )BaseProtocol)ClientOSErrorClientPayloadErrorServerDisconnectedErrorServerTimeoutError)BaseTimerContextstatus_code_must_be_empty_body)HttpResponseParserRawResponseMessage)EMPTY_PAYLOAD	DataQueueStreamReaderc                       sj  e Zd ZdZejddddZeedddZ	eedd	d
Z
ddddZddddZedddZee dd fddZddddZdd fddZdd fddZedd fddZeeddddZdddd dd!d"d#d#d$	ee eeeee eeeedd%
d&d'Zddd(d)Zddd*d+Zddd,d-Zddd.d/Zedd0d1d2Z   Z!S )3ResponseHandlerz8Helper class to adapt between Protocol and StreamReader.N)loopreturnc                 C   s`   t j| |d t| | d| _d | _d| _d | _d | _d| _d| _	d | _
d | _d | _d| _d S )N)r   F       )r   __init__r   _should_close_payload_skip_payload_payload_parser_timer_tail	_upgraded_parser_read_timeout_read_timeout_handle_timeout_ceil_threshold)selfr    r%   Y/var/www/html/swiplay.fr/scambot/venv/lib/python3.9/site-packages/aiohttp/client_proto.pyr      s    zResponseHandler.__init__)r   c                 C   s   | j S N)r   r$   r%   r%   r&   upgraded)   s    zResponseHandler.upgradedc                 C   sV   | j d ur| j  r| jrdS | jpT| jpT|  d upT| jd upTt| dkpTt| jS NTr   )	r   is_eofr   r   	exceptionr   lenboolr   r(   r%   r%   r&   should_close-   s    

zResponseHandler.should_closec                 C   s
   d| _ d S NT)r   r(   r%   r%   r&   force_close;   s    zResponseHandler.force_closec                 C   s.   | j }|d ur*|  d | _ d | _|   d S r'   )	transportcloser   _drop_timeout)r$   r2   r%   r%   r&   r3   >   s    zResponseHandler.closec                 C   s   | j d uo| j   S r'   )r2   
is_closingr(   r%   r%   r&   is_connectedF   s    zResponseHandler.is_connected)excr   c                    s   |    | jd urDtt | j  W d    n1 s:0    Y  d }| jd urz| j }W n, ty   | jd ur| jtd Y n0 | 	 st
|trt|j }|d u rt|}| | d| _d | _d | _d | _d| _t | d S )Nz!Response payload is not completedTF)r4   r   r   	Exceptionfeed_eofr    r   set_exceptionr	   r+   
isinstanceOSErrorr   argsr
   r   _reading_pausedsuperconnection_lost)r$   r7   Zuncompleted	__class__r%   r&   r@   I   s2    

(





zResponseHandler.connection_lostc                 C   s   |    d S r'   )r4   r(   r%   r%   r&   eof_receivedk   s    zResponseHandler.eof_receivedc                    s   t    |   d S r'   )r?   pause_readingr4   r(   rA   r%   r&   rD   o   s    
zResponseHandler.pause_readingc                    s   t    |   d S r'   )r?   resume_reading_reschedule_timeoutr(   rA   r%   r&   rE   s   s    
zResponseHandler.resume_readingc                    s   d| _ |   t | d S r0   )r   r4   r?   r:   r$   r7   rA   r%   r&   r:   w   s    zResponseHandler.set_exception)parserpayloadr   c                 C   s6   || _ || _|   | jr2| jd }| _| | d S )Nr   )r   r   r4   r   data_received)r$   rH   rI   datar%   r%   r&   
set_parser|   s    zResponseHandler.set_parserFTi   r   i  )	timerskip_payloadread_until_eofauto_decompressread_timeoutread_bufsizetimeout_ceil_thresholdmax_line_sizemax_field_size)
rM   rN   rO   rP   rQ   rR   rS   rT   rU   r   c       	         C   sV   || _ || _|| _t| | j||t| ||||	d
| _| jrR| jd }
| _| |
 d S )N)rM   payload_exceptionresponse_with_bodyrO   rP   rT   rU   r   )	r   r!   r#   r   _loopr	   r    r   rJ   )r$   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rK   r%   r%   r&   set_response_params   s$    z#ResponseHandler.set_response_paramsc                 C   s   | j d ur| j   d | _ d S r'   )r"   cancelr(   r%   r%   r&   r4      s    

zResponseHandler._drop_timeoutc                 C   s<   | j }| jd ur| j  |r2| j|| j| _nd | _d S r'   )r!   r"   rZ   rX   
call_later_on_read_timeout)r$   timeoutr%   r%   r&   rF      s    

z#ResponseHandler._reschedule_timeoutc                 C   s   |    d S r'   )rF   r(   r%   r%   r&   start_timeout   s    zResponseHandler.start_timeoutc                 C   s,   t d}| | | jd ur(| j| d S )Nz#Timeout on reading data from socket)r   r:   r   rG   r%   r%   r&   r\      s    

z ResponseHandler._on_read_timeout)rK   r   c           	   
   C   sv  |    |sd S | jd urL| j|\}}|rHd | _d | _|rH| | d S | js\| jd u rn|  j|7  _nz| j|\}}}W nD ty } z,| j	d ur| j	
  | | W Y d }~d S d }~0 0 || _d }|D ]P\}}|jrd| _|| _| jst|jr| |tfd q| ||fd q|d urT|turL|| j n|   |rr|rl| | n|| _d S r*   )rF   r   	feed_datar   rJ   r   r    r   BaseExceptionr2   r3   r:   r/   r   r   r   coder   on_eofr4   )	r$   rK   eoftailmessagesr)   r7   rI   messager%   r%   r&   rJ      sN    







zResponseHandler.data_received)"__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr.   r)   r/   r1   r3   r6   r   r`   r@   rC   rD   rE   r:   r   rL   r   floatintrY   r4   rF   r^   r\   bytesrJ   __classcell__r%   r%   rA   r&   r      sR   "$r   )rk   
contextlibr   typingr   r   r   base_protocolr   client_exceptionsr   r	   r
   r   helpersr   r   httpr   r   streamsr   r   r   r   r%   r%   r%   r&   <module>   s   