
     @g!                       d dl mZ d dlZd dlZd dlZd dlZd dlZddlmZ ddl	m
Z
mZmZ ddlmZmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dZ ej        d          Z ddZ! G d de          Z"dS )    )annotationsN   )AutoBackend)SOCKET_OPTIONAsyncNetworkBackendAsyncNetworkStream)ConnectErrorConnectTimeout)OriginRequestResponse)default_ssl_context)	AsyncLock)Trace   )AsyncHTTP11Connection)AsyncConnectionInterfaceg      ?zhttpcore.connectionfactorfloatreturntyping.Iterator[float]c              #  R   K   dV  t          j                    D ]}| d|z  z  V  dS )z
    Generate a geometric sequence that has a ratio of 2 and starts with 0.

    For example:
    - `factor = 2`: `0, 2, 4, 8, 16, 32, 64, ...`
    - `factor = 3`: `0, 3, 6, 12, 24, 48, 96, ...`
    r   r   N)	itertoolscount)r   ns     N/var/www/piapp/venv/lib/python3.11/site-packages/httpcore/_async/connection.pyexponential_backoffr      sI       GGG_  q!tm     c                      e Zd Z	 	 	 	 	 	 	 	 	 d1d2dZd3dZd4dZd5d Zd6d!Zd7d"Zd7d#Z	d7d$Z
d7d%Zd8d'Zd8d(Zd9d)Z	 	 	 d:d;d0ZdS )<AsyncHTTPConnectionNTFr   originr   ssl_contextssl.SSLContext | Nonekeepalive_expiryfloat | Nonehttp1boolhttp2retriesintlocal_address
str | Noneudsnetwork_backendAsyncNetworkBackend | Nonesocket_options%typing.Iterable[SOCKET_OPTION] | Noner   Nonec                    || _         || _        || _        || _        || _        || _        || _        || _        |	t                      n|	| _	        d | _
        d| _        t                      | _        |
| _        d S )NF)_origin_ssl_context_keepalive_expiry_http1_http2_retries_local_address_udsr   _network_backend_connection_connect_failedr   _request_lock_socket_options)selfr!   r"   r$   r&   r(   r)   r+   r-   r.   r0   s              r   __init__zAsyncHTTPConnection.__init__'   s     '!1+	 -4KMMM/ 	 =A%*&[[-r   requestr   r   c                  K   |                      |j        j                  s$t          d|j        j         d| j                   	 | j        4 d {V  | j        |                     |           d {V }|                    d          }|d uo|	                                dk    }|s| j
        r+| j        s$ddlm}  || j        || j                  | _        n!t          | j        || j                  | _        	 d d d           d {V  n# 1 d {V swxY w Y   n# t           $ r}d| _        |d }~ww xY w| j                            |           d {V S )	NzAttempted to send request to z on connection to 
ssl_objecth2r   )AsyncHTTP2Connection)r!   streamr$   T)can_handle_requesturlr!   RuntimeErrorr4   r?   r=   _connectget_extra_infoselected_alpn_protocolr8   r7   r(   rG   r6   r   BaseExceptionr>   handle_async_request)rA   rC   rH   rE   http2_negotiatedrG   excs          r   rP   z(AsyncHTTPConnection.handle_async_requestE   sR     &&w{'9:: 	d0BddVZVbdd  	)        #+#'==#9#9999999F!'!6!6|!D!DJ"$. H&==??4G % ( DK  ??????+?+?#'<#)-1-C, , ,(( ,A#'<#)-1-C, , ,( %                          .  	 	 	#'D I	 %::7CCCCCCCCCs=   D" B)D>D" 
DD" DD" "
D:,	D55D:r   c                  K   |j                             di           }|j                             dd           }|                    dd           }| j        }t          t                    }	 	 | j        | j        j                            d          | j        j	        | j
        || j        d}t          dt          ||          4 d {V } | j        j        di | d {V }	|	|_        d d d           d {V  n# 1 d {V swxY w Y   nq| j        || j        d	}t          d
t          ||          4 d {V 	 } | j        j        di | d {V }	|	|_        d d d           d {V  n# 1 d {V swxY w Y   | j        j        dv r| j        t)                      n| j        }
| j        rddgndg}|
                    |           |
|p| j        j                            d          |d}t          dt          ||          4 d {V } |	j        di | d {V }	|	|_        d d d           d {V  n# 1 d {V swxY w Y   |	S # t0          t2          f$ r |dk    r |dz  }t5          |          }t          dt          ||          4 d {V }| j                            |           d {V  d d d           d {V  n# 1 d {V swxY w Y   Y nw xY ww)Ntimeoutsni_hostnameconnect)r   Tascii)hostportr+   rT   r0   connect_tcp)pathrT   r0   connect_unix_socket)   httpss   wsszhttp/1.1rF   )r"   server_hostnamerT   	start_tlsr   r   retry )
extensionsgetr9   r   RETRIES_BACKOFF_FACTORr;   r4   rX   decoderY   r:   r@   r   loggerr<   rZ   return_valuer\   schemer5   r   r8   set_alpn_protocolsr_   r	   r
   nextsleep)rA   rC   timeoutsrU   rT   retries_leftdelayskwargstracerH   r"   alpn_protocolsdelays                r   rL   zAsyncHTTPConnection._connecti   s     %)))R88)--ndCC,,y$//}$,BCCC4	=3=9$ $ 1 8 8 A A $ 1)-)<#**.*> F  %]FGVLL 4 4 4 4 4 4 4PU'Ht'<'H'R'R6'R'R!R!R!R!R!R!R-3*4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
 !%	#**.*> F
  %-vw    4 4 4 4 4 4 4 4'Pt'<'P ( ($( ( " " " " " " .4*4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 <&*<<<  ,4 ,---!.  
 <@;%Xj$%7%7ZLN22>BBB (3+7 ,=<,33G<<#*	 F  %[&'6JJ 4 4 4 4 4 4 4e'7v'7'A'A&'A'A!A!A!A!A!A!A-3*4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4  .1 = = =1$$!V &'6BB = = = = = = =e/55e<<<<<<<<<= = = = = = = = = = = = = = = = = = = = = = = = = = ==]4	=s   -AI 
 C<*I <
DI 	D
1I < E.I .
E88I ;E8<BI H;)I ;
II I	I A	K!K
8K

K	KK	KKc                    || j         k    S N)r4   )rA   r!   s     r   rI   z&AsyncHTTPConnection.can_handle_request   s    %%r   c                   K   | j         ct          dt          d i           4 d {V  | j                                          d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S d S )Nclose)r=   r   rf   acloserA   s    r   rw   zAsyncHTTPConnection.aclose   s     'WfdB77 0 0 0 0 0 0 0 0&--/////////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ('s    A
A$'A$c                    | j         '| j        o| j        j        dk    p| j         o| j         S | j                                         S )Nr]   )r=   r8   r4   rh   r7   r>   is_availablerx   s    r   rz   z AsyncHTTPConnection.is_available   sW    #
  -\(H4GDK-,,
 ,,...r   c                P    | j         | j        S | j                                         S rt   )r=   r>   has_expiredrx   s    r   r|   zAsyncHTTPConnection.has_expired   s)    #''++---r   c                P    | j         | j        S | j                                         S rt   )r=   r>   is_idlerx   s    r   r~   zAsyncHTTPConnection.is_idle   s)    #'''')))r   c                P    | j         | j        S | j                                         S rt   )r=   r>   	is_closedrx   s    r   r   zAsyncHTTPConnection.is_closed   s)    #''))+++r   strc                X    | j         | j        rdndS | j                                         S )NzCONNECTION FAILED
CONNECTING)r=   r>   inforx   s    r   r   zAsyncHTTPConnection.info   s4    #*.*>P&&LP$$&&&r   c                L    d| j         j         d|                                  dS )N<z [z]>)	__class____name__r   rx   s    r   __repr__zAsyncHTTPConnection.__repr__   s(    =4>*==diikk====r   c                
   K   | S rt   ra   rx   s    r   
__aenter__zAsyncHTTPConnection.__aenter__   s      r   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebacktypes.TracebackType | Nonec                >   K   |                                   d {V  d S rt   )rw   )rA   r   r   r   s       r   	__aexit__zAsyncHTTPConnection.__aexit__   s.       kkmmr   )	NNTFr   NNNN)r!   r   r"   r#   r$   r%   r&   r'   r(   r'   r)   r*   r+   r,   r-   r,   r.   r/   r0   r1   r   r2   )rC   r   r   r   )rC   r   r   r   )r!   r   r   r'   )r   r2   )r   r'   )r   r   )r   r    )NNN)r   r   r   r   r   r   r   r2   )r   
__module____qualname__rB   rP   rL   rI   rw   rz   r|   r~   r   r   r   r   r   ra   r   r   r    r    &   sP        .2)-$(6:@D. . . . .<"D "D "D "DH<= <= <= <=|& & & &0 0 0 0

/ 
/ 
/ 
/. . . .
* * * *
, , , ,
' ' ' '
> > > >   
 04*.04	      r   r    )r   r   r   r   )#
__future__r   r   loggingssltypestyping_backends.autor   _backends.baser   r   r   _exceptionsr	   r
   _modelsr   r   r   _sslr   _synchronizationr   _tracer   http11r   
interfacesr   rd   	getLoggerrf   r   r    ra   r   r   <module>r      su   " " " " " "      



   ( ( ( ( ( ( S S S S S S S S S S 6 6 6 6 6 6 6 6 / / / / / / / / / / & & & & & & ( ( ( ( ( (       ) ) ) ) ) ) 0 0 0 0 0 0  
	0	1	1
 
 
 
x x x x x2 x x x x xr   