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_parserZ_timer_tail	_upgraded_parser_read_timeout_read_timeout_handle_timeout_ceil_threshold)selfr    r'   b/var/www/html/cobodadashboardai.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&   r3   r'   r'   r(   r4   B   s    zResponseHandler.closec                 C   s   | j d uo| j   S r)   )r3   
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)r5   r   r   	Exceptionfeed_eofr"   r   r   r	   r-   
isinstanceOSErrorr   argsr
   r   r   Z_reading_pausedsuperconnection_lost)	r&   r8   Zoriginal_connection_errorZreraised_excZconnection_closed_cleanlyZuncompletedunderlying_excZclient_payload_exc_msgZunderlying_non_eof_exc	__class__r'   r(   r?   M   sV    

(




zResponseHandler.connection_lostc                 C   s   |    d S r)   )r5   r*   r'   r'   r(   eof_received   s    zResponseHandler.eof_receivedc                    s   t    |   d S r)   )r>   pause_readingr5   r*   rA   r'   r(   rD      s    
zResponseHandler.pause_readingc                    s   t    |   d S r)   )r>   resume_reading_reschedule_timeoutr*   rA   r'   r(   rE      s    
zResponseHandler.resume_reading)r8   	exc_causer   c                    s    d| _ |   t || d S r1   )r   r5   r>   r   )r&   r8   rG   rA   r'   r(   r      s    zResponseHandler.set_exception)parserpayloadr   c                 C   s6   || _ || _|   | jr2| jd }| _| | d S )Nr   )r   r   r5   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   Zpayload_exceptionZ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(   r5      s    

zResponseHandler._drop_timeoutc                 C   s<   | j }| jd ur| j  |r2| j|| j| _nd | _d S r)   )r#   r$   rX   rV   
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   | j S r)   r#   r*   r'   r'   r(   rQ      s    zResponseHandler.read_timeout)rQ   r   c                 C   s
   || _ d S r)   r]   )r&   rQ   r'   r'   r(   rQ      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&   r8   r'   r'   r(   rZ      s    

z ResponseHandler._on_read_timeout)rK   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   )rF   r   	feed_datar   rJ   r!   r"   r    BaseExceptionr3   r4   r;   r   r^   r_   r`   r   r0   r   r   r   r   Zon_eofr5   )
r&   rK   eoftailmessagesr+   r@   r8   rI   r_   r'   r'   r(   rJ      sV    






zResponseHandler.data_received)%__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr,   r+   r0   r2   r4   r7   r   rb   r?   rC   rD   rE   r   r   r   rL   r   floatintrW   r5   rF   r\   rQ   setterrZ   bytesrJ   __classcell__r'   r'   rA   r(   r      sd   8	$r   )rj   
contextlibr   typingr   r   r   Zbase_protocolr   Zclient_exceptionsr   r	   r
   r   helpersr   r   r   r   httpr   r   Zhttp_exceptionsr   streamsr   r   r   r   r'   r'   r'   r(   <module>   s   