
    tniN/              	           d dl Z d dlmZ d dlmZ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dS )    N)suppress)AnyOptionalTupleUnion   )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dej	        d         f         fd            Z
edefd            Zedefd            Zd/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 )0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 | _        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_closed_connection_lost_called)selfr   s     Q/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/aiohttp/client_proto.pyr!   zResponseHandler.__init__   s    d....4&&&"04"#
59.2CG!89$:>',$$$r   c                 h    | j         %| 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)
        )r-   r.   _loopcreate_futurer/   s    r0   closedzResponseHandler.closed4   s1     <(D:3355DL|r   c                     | j         S N)r(   r4   s    r0   upgradedzResponseHandler.upgradedF   s
    ~r   c                     t          | j        pI| j        d uo| j                                         p&| j        p| j        d up| j        d up| j        p| j                  S r7   )	boolr"   r#   is_eofr(   
_exceptionr%   _bufferr'   r4   s    r0   should_closezResponseHandler.should_closeJ   s     T)H$-2F2F2H2H.H~ d* #4/	
 | z
 
 	
r   c                     d| _         d S NT)r"   r4   s    r0   force_closezResponseHandler.force_closeV   s    !r   c                     d | _         | j        }|8|                                 d | _        d | _        |                                  d S d S r7   )r<   	transportcloser#   _drop_timeoutr/   rC   s     r0   rD   zResponseHandler.closeY   T    N	 OO!DN DM     	 ! r   c                     d | _         | j        }|8|                                 d | _        d | _        |                                  d S d S r7   )r<   rC   abortr#   rE   rF   s     r0   rI   zResponseHandler.abortb   rG   r   c                 H    | j         d uo| j                                          S r7   )rC   
is_closingr4   s    r0   is_connectedzResponseHandler.is_connectedk   s%    ~T)M$.2K2K2M2M.MMr   excc                    d| _         |                                  |}|}|d u }| j        B|rt          | j        d            n*|J t	          | j        t          d|          |           | j        Et          t                    5  | j        	                                 d d d            n# 1 swxY w Y   d }| j
        j	 | j
        	                                }nO# t          $ rB}| j        1d|}|s|d|}t	          | j        t          |          |           Y d }~nd }~ww xY w|                                 s]t          |t                    rt!          |j         }|rt%          |          }|rt&          n|}|J |J |                     ||           d| _        d | _
        d | _        d | _        d| _        t-                                          |           d S )NTzConnection lost: z#Response payload is not completed: z. F)r.   rE   r-   r   r   r
   r%   r   	Exceptionfeed_eofr)   r#   r   r;   
isinstanceOSErrorr   argsr   r   r"   _reading_pausedsuperconnection_lost)
r/   rM   original_connection_errorreraised_excconnection_closed_cleanlyuncompletedunderlying_excclient_payload_exc_msgunderlying_non_eof_exc	__class__s
            r0   rV   zResponseHandler.connection_lostn   s   '+$$'!0$=$E!<# ) 
4<....0<<<L)J,EJJ  .   +)$$ 0 0$--///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <#"l3355   =,QnQQ + 5 5 > >8> > / "*+ABB&    {{}} 	E3W== N,.G.LM( D6{CC
 -/. #
 *555+++|-CDDD!#$-----s*   	B//B36B3C 
D*(8D%%D*c                 .    |                                   d S r7   )rE   r4   s    r0   eof_receivedzResponseHandler.eof_received   s    r   c                 p    t                                                       |                                  d S r7   )rU   pause_readingrE   r/   r^   s    r0   rb   zResponseHandler.pause_reading   s1    r   c                 p    t                                                       |                                  d S r7   )rU   resume_reading_reschedule_timeoutrc   s    r0   re   zResponseHandler.resume_reading   s1         """""r   	exc_causec                     d| _         |                                  t                                          ||           d S r@   )r"   rE   rU   r   )r/   rM   rg   r^   s      r0   r   zResponseHandler.set_exception   s?    
 "c9-----r   parserpayloadc                     || _         || _        |                                  | j        r&| j        dc}| _        |                     |           d S d S )Nr   )r#   r%   rE   r'   data_received)r/   ri   rj   datas       r0   
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_sizero   rp   rq   rr   rs   rt   ru   rv   rw   c       	             || _         || _        || _        t          | | j        ||t
          | ||||	
  
        | _        | j        r&| j        dc}
| _        |                     |
           d S d S )N)ro   payload_exceptionresponse_with_bodyrq   rr   rv   rw   r   )	r$   r*   r,   r   r2   r   r)   r'   rl   )r/   ro   rp   rq   rr   rs   rt   ru   rv   rw   rm   s              r0   set_response_paramsz#ResponseHandler.set_response_params   s     *)'=$)J0#//)+')
 
 
 : 	%#z3D$*t$$$$$	% 	%r   c                 X    | j         "| j                                          d | _         d S d S r7   )r+   cancelr4   s    r0   rE   zResponseHandler._drop_timeout  s6    $0%,,...(,D%%% 10r   c                     | j         }| j        | j                                         |r'| j                            || j                  | _        d S d | _        d S r7   )r*   r+   r}   r2   
call_later_on_read_timeout)r/   timeouts     r0   rf   z#ResponseHandler._reschedule_timeout  sh    $$0%,,... 	-(,
(=(=.) )D%%% )-D%%%r   c                 .    |                                   d S r7   )rf   r4   s    r0   start_timeoutzResponseHandler.start_timeout  s      """""r   c                     | j         S r7   r*   r4   s    r0   rs   zResponseHandler.read_timeout  s    !!r   c                     || _         d S r7   r   )r/   rs   s     r0   rs   zResponseHandler.read_timeout  s    )r   c                     t          d          }|                     |           | j        t          | j        |           d S d S )Nz#Timeout on reading data from socket)r   r   r#   )r/   rM   s     r0   r   z ResponseHandler._on_read_timeout  sL     !FGG3=$$------ %$r   rm   c                    |                                   |sd S | j        F| j                            |          \  }}|r%d | _        d | _        |r|                     |           d S | j        s| j        | xj        |z  c_        d S 	 | j                            |          \  }}}n# t          $ r}| j	        | j	        
                                 t          |t                    r"t          |j        |j        |j                  }nt                      }|                     ||           Y d }~d S d }~ww xY w|| _        d }|D ]e\  }	}|	j        rd| _        || _        | j        s|	j        t(          v r|                     |	t*          fd           M|                     |	|fd           f|8|t*          ur|                    | j                   n|                                  |r|r|                     |           d S d S d S )N)codemessageheadersTr   )rf   r%   	feed_datar#   rl   r(   r)   r'   BaseExceptionrC   rD   rQ   r   r   r   r   r   r>   r"   r$   r   r   on_eofrE   )
r/   rm   eoftailmessagesr8   r[   rM   rj   r   s
             r0   rl   zResponseHandler.data_received#  su     """ 	F +,66t<<IC - $'+$ -&&t,,,F> 	T\1JJ$JJF	'+|'='=d'C'C$Hh 	 	 	~) $$&&&.*=>> ,)',*2*2   *++sN333FFFFF!	$ "*. ( 		6 		6GW# *%)"#DM! 6W\5L%L%L7;;;;115555
 m++t12222""$$$ 	% 	%t$$$$$	% 	% 	% 	%s   B& &
D60A;D11D6)r   N))__name__
__module____qualname____doc__asyncioAbstractEventLoopr!   propertyr   Futurer5   r:   r8   r>   rA   rD   rI   rL   r   r   rV   r`   rb   re   r   r   r   rn   r   floatintr{   rE   rf   r   rs   setterr   bytesrl   __classcell__)r^   s   @r0   r   r      s       BB-W6 -4 - - - -0 dGN4$889    X" $    X 	
d 	
 	
 	
 X	
" " " "! ! ! !! ! ! !Nd N N N NI.8M#: I.t I. I. I. I. I. I.V        # # # # # # $1. .. !. 
	. . . . . .% %s %t % % % %$ -1"$ $(,!()!""% "% "% ()"% 	"%
 "% "% uo"% "% !&"% "% "% 
"% "% "% "%H- - - -

- 
- 
- 
-# # # # "huo " " " X" *% *T * * * *. . . .D%% D%D D% D% D% D% D% D% D% D%r   r   ) r   
contextlibr   typingr   r   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      s|          . . . . . . . . . . . . ' ' ' ' ' '                           9 8 8 8 8 8 8 8 0 0 0 0 0 0 ; ; ; ; ; ; ; ; ; ;N% N% N% N% N%lIe4F4T.U$V N% N% N% N% N%r   