
    yi!              	           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y)    N)suppress)AnyOptionalTuple   )BaseProtocol)ClientOSErrorClientPayloadErrorServerDisconnectedErrorServerTimeoutError)BaseTimerContextstatus_code_must_be_empty_body)HttpResponseParserRawResponseMessage)EMPTY_PAYLOAD	DataQueueStreamReaderc                   h    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| _        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     O/root/polymarket_arb/.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_close-   s    ==$T]]-A-A-Ct~~   ~~ ~~t+  ##4/  4y1}	 
 DJJ	
r   c                     d| _         y NT)r   r+   s    r(   force_closezResponseHandler.force_close;   s
    !r   c                 ~    | j                   }|/|j                          d | _         d | _        | j                          y y r*   )	transportcloser   _drop_timeout)r'   r8   s     r(   r9   zResponseHandler.close>   s:    NN	 OO!DN DM 	 !r   c                 X    | j                   d uxr | j                   j                          S r*   )r8   
is_closingr+   s    r(   is_connectedzResponseHandler.is_connectedF   s&    ~~T)M$..2K2K2M.MMr   excc                    | j                          | j                  2t        t              5  | j                  j	                          d d d        d }| j
                  	 | j
                  j	                         }| j                         s@t        |t              rt        |j                   }|t        |      }| j                  |       d| _        d | _        d | _        d | _        d| _        t$        | M  |       y # 1 sw Y   xY w# t        $ rC}| j                  -t        d      }||_        | j                  j                  |       Y d }~d }~ww xY w)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 <<#5"ll335 {{}#w'#SXX.{-k: s#!#$$90 0  5==,,-PQC$%CMMM//4	5s#   C<D <D	E9EEc                 $    | j                          y r*   )r:   r+   s    r(   eof_receivedzResponseHandler.eof_receivedk   s    r   c                 B    t         |           | j                          y r*   )rH   pause_readingr:   r'   rL   s    r(   rP   zResponseHandler.pause_readingo   s    r   c                 B    t         |           | j                          y r*   )rH   resume_reading_reschedule_timeoutrQ   s    r(   rS   zResponseHandler.resume_readings   s       "r   c                 R    d| _         | j                          t        |   |       y r5   )r   r:   rH   rC   )r'   r>   rL   s     r(   rC   zResponseHandler.set_exceptionw   s$    !c"r   parserpayloadc                     || _         || _        | j                          | j                  r&| j                  dc}| _        | j	                  |       y y )Nr   )r   r   r:   r!   data_received)r'   rV   rW   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_sizer\   r]   r^   r_   r`   ra   rb   rc   rd   c       	             || _         || _        || _        t        | | j                  ||t
        | ||||	
      | _        | j                  r&| j                  dc}
| _        | j                  |
       y y )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{     *)'=$)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%   rk   rh   
call_later_on_read_timeout)r'   timeouts     r(   rT   z#ResponseHandler._reschedule_timeout   sZ    $$$$0%%,,.(,

(=(=..)D% )-D%r   c                 $    | j                          y r*   )rT   r+   s    r(   start_timeoutzResponseHandler.start_timeout   s      "r   c                     t        d      }| j                  |       | j                  | j                  j                  |       y y )Nz#Timeout on reading data from socket)r   rC   r   )r'   r>   s     r(   rn   z ResponseHandler._on_read_timeout   s<     !FG3==$MM'', %r   rZ   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        $ rA}| j                  | j                  j                          | j                  |       Y d }~y d }~ww xY w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   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 ,,.&&s+s   F   	G
	7GG
)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      sz   B:W66 :4 :* $   
d 
 
"!Nd 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      sM      ' ' '  F 8 ; ;w*lIe4F4T.U$V w*r   