
    3Cf&              	           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eeeeef            Zy)    N)suppress)AnyOptionalTuple   )BaseProtocol)ClientOSErrorClientPayloadErrorServerDisconnectedErrorServerTimeoutError)_EXC_SENTINELBaseTimerContextset_exceptionstatus_code_must_be_empty_body)HttpResponseParserRawResponseMessage)HttpProcessingError)EMPTY_PAYLOAD	DataQueueStreamReaderc                   p    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efde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| _        y )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     T/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/aiohttp/client_proto.pyr   zResponseHandler.__init__   su    d.4&"04"#
59.2CG!89$r   c                     | j                   S N)r%   r*   s    r+   upgradedzResponseHandler.upgraded/   s    ~~r   c                 2   | j                   | j                   j                         r| j                  ry| j                  xsW | j                  xsI | j	                         d uxs5 | j
                  d uxs% t        |       dkD  xs t        | j                        S NTr   )	r    is_eofr%   r   	exceptionr"   lenboolr$   r.   s    r+   should_closezResponseHandler.should_close3   s    ==$T]]-A-A-Ct~~   ~~ ~~t+  ##4/  4y1}	 
 DJJ	
r   c                     d| _         y NT)r   r.   s    r+   force_closezResponseHandler.force_closeA   s
    !r   c                 ~    | j                   }|/|j                          d | _         d | _        | j                          y y r-   )	transportcloser    _drop_timeout)r*   r;   s     r+   r<   zResponseHandler.closeD   s:    NN	 OO!DN DM 	 !r   c                 X    | j                   d uxr | j                   j                          S r-   )r;   
is_closingr.   s    r+   is_connectedzResponseHandler.is_connectedL   s&    ~~T)M$..2K2K2M.MMr   excc                    | j                          |}|}|d u }| j                  2t        t              5  | j                  j	                          d d d        d }| j
                  	 | j
                  j	                         }| j                         sSt        |t              rt        |j                   }|rt        |      }|rt        n|}|J |J | j                  ||       d| _        d | _        d | _        d | _        d| _        t$        	| M  |       y # 1 sw Y   xY w# t        $ rD}| j                  .d|}|s|d|}t        | j                  t        |      |       Y d }~d }~ww xY w)Nz#Response payload is not completed: z. TF)r=   r"   r   	Exceptionfeed_eofr&   r    r   r
   r2   
isinstanceOSErrorr	   argsr   r   r   _reading_pausedsuperconnection_lost)
r*   rA   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__s
            r+   rJ   zResponseHandler.connection_lostO   s   $'!0$=$E!+)$ 0$$--/0 <<#"ll335" {{}3W=,.G.L.LM(6{C
 - . #
 *555+++|-CD!#$-[0 0  ==,=n=PQ + 5598<> / "*+AB&s#   D'D# D #	E0,:E++E0c                 $    | j                          y r-   )r=   r.   s    r+   eof_receivedzResponseHandler.eof_received   s    r   c                 B    t         |           | j                          y r-   )rI   pause_readingr=   r*   rR   s    r+   rV   zResponseHandler.pause_reading   s    r   c                 B    t         |           | j                          y r-   )rI   resume_reading_reschedule_timeoutrW   s    r+   rY   zResponseHandler.resume_reading   s       "r   	exc_causec                 T    d| _         | j                          t        |   ||       y r8   )r   r=   rI   r   )r*   rA   r[   rR   s      r+   r   zResponseHandler.set_exception   s(    
 "c9-r   parserpayloadc                     || _         || _        | j                          | j                  r&| j                  dc}| _        | j	                  |       y y )Nr   )r    r"   r=   r$   data_received)r*   r]   r^   datas       r+   
set_parserzResponseHandler.set_parser   sK      %::#zz3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_sizerc   rd   re   rf   rg   rh   ri   rj   rk   c       	             || _         || _        || _        t        | | j                  ||t
        | ||||	
      | _        | j                  r&| j                  dc}
| _        | j                  |
       y y )N)rc   payload_exceptionresponse_with_bodyre   rf   rj   rk   r   )	r!   r'   r)   r   _loopr
   r&   r$   r`   )r*   rc   rd   re   rf   rg   rh   ri   rj   rk   ra   s              r+   set_response_paramsz#ResponseHandler.set_response_params   s{     *)'=$)JJ0#//)+')
 ::#zz3D$*t$ r   c                 `    | j                   "| j                   j                          d | _         y y r-   )r(   cancelr.   s    r+   r=   zResponseHandler._drop_timeout   s-    $$0%%,,.(,D% 1r   c                     | j                   }| j                  | j                  j                          |r,| j                  j	                  || j
                        | _        y d | _        y r-   )r'   r(   rr   ro   
call_later_on_read_timeout)r*   timeouts     r+   rZ   z#ResponseHandler._reschedule_timeout   sZ    $$$$0%%,,.(,

(=(=..)D% )-D%r   c                 $    | j                          y r-   )rZ   r.   s    r+   start_timeoutzResponseHandler.start_timeout   s      "r   c                     t        d      }| j                  |       | j                  t        | j                  |       y y )Nz#Timeout on reading data from socket)r   r   r    )r*   rA   s     r+   ru   z ResponseHandler._on_read_timeout   s8     !FG3==$$--- %r   ra   c                    | j                          |sy | j                  B| j                  j                  |      \  }}|r!d | _        d | _        |r| j	                  |       y | j
                  s| j                  | xj                  |z  c_        y 	 | j                  j                  |      \  }}}|| _        d }|D ]m  \  }}|j                  rd| _        || _        | j                  st!        |j"                        r| j                  |t$        fd       Z| j                  ||fd       o |4|t$        ur|j'                  | j(                         n| j)                          |r|r| j	                  |       y || _        y y # t        $ rJ}| j                  | j                  j                          | j                  t               |       Y d }~y d }~ww xY wr1   )rZ   r"   	feed_datar    r`   r%   r&   r$   BaseExceptionr;   r<   r   r   r6   r   r!   r   coder   on_eofr=   )	r*   ra   eoftailmessagesr/   rO   r^   messages	            r+   r`   zResponseHandler.data_received   s     " +,,66t<IC $'+$&&t,~~!5

d"

/3||/E/Ed/K,Hh "*26(0 >$GW++-1*$+DM))-K. '?C'91=> &
 m3t'9'9:**,**40%)
	 G % ~~1 ,,.&&':'<nMs   F   	G	A GG)r   N)#__name__
__module____qualname____doc__asyncioAbstractEventLoopr   propertyr5   r/   r6   r9   r<   r@   r   r|   rJ   rT   rV   rY   r   r   r   rb   r   floatintrp   r=   rZ   rx   ru   bytesr`   __classcell__)rR   s   @r+   r   r      s   B:W66 :4 :* $   
d 
 
"!Nd N6.8M#: 6.t 6.p# $1.. !. 
	.% %s %t %$ -1"$ $(,!()!""% ()"% 	"%
 "% "% uo"% "% !&"% "% "% 
"%H-

-#.?*% ?*D ?*r   r   )r   
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+   <module>r      sV      ' ' '   9 0 ; ;Q*lIe4F4T.U$V Q*r   