a
    ~g'                     @   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SocketTimeoutError)_EXC_SENTINELEMPTY_BODY_STATUS_CODESBaseTimerContextset_exception)HttpResponseParserRawResponseMessage)HttpProcessingError)EMPTY_PAYLOAD	DataQueueStreamReaderc                       s  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fe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eee dd/d0Zej ee dd1d2d0Zddd3d4Z!e"dd5d6d7Z#  Z$S )8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/emsaiapi.evdpl.com/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   sF   t | jpB| jd ur| j  pB| jpB| jd upB| jd upB| jpB| jS r*   )	boolr   r   is_eofr"   
_exceptionr   _bufferr!   r+   r(   r(   r)   should_close3   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'   r4   r(   r(   r)   r5   B   s    zResponseHandler.closec                 C   s   | j d uo| j   S r*   )r4   
is_closingr+   r(   r(   r)   is_connectedJ   s    zResponseHandler.is_connected)excr   c           	   
      s\  |    |}|}|d u }| jd urTtt | j  W d    n1 sJ0    Y  d }| jd urz| j }W n\ ty } zD| jd urd|}|s|d|}t| jt|| W Y d }~n
d }~0 0 | 	 s.t
|trt|j }|rt|}|rtn|}|d usJ |d us"J | || d| _d | _d | _d | _d| _t | d S )Nz#Response payload is not completed: z. TF)r6   r   r   	Exceptionfeed_eofr#   r   r   r	   r.   
isinstanceOSErrorr   argsr
   r   r   _reading_pausedsuperconnection_lost)	r'   r9   Zoriginal_connection_errorreraised_excZconnection_closed_cleanlyZuncompletedunderlying_excZclient_payload_exc_msgZunderlying_non_eof_exc	__class__r(   r)   rA   M   sV    

(




zResponseHandler.connection_lostc                 C   s   |    d S r*   )r6   r+   r(   r(   r)   eof_received   s    zResponseHandler.eof_receivedc                    s   t    |   d S r*   )r@   pause_readingr6   r+   rD   r(   r)   rG      s    
zResponseHandler.pause_readingc                    s   t    |   d S r*   )r@   resume_reading_reschedule_timeoutr+   rD   r(   r)   rH      s    
zResponseHandler.resume_reading)r9   	exc_causer   c                    s    d| _ |   t || d S r2   )r   r6   r@   r   )r'   r9   rJ   rD   r(   r)   r      s    zResponseHandler.set_exception)parserpayloadr   c                 C   s6   || _ || _|   | jr2| jd }| _| | d S )Nr   )r   r   r6   r!   data_received)r'   rK   rL   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)
rP   rQ   rR   rS   rT   rU   rV   rW   rX   r   c       	         C   sV   || _ || _|| _t| | j||t| ||||	d
| _| jrR| jd }
| _| |
 d S )N)rP   payload_exceptionresponse_with_bodyrR   rS   rW   rX   r   )	r   r$   r&   r   _loopr	   r#   r!   rM   )r'   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rN   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)   r6      s    

zResponseHandler._drop_timeoutc                 C   s<   | j }| jd ur| j  |r2| j|| j| _nd | _d S r*   )r$   r%   r]   r[   
call_later_on_read_timeout)r'   timeoutr(   r(   r)   rI      s    

z#ResponseHandler._reschedule_timeoutc                 C   s   |    d S r*   )rI   r+   r(   r(   r)   start_timeout   s    zResponseHandler.start_timeoutc                 C   s   | j S r*   r$   r+   r(   r(   r)   rT      s    zResponseHandler.read_timeout)rT   r   c                 C   s
   || _ d S r*   rb   )r'   rT   r(   r(   r)   rT      s    c                 C   s,   t d}| | | jd ur(t| j| d S )Nz#Timeout on reading data from socket)r   r   r   )r'   r9   r(   r(   r)   r_      s    

z ResponseHandler._on_read_timeout)rN   r   c           
   
   C   s  |    |sd S | jd urL| j|\}}|rHd | _d | _|rH| | d S | js\| jd u rn|  j|7  _d S z| j|\}}}W nl ty } zT| j	d ur| j	
  t|trt|j|j|jd}nt }| || W Y d }~d S d }~0 0 || _d }|D ]T\}	}|	jrd| _|| _| js0|	jtv rB| |	tfd n| |	|fd q |d ur|turx|| j n|   |r|r| | d S )N)codemessageheadersTr   )rI   r   	feed_datar   rM   r"   r#   r!   BaseExceptionr4   r5   r<   r   rc   rd   re   r   r1   r   r   r   r   on_eofr6   )
r'   rN   eoftailmessagesr,   rC   r9   rL   rd   r(   r(   r)   rM      sV    






zResponseHandler.data_received)%__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr-   r,   r1   r3   r5   r8   r   rg   rA   rF   rG   rH   r   r   r   rO   r   floatintr\   r6   rI   ra   rT   setterr_   bytesrM   __classcell__r(   r(   rD   r)   r      sd   8	$r   )rp   
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   