
    !:h~*              	           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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eeeeef            Zy)    N)suppress)AnyOptionalTuple   )BaseProtocol)ClientConnectionErrorClientOSErrorClientPayloadErrorServerDisconnectedErrorSocketTimeoutError)_EXC_SENTINELEMPTY_BODY_STATUS_CODESBaseTimerContextset_exception
set_result)HttpResponseParserRawResponseMessage)HttpProcessingError)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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edee   fd(       Zej@                  dee   ddf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                 6   t        j                  | |       t        j                  | |       d| _        d | _        d| _        d | _        d | _        d| _        d| _	        d | _
        d | _        d | _        d| _        | j                  j                         | _        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_loopcreate_futureclosed)selfr   s     N/var/www/html/turnos/venv/lib/python3.12/site-packages/aiohttp/client_proto.pyr    zResponseHandler.__init__   s    d.4&"04"#
59.2CG!89$,0JJ,D,D,Fr   c                     | j                   S N)r'   r/   s    r0   upgradedzResponseHandler.upgraded2   s    ~~r   c                    t        | j                  xsu | j                  d uxr | j                  j                          xsH | j                  xs: | j
                  d uxs* | j                  d uxs | j                  xs | j                        S r2   )	boolr!   r"   is_eofr'   
_exceptionr$   _bufferr&   r3   s    r0   should_closezResponseHandler.should_close6   s     T)H$--2F2F2H.H~~ d* ##4/	
 || zz
 	
r   c                     d| _         y NT)r!   r3   s    r0   force_closezResponseHandler.force_closeB   s
    !r   c                     d | _         | j                  }|/|j                          d | _        d | _        | j	                          y y r2   )r8   	transportcloser"   _drop_timeout)r/   r?   s     r0   r@   zResponseHandler.closeE   sA    NN	 OO!DN DM 	 !r   c                 X    | j                   d uxr | j                   j                          S r2   )r?   
is_closingr3   s    r0   is_connectedzResponseHandler.is_connectedN   s&    ~~T)M$..2K2K2M.MMr   excc                    | j                          |}|}|d u }|rt        | j                  d        nY|J t        | j                  t	        d|      |       t        t              5  | j                  j                          d d d        | 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,        	| ]  |       y # 1 sw Y   xY w# 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Connection lost: z#Response payload is not completed: z. TF)rA   r   r.   r   r	   r   	Exception	exceptionr$   feed_eofr(   r"   r   r7   
isinstanceOSErrorr
   argsr   r   r!   _reading_pausedsuperconnection_lost)
r/   rE   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__s
            r0   rO   zResponseHandler.connection_lostQ   s	   $'!0$=$E!$t{{D),888%'(A'EF * )$ (%%'( +)$ 0$$--/0 <<#"ll335" {{}3W=,.G.L.LM(6{C
 - . #
 *555+++|-CD!#$-c( (0 0  ==,=n=PQ + 5598<> / "*+AB&s0   )F	'FF" 	FF"	G/+:G**G/c                 $    | j                          y r2   )rA   r3   s    r0   eof_receivedzResponseHandler.eof_received   s    r   c                 B    t         |           | j                          y r2   )rN   pause_readingrA   r/   rW   s    r0   r[   zResponseHandler.pause_reading   s    r   c                 B    t         |           | j                          y r2   )rN   resume_reading_reschedule_timeoutr\   s    r0   r^   zResponseHandler.resume_reading   s       "r   	exc_causec                 T    d| _         | j                          t        |   ||       y r<   )r!   rA   rN   r   )r/   rE   r`   rW   s      r0   r   zResponseHandler.set_exception   s(    
 "c9-r   parserpayloadc                     || _         || _        | j                          | j                  r&| j                  dc}| _        | j	                  |       y y )Nr   )r"   r$   rA   r&   data_received)r/   rb   rc   datas       r0   
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_sizerh   ri   rj   rk   rl   rm   rn   ro   rp   c       	             || _         || _        || _        t        | | j                  ||t
        | ||||	
      | _        | j                  r&| j                  dc}
| _        | j                  |
       y y )N)rh   payload_exceptionresponse_with_bodyrj   rk   ro   rp   r   )	r#   r)   r+   r   r,   r   r(   r&   re   )r/   rh   ri   rj   rk   rl   rm   rn   ro   rp   rf   s              r0   set_response_paramsz#ResponseHandler.set_response_params   s{     *)'=$)JJ0#//)+')
 ::#zz3D$*t$ r   c                 `    | j                   "| j                   j                          d | _         y y r2   )r*   cancelr3   s    r0   rA   zResponseHandler._drop_timeout   s-    $$0%%,,.(,D% 1r   c                     | j                   }| j                  | j                  j                          |r,| j                  j	                  || j
                        | _        y d | _        y r2   )r)   r*   rv   r,   
call_later_on_read_timeout)r/   timeouts     r0   r_   z#ResponseHandler._reschedule_timeout   sZ    $$$$0%%,,.(,

(=(=..)D% )-D%r   c                 $    | j                          y r2   )r_   r3   s    r0   start_timeoutzResponseHandler.start_timeout   s      "r   c                     | j                   S r2   r)   r3   s    r0   rl   zResponseHandler.read_timeout   s    !!!r   c                     || _         y r2   r~   )r/   rl   s     r0   rl   zResponseHandler.read_timeout   s
    )r   c                     t        d      }| j                  |       | j                  t        | j                  |       y y )Nz#Timeout on reading data from socket)r   r   r"   )r/   rE   s     r0   ry   z ResponseHandler._on_read_timeout   s8     !FG3==$$--- %r   rf   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 ]j  \  }	}|	j"                  rd| _        || _        | j&                  s|	j                  t(        v r| j                  |	t*        fd       W| j                  |	|fd       l |4|t*        ur|j-                  | j.                         n| j/                          |r|r| j	                  |       y y y # t        $ r}| j                  | j                  j                          t        |t              r-t        |j                  |j                  |j                        }n
t               }| j!                  ||       Y d }~y d }~ww xY w)N)codemessageheadersTr   )r_   r$   	feed_datar"   re   r'   r(   r&   BaseExceptionr?   r@   rJ   r   r   r   r   r   r:   r!   r#   r   r   on_eofrA   )
r/   rf   eoftailmessagesr4   rT   rE   rc   r   s
             r0   re   zResponseHandler.data_received  s     " +,,66t<IC $'+$&&t,>>T\\1JJ$J	'+||'='=d'C$Hh& "*. ( 		6GW##%)"#DM!!W\\5L%L7;115		6 
 m+t112""$t$ 8U  	~~) $$&.*=>)',,*22*22 *+sN3!	s   E6 6	H?A?HH)r   N)%__name__
__module____qualname____doc__asyncioAbstractEventLoopr    propertyr6   r4   r:   r=   r@   rD   r   r   rO   rY   r[   r^   r   r   r   rg   r   floatintrt   rA   r_   r|   rl   setterry   bytesre   __classcell__)rW   s   @r0   r   r      s   BGW66 G4 G, $   	
d 	
 	
"!Nd NH.8M#: H.t H.T# $1.. !. 
	.% %s %t %$ -1"$ $(,!()!""% ()"% 	"%
 "% "% uo"% "% !&"% "% "% 
"%H-

-# "huo " " *% *T * *.D%% D%D D%r   r   )r   
contextlibr   typingr   r   r   base_protocolr   client_exceptionsr	   r
   r   r   r   helpersr   r   r   r   r   httpr   r   http_exceptionsr   streamsr   r   r   r    r   r0   <module>r      sV      ' ' '   9 0 ; ;p%lIe4F4T.U$V p%r   