
    `e!              	           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 ddlmZmZ dd	lmZmZmZ  G d
 deeeeef                            ZdS )    N)suppress)AnyOptionalTuple   )BaseProtocol)ClientOSErrorClientPayloadErrorServerDisconnectedErrorServerTimeoutError)BaseTimerContextstatus_code_must_be_empty_body)HttpResponseParserRawResponseMessage)EMPTY_PAYLOAD	DataQueueStreamReaderc                   |    e Zd ZdZdej        ddfdZedefd            Z	edefd            Z
d*dZd*d	Zdefd
Zdee         ddf fdZd*dZd* fdZd* fdZdeddf fdZdededdf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d#Zd*d$Zd*d%Zd*d&Zd*d'Zd(eddfd)Z  xZ!S )+ResponseHandlerz8Helper class to adapt between Protocol and StreamReader.loopreturnNc                     t          j        | |           t          j        | |           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   s     4lib/python3.11/site-packages/aiohttp/client_proto.pyr   zResponseHandler.__init__   s    d....4&&&"04"#
59.2CG!89$$$r   c                     | j         S N)r"   r'   s    r(   upgradedzResponseHandler.upgraded)   s
    ~r   c                     | j         | j                                         r| j        rdS | j        pL| j        pE|                                 d up/| j        d up&t          |           dk    pt          | j                  S NTr   )	r   is_eofr"   r   	exceptionr   lenboolr!   r+   s    r(   should_closezResponseHandler.should_close-   s    =$T]-A-A-C-C$t~$4   ~ ~~t+  #4/  4yy1}	 
 DJ	
r   c                     d| _         d S NT)r   r+   s    r(   force_closezResponseHandler.force_close;   s    !r   c                     | j         }|8|                                 d | _         d | _        |                                  d S d S r*   )	transportcloser   _drop_timeout)r'   r8   s     r(   r9   zResponseHandler.close>   sM    N	 OO!DN DM     	 ! r   c                 H    | j         d uo| j                                          S r*   )r8   
is_closingr+   s    r(   is_connectedzResponseHandler.is_connectedF   s%    ~T)M$.2K2K2M2M.MMr   excc                    |                                   | j        Et          t                    5  | j                                         d d d            n# 1 swxY w Y   d }| j        i	 | j                                        }nN# t          $ rA}| j        0t          d          }||_        | j        	                    |           Y d }~nd }~ww xY w| 
                                sIt          |t                    rt          |j         }|t          |          }| 	                    |           d| _        d | _        d | _        d | _        d| _        t%                                          |           d S )Nz!Response payload is not completedTF)r:   r   r   	Exceptionfeed_eofr#   r   r
   	__cause__set_exceptionr/   
isinstanceOSErrorr	   argsr   r   _reading_pausedsuperconnection_lost)r'   r>   uncompletede	__class__s       r(   rI   zResponseHandler.connection_lostI   s   +)$$ 0 0$--///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <#5"l3355 5 5 5=,,-PQQC$%CMM//444	5 {{}} 	$#w'' /#SX.{-k:: s###!#$$$$$$s)   AAA,B 
C7CCc                 .    |                                   d S r*   )r:   r+   s    r(   eof_receivedzResponseHandler.eof_receivedk   s    r   c                 p    t                                                       |                                  d S r*   )rH   pause_readingr:   r'   rL   s    r(   rP   zResponseHandler.pause_readingo   s1    r   c                 p    t                                                       |                                  d S r*   )rH   resume_reading_reschedule_timeoutrQ   s    r(   rS   zResponseHandler.resume_readings   s1         """""r   c                     d| _         |                                  t                                          |           d S r5   )r   r:   rH   rC   )r'   r>   rL   s     r(   rC   zResponseHandler.set_exceptionw   s;    !c"""""r   parserpayloadc                     || _         || _        |                                  | j        r&| j        dc}| _        |                     |           d S d S )Nr   )r   r   r:   r!   data_received)r'   rV   rW   datas       r(   
set_parserzResponseHandler.set_parser|   sc      %: 	%#z3D$*t$$$$$	% 	%r   FTi   r   i  )	timerskip_payloadread_until_eofauto_decompressread_timeoutread_bufsizetimeout_ceil_thresholdmax_line_sizemax_field_sizer\   r]   r^   r_   r`   ra   rb   rc   rd   c       	             || _         || _        || _        t          | | j        ||t
          | ||||	
  
        | _        | j        r&| j        dc}
| _        |                     |
           d S d S )N)r\   payload_exceptionresponse_with_bodyr^   r_   rc   rd   r   )	r   r$   r&   r   _loopr
   r#   r!   rY   )r'   r\   r]   r^   r_   r`   ra   rb   rc   rd   rZ   s              r(   set_response_paramsz#ResponseHandler.set_response_params   s     *)'=$)J0#//)+')
 
 
 : 	%#z3D$*t$$$$$	% 	%r   c                 X    | j         "| j                                          d | _         d S d S r*   )r%   cancelr+   s    r(   r:   zResponseHandler._drop_timeout   s6    $0%,,...(,D%%% 10r   c                     | j         }| j        | j                                         |r'| j                            || j                  | _        d S d | _        d S r*   )r$   r%   rk   rh   
call_later_on_read_timeout)r'   timeouts     r(   rT   z#ResponseHandler._reschedule_timeout   sh    $$0%,,... 	-(,
(=(=.) )D%%% )-D%%%r   c                 .    |                                   d S r*   )rT   r+   s    r(   start_timeoutzResponseHandler.start_timeout   s      """""r   c                     t          d          }|                     |           | j        | j                            |           d S d S )Nz#Timeout on reading data from socket)r   rC   r   )r'   r>   s     r(   rn   z ResponseHandler._on_read_timeout   sP     !FGG3=$M'',,,,, %$r   rZ   c                    |                                   |sd S | j        F| j                            |          \  }}|r%d | _        d | _        |r|                     |           d S | j        s| j        | xj        |z  c_        d S 	 | j                            |          \  }}}nM# t          $ r@}| j	        | j	        
                                 |                     |           Y d }~d S d }~ww xY w|| _        d }|D ]k\  }}|j        rd| _        || _        | j        st          |j                  r|                     |t"          fd           S|                     ||fd           l|8|t"          ur|                    | j                   n|                                  |r"|r|                     |           d S || _        d S d S r.   )rT   r   	feed_datar   rY   r"   r#   r!   BaseExceptionr8   r9   rC   r3   r   r   r   coder   on_eofr:   )	r'   rZ   eoftailmessagesr,   r>   rW   messages	            r(   rY   zResponseHandler.data_received   s8     """ 	F +,66t<<IC - $'+$ -&&t,,,F~ .*!5

d"




/3|/E/Ed/K/K,Hh$   ~1 ,,...&&s+++FFFFF "*26(0 > >$GW+ 2-1*$+DM) >-K. . > '?CCCC'91====&
 m33t'9::::**,,, * ***400000%)


	* *s   B& &
C005C++C0)r   N)"__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr2   r,   r3   r6   r9   r=   r   ru   rI   rN   rP   rS   rC   r   r[   r   floatintri   r:   rT   rq   rn   bytesrY   __classcell__)rL   s   @r(   r   r      s       BB:W6 :4 : : : :* $    X 
d 
 
 
 X
" " " "! ! ! !Nd N N N N %8M#:  %t  %  %  %  %  %  %D        # # # # # ## #4 # # # # # #
% %s %t % % % %$ -1"$ $(,!()!""% "% "% ()"% 	"%
 "% "% uo"% "% !&"% "% "% 
"% "% "% "%H- - - -

- 
- 
- 
-# # # #- - - -?*% ?*D ?* ?* ?* ?* ?* ?* ?* ?*r   r   )r   
contextlibr   typingr   r   r   base_protocolr   client_exceptionsr	   r
   r   r   helpersr   r   httpr   r   streamsr   r   r   r    r   r(   <module>r      s-          ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '            F E E E E E E E 8 8 8 8 8 8 8 8 ; ; ; ; ; ; ; ; ; ;w* w* w* w* w*lIe4F4T.U$V w* w* w* w* w*r   