o
    f>h/.                     @   s   d dl Z d dlmZ d dlmZmZ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 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Union   )BaseProtocol)ClientConnectionErrorClientOSErrorClientPayloadErrorServerDisconnectedErrorSocketTimeoutError)_EXC_SENTINEL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edej	d f fddZ
edefd	d
ZedefddZdBddZdBddZdefddZdee ddf fddZdBddZdB fddZdB 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d0ed1eddfd2d3ZdBd4d5ZdBd6d7Z dBd8d9Z!edee fd:d;Z"e"j#d-ee ddfd<d;Z"dBd=d>Z$d?e%ddfd@dAZ&  Z'S )CResponseHandlerz8Helper class to adapt between Protocol and StreamReader.loopreturnNc                 C   sl   t j| |d t| | d| _d | _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_closed_connection_lost_called)selfr    r-   G/var/www/html/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.   closed4   s   zResponseHandler.closedc                 C      | j S N)r%   r1   r-   r-   r.   upgradedF      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 r4   )	boolr   r    is_eofr%   
_exceptionr"   _bufferr$   r1   r-   r-   r.   should_closeJ   s   zResponseHandler.should_closec                 C   s
   d| _ d S NT)r   r1   r-   r-   r.   force_closeV   s   
zResponseHandler.force_closec                 C   s8   d | _ | j}|d ur|  d | _d | _|   d S d S r4   )r9   	transportcloser    _drop_timeout)r,   r>   r-   r-   r.   r?   Y   s   zResponseHandler.closec                 C   s   | j d uo
| j   S r4   )r>   
is_closingr1   r-   r-   r.   is_connectedb   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rz| j
	 }W n. ty } z"| jd urd|}|sv|d|}t| jt|| W Y d }~nd }~ww |  st|trt|j }|rt|}|rtn|}|d usJ |d usJ | || d| _d | _
d | _d | _d| _t | d S )NTzConnection lost: z#Response payload is not completed: z. F)r+   r@   r*   r   r   r	   r"   r   	Exceptionfeed_eofr&   r    r   r8   
isinstanceOSErrorr
   argsr   r   r   _reading_pausedsuperconnection_lost)	r,   rC   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__r-   r.   rK   e   st   






zResponseHandler.connection_lostc                 C      |    d S r4   )r@   r1   r-   r-   r.   eof_received   s   zResponseHandler.eof_receivedc                       t    |   d S r4   )rJ   pause_readingr@   r1   rS   r-   r.   rX         
zResponseHandler.pause_readingc                    rW   r4   )rJ   resume_reading_reschedule_timeoutr1   rS   r-   r.   rZ      rY   zResponseHandler.resume_reading	exc_causec                    s    d| _ |   t || d S r<   )r   r@   rJ   r   )r,   rC   r\   rS   r-   r.   r      s   zResponseHandler.set_exceptionparserpayloadc                 C   s:   || _ || _|   | jr| jd}| _| | d S d S )Nr   )r    r"   r@   r$   data_received)r,   r]   r^   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_sizerb   rc   rd   re   rf   rg   rh   ri   rj   c       	         C   sZ   || _ || _|| _t| | j||t| ||||	d
| _| jr+| jd}
| _| |
 d S d S )N)rb   payload_exceptionresponse_with_bodyrd   re   ri   rj   r   )	r!   r'   r)   r   r/   r   r&   r$   r_   )r,   rb   rc   rd   re   rf   rg   rh   ri   rj   r`   r-   r-   r.   set_response_params   s&   z#ResponseHandler.set_response_paramsc                 C   s"   | j d ur| j   d | _ d S d S r4   )r(   cancelr1   r-   r-   r.   r@      s   


zResponseHandler._drop_timeoutc                 C   s>   | j }| jd ur| j  |r| j|| j| _d S d | _d S r4   )r'   r(   rn   r/   
call_later_on_read_timeout)r,   timeoutr-   r-   r.   r[      s   



z#ResponseHandler._reschedule_timeoutc                 C   rU   r4   )r[   r1   r-   r-   r.   start_timeout	  s   zResponseHandler.start_timeoutc                 C   r3   r4   r'   r1   r-   r-   r.   rf     r6   zResponseHandler.read_timeoutc                 C   s
   || _ d S r4   rs   )r,   rf   r-   r-   r.   rf     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,   rC   r-   r-   r.   rp     s
   

z ResponseHandler._on_read_timeoutr`   c           
   
   C   s  |    |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 n6 tyx } z*| j	d urT| j	
  t|trdt|j|j|jd}nt }| || W Y d }~d S d }~ww || _d }|D ]&\}	}|	jrd| _|| _| 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 )N)codemessageheadersTr   )r[   r"   	feed_datar    r_   r%   r&   r$   BaseExceptionr>   r?   rF   r   rt   ru   rv   r   r;   r   r!   r   r   on_eofr@   )
r,   r`   eoftailmessagesr5   rP   rC   r^   ru   r-   r-   r.   r_     s\   




zResponseHandler.data_received)r   N)(__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr   Futurer2   r7   r5   r;   r=   r?   rB   r   rx   rK   rV   rX   rZ   r   r   r   ra   r   floatintrm   r@   r[   rr   rf   setterrp   bytesr_   __classcell__r-   r-   rS   r.   r      s    

	
K		


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