
     @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   )SyncBackend)SOCKET_OPTIONNetworkBackendNetworkStream)ConnectErrorConnectTimeout)OriginRequestResponse)default_ssl_context)Lock)Trace   )HTTP11Connection)ConnectionInterfaceg      ?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     M/var/www/piapp/venv/lib/python3.11/site-packages/httpcore/_sync/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 )<HTTPConnectionNTFr   originr   ssl_contextssl.SSLContext | Nonekeepalive_expiryfloat | Nonehttp1boolhttp2retriesintlocal_address
str | Noneudsnetwork_backendNetworkBackend | 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HTTPConnection.__init__'   s     '!1+	 -4KMMM/ 	 8<%*!VV-r   requestr   r   c                x   |                      |j        j                  s$t          d|j        j         d| j                   	 | j        5  | j        |                     |          }|                    d          }|d uo|	                                dk    }|s| j
        r+| j        s$ddlm}  || j        || j                  | _        n!t          | j        || j                  | _        d d d            n# 1 swxY w Y   n# t           $ r}d| _        |d }~ww xY w| j                            |          S )	NzAttempted to send request to z on connection to 
ssl_objecth2r   )HTTP2Connection)r!   streamr$   T)can_handle_requesturlr!   RuntimeErrorr4   r?   r=   _connectget_extra_infoselected_alpn_protocolr8   r7   r(   rG   r6   r   BaseExceptionr>   handle_request)rA   rC   rH   rE   http2_negotiatedrG   excs          r   rP   zHTTPConnection.handle_requestE   s   &&w{'9:: 	d0BddVZVbdd  	#  #+!]]733F!'!6!6|!D!DJ"$. H&==??4G % ( DK  ::::::+:?#'<#)-1-C, , ,(( ,<#'<#)-1-C, , ,(%              .  	 	 	#'D I	 ..w777s=   D B#C;/D ;C??D C?D 
D	DDr   c                    |j                             di           }|j                             dd           }|                    dd           }| j        }t          t                    }	 	 | j        | j        j                            d          | j        j	        | j
        || j        d}t          dt          ||          5 } | j        j        di |}	|	|_        d d d            n# 1 swxY w Y   nX| j        || j        d	}t          d
t          ||          5 } | j        j        di |}	|	|_        d d d            n# 1 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          ||          5 } |	j        di |}	|	|_        d d d            n# 1 swxY w Y   |	S # t0          t2          f$ rg |dk    r |dz  }t5          |          }t          dt          ||          5 }| j                            |           d d d            n# 1 swxY w Y   Y nw xY 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HTTPConnection._connecti   s   %)))R88)--ndCC,,y$//}$,BCCC4	7379$ $ 1 8 8 A A $ 1)-)<#**.*> F }fgvFF 4%!B!6!B!L!LV!L!L-3*4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
 !%	#**.*> F
 -vw  4!J!6!J " "$" " .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 {FGVDD 4!1!1!;!;F!;!;-3*4 4 4 4 4 4 4 4 4 4 4 4 4 4 4  .1 7 7 71$$!V7FGV<< 7)//6667 7 7 7 7 7 7 7 7 7 7 7 7 7 77]4	7s   +AH C(H (C,,H /C,0+H E5H EH E	BH G6*H 6G::H =G:>H AI;I-!I;-I1	1I;4I1	5I;:I;c                    || j         k    S N)r4   )rA   r!   s     r   rI   z!HTTPConnection.can_handle_request   s    %%r   c                    | j         Kt          dt          d i           5  | j                                          d d d            d S # 1 swxY w Y   d S d S )Nclose)r=   r   rf   rv   rA   s    r   rv   zHTTPConnection.close   s    'wb11 ) ) &&((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ('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_availablerw   s    r   ry   zHTTPConnection.is_available   sW    #
  -\(H4GDK-,,
 ,,...r   c                P    | j         | j        S | j                                         S rt   )r=   r>   has_expiredrw   s    r   r{   zHTTPConnection.has_expired   s)    #''++---r   c                P    | j         | j        S | j                                         S rt   )r=   r>   is_idlerw   s    r   r}   zHTTPConnection.is_idle   s)    #'''')))r   c                P    | j         | j        S | j                                         S rt   )r=   r>   	is_closedrw   s    r   r   zHTTPConnection.is_closed   s)    #''))+++r   strc                X    | j         | j        rdndS | j                                         S )NzCONNECTION FAILED
CONNECTING)r=   r>   inforw   s    r   r   zHTTPConnection.info   s4    #*.*>P&&LP$$&&&r   c                L    d| j         j         d|                                  dS )N<z [z]>)	__class____name__r   rw   s    r   __repr__zHTTPConnection.__repr__   s(    =4>*==diikk====r   c                    | S rt   ra   rw   s    r   	__enter__zHTTPConnection.__enter__   s    r   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebacktypes.TracebackType | Nonec                .    |                                   d S rt   )rv   )rA   r   r   r   s       r   __exit__zHTTPConnection.__exit__   s     	

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   rv   ry   r{   r}   r   r   r   r   r   ra   r   r   r    r    &   sL        .2)-$(15@D. . . . .<"8 "8 "8 "8H<7 <7 <7 <7|& & & &) ) ) )

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



   ( ( ( ( ( ( I I I I I I I I I I 6 6 6 6 6 6 6 6 / / / / / / / / / / & & & & & & # # # # # #       $ $ $ $ $ $ + + + + + +  
	0	1	1
 
 
 
x x x x x( x x x x xr   