o
    +if&                     @   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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OptionalTuple   )BaseProtocol)ClientOSErrorClientPayloadErrorServerDisconnectedErrorServerTimeoutError)_EXC_SENTINELBaseTimerContextset_exceptionstatus_code_must_be_empty_body)HttpResponseParserRawResponseMessage)HttpProcessingError)EMPTY_PAYLOAD	DataQueueStreamReaderc                       sl  e Zd ZdZdejddfddZedefddZ	edefd	d
Z
d=ddZd=ddZdefddZdee ddf fddZd=ddZd= fddZd= fddZefdededdf fddZdededdfdd Zdd!d!d"dd#d$d%d%d&	d'ee d(ed)ed*ed+ee d,ed-ed.ed/eddfd0d1Zd=d2d3Zd=d4d5Zd=d6d7Zd=d8d9Zd:e ddfd;d<Z!  Z"S )>ResponseHandlerz8Helper class to adapt between Protocol and StreamReader.loopreturnNc                 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(   M/var/www/html/corbot_env/lib/python3.10/site-packages/aiohttp/client_proto.pyr      s   
zResponseHandler.__init__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p*| jp*|  d up*| jd up*t| dkp*t| jS NTr   )	r   is_eofr"   r   	exceptionr   lenboolr!   r+   r(   r(   r)   should_close3   s   

zResponseHandler.should_closec                 C   s
   d| _ d S NT)r   r+   r(   r(   r)   force_closeA   s   
zResponseHandler.force_closec                 C   s2   | j }|d ur|  d | _ d | _|   d S d S r*   )	transportcloser   _drop_timeout)r'   r5   r(   r(   r)   r6   D   s   zResponseHandler.closec                 C   s   | j d uo
| j   S r*   )r5   
is_closingr+   r(   r(   r)   is_connectedL   s   zResponseHandler.is_connectedexcc           	   
      sT  |    |}|}|d u }| jd ur*tt | j  W d    n1 s%w   Y  d }| jd urgz| j }W n. tyf } z"| jd ur\d|}|sS|d|}t| jt|| W Y d }~nd }~ww | 	 st
|trut|j }|r{t|}|rtn|}|d usJ |d usJ | || d| _d | _d | _d | _d| _t | d S )Nz#Response payload is not completed: z. TF)r7   r   r   	Exceptionfeed_eofr#   r   r   r	   r.   
isinstanceOSErrorr   argsr
   r   r   _reading_pausedsuperconnection_lost)	r'   r:   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__r(   r)   rB   O   s\   





zResponseHandler.connection_lostc                 C      |    d S r*   )r7   r+   r(   r(   r)   eof_received   s   zResponseHandler.eof_receivedc                       t    |   d S r*   )rA   pause_readingr7   r+   rJ   r(   r)   rO         
zResponseHandler.pause_readingc                    rN   r*   )rA   resume_reading_reschedule_timeoutr+   rJ   r(   r)   rQ      rP   zResponseHandler.resume_reading	exc_causec                    s    d| _ |   t || d S r3   )r   r7   rA   r   )r'   r:   rS   rJ   r(   r)   r      s   zResponseHandler.set_exceptionparserpayloadc                 C   s:   || _ || _|   | jr| jd}| _| | d S d S )Nr   )r   r   r7   r!   data_received)r'   rT   rU   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_sizerY   rZ   r[   r\   r]   r^   r_   r`   ra   c       	         C   sZ   || _ || _|| _t| | j||t| ||||	d
| _| jr+| jd}
| _| |
 d S d S )N)rY   payload_exceptionresponse_with_bodyr[   r\   r`   ra   r   )	r   r$   r&   r   _loopr	   r#   r!   rV   )r'   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rW   r(   r(   r)   set_response_params   s&   z#ResponseHandler.set_response_paramsc                 C   s"   | j d ur| j   d | _ d S d S r*   )r%   cancelr+   r(   r(   r)   r7      s   


zResponseHandler._drop_timeoutc                 C   s>   | j }| jd ur| j  |r| j|| j| _d S d | _d S r*   )r$   r%   rf   rd   
call_later_on_read_timeout)r'   timeoutr(   r(   r)   rR      s   



z#ResponseHandler._reschedule_timeoutc                 C   rL   r*   )rR   r+   r(   r(   r)   start_timeout   s   zResponseHandler.start_timeoutc                 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'   r:   r(   r(   r)   rh      s
   

z ResponseHandler._on_read_timeoutrW   c           	   
   C   st  |    |sd S | jd ur&| j|\}}|r$d | _d | _|r$| | d S | js.| jd u r7|  j|7  _d S z| j|\}}}W n$ tyf } z| j	d urT| j	
  | t | W Y d }~d S d }~ww || _d }|D ]&\}}|jrxd| _|| _| jst|jr| |tfd qn| ||fd qn|d ur|tur|| j n|   |r|r| | d S || _d S d S r-   )rR   r   	feed_datar   rV   r"   r#   r!   BaseExceptionr5   r6   r   r   r2   r   r   r   coder   on_eofr7   )	r'   rW   eoftailmessagesr,   rG   rU   messager(   r(   r)   rV      sT   





zResponseHandler.data_received)r   N)#__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr1   r,   r2   r4   r6   r9   r   rl   rB   rM   rO   rQ   r   r   r   rX   r   floatintre   r7   rR   rj   rh   bytesrV   __classcell__r(   r(   rJ   r)   r      st    


8		


$


r   )rw   
contextlibr   typingr   r   r   base_protocolr   client_exceptionsr   r	   r
   r   helpersr   r   r   r   httpr   r   http_exceptionsr   streamsr   r   r   r   r(   r(   r(   r)   <module>   s    "