o
    m=8jY1                     @   s   d dl Z d dlmZ d dl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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Callable   )BaseProtocol)ClientConnectionErrorClientOSErrorClientPayloadErrorServerDisconnectedErrorSocketTimeoutError)_EXC_SENTINELDEFAULT_CHUNK_SIZE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dejd B fddZ	ede
fd	d
Zede
fddZdGddZdGddZdGddZde
fddZdedB ddf fddZdGddZdG fddZdHde
ddf fddZefded eddf fd!d"Z	dId#ed$ed%eg df dB ddfd&d'Zdd(d(dded)d*d*d+d,
d-edB d.e
d/e
d0e
d1edB d2ed3ed4ed5ed6eddfd7d8ZdGd9d:Z dGd;d<Z!dGd=d>Z"ededB fd?d@Z#e#j$d1edB ddfdAd@Z#dGdBdCZ%dDe&ddfdEdFZ'  Z(S )JResponseHandlerz8Helper class to adapt between Protocol and StreamReader.loopreturnNc                 C   sh   t j| |d d t| | d| _d | _d| _d | _d | _d | _d| _	d | _
d | _d| _d | _d| _d S )N)r   parserF       )r   __init__r   _should_close_payload_skip_payload_payload_parser_data_received_cb_timer_tail_read_timeout_read_timeout_handle_timeout_ceil_threshold_closed_connection_lost_called)selfr    r,   [/home/nk/hobo-godmode/plappi-mvp/.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-   closed3   s   zResponseHandler.closedc                 C      | j S N)	_upgradedr0   r,   r,   r-   upgradedE      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 r3   )	boolr   r    is_eofr4   
_exceptionr"   _bufferr%   r0   r,   r,   r-   should_closeI   s   zResponseHandler.should_closec                 C   s
   d| _ d S NT)r   r0   r,   r,   r-   force_closeU   s   
zResponseHandler.force_closec                 C   8   d | _ | j}|d ur|  d | _d | _|   d S d S r3   )r9   	transportcloser    _drop_timeoutr+   r?   r,   r,   r-   r@   X      zResponseHandler.closec                 C   r>   r3   )r9   r?   abortr    rA   rB   r,   r,   r-   rD   a   rC   zResponseHandler.abortc                 C   s   | j d uo
| j   S r3   )r?   
is_closingr0   r,   r,   r-   is_connectedj   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*   rA   r)   r   r   r   r"   r   	Exceptionfeed_eof_parserr    r	   r8   
isinstanceOSErrorr   argsr
   r   r   _reading_pausedsuperconnection_lost)	r+   rG   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__r,   r-   rP   m   st   






zResponseHandler.connection_lostc                 C      |    d S r3   )rA   r0   r,   r,   r-   eof_received   s   zResponseHandler.eof_receivedc                    s   t    |   d S r3   )rO   pause_readingrA   r0   rX   r,   r-   r\      s   
zResponseHandler.pause_readingTresume_parserc                    s   t  | |   d S r3   )rO   resume_reading_reschedule_timeout)r+   r]   rX   r,   r-   r^      s   zResponseHandler.resume_reading	exc_causec                    s    d| _ |   t || d S r<   )r   rA   rO   r   )r+   rG   r`   rX   r,   r-   r      s   zResponseHandler.set_exceptionr   payloaddata_received_cbc                 C   s@   || _ || _|| _|   | jr| jd}| _| | d S d S )Nr   )r    r"   r#   rA   r%   data_received)r+   r   ra   rb   datar,   r,   r-   
set_parser   s   zResponseHandler.set_parserFr   i     )
timerskip_payloadread_until_eofauto_decompressread_timeoutread_bufsizetimeout_ceil_thresholdmax_line_sizemax_field_sizemax_headersrg   rh   ri   rj   rk   rl   rm   rn   ro   rp   c       
         C   s\   || _ || _|| _t| | j||t| ||||	|
d| _| jr,| jd}| _| | d S d S )N)rg   payload_exceptionresponse_with_bodyri   rj   rn   ro   rp   r   )	r!   r&   r(   r   r.   r	   rJ   r%   rc   )r+   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rd   r,   r,   r-   set_response_params   s(   z#ResponseHandler.set_response_paramsc                 C   s"   | j d ur| j   d | _ d S d S r3   )r'   cancelr0   r,   r,   r-   rA     s   


zResponseHandler._drop_timeoutc                 C   s>   | j }| jd ur| j  |r| j|| j| _d S d | _d S r3   )r&   r'   rt   r.   
call_later_on_read_timeout)r+   timeoutr,   r,   r-   r_     s   



z#ResponseHandler._reschedule_timeoutc                 C   rZ   r3   )r_   r0   r,   r,   r-   start_timeout  s   zResponseHandler.start_timeoutc                 C   r2   r3   r&   r0   r,   r,   r-   rk     r6   zResponseHandler.read_timeoutc                 C   s
   || _ d S r3   ry   )r+   rk   r,   r,   r-   rk      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+   rG   r,   r,   r-   rv   $  s
   

z ResponseHandler._on_read_timeoutrd   c           
   
   C   s  |r|    | jd ur-| jd ur|   | j|\}}|r+d | _d | _|r+| | d S | js5| jd u r>|  j|7  _d S z| j|\}}}W n< t	y } z0| j
d ur[| j
  t|tsa t|trqt|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"   r#   	feed_datar    rc   r4   rJ   r%   BaseExceptionr?   r@   rK   rH   r   rz   r{   r|   r   r;   r   r!   r   r   on_eofrA   )
r+   rd   eoftailmessagesr5   rU   rG   ra   r{   r,   r,   r-   rc   *  sb   






zResponseHandler.data_received)r   N)Tr3   ))__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyFuturer1   r7   r5   r;   r=   r@   rD   rF   r~   rP   r[   r\   r^   r   r   r   r   re   r   r   floatintrs   rA   r_   rx   rk   setterrv   bytesrc   __classcell__r,   r,   rX   r-   r      s    


		
K
	


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