
    6=gC                        S SK Jr  S SKrS SKrS SKrS SKrSSKJr  SSKJ	r	J
r
  SSKJrJr  SSKJrJrJrJr  SSKJrJrJr  S	S
KJr  S	SKJrJr   " S S5      r " S S\5      r " S S5      rg)    )annotationsN   )AutoBackend)SOCKET_OPTIONAsyncNetworkBackend)ConnectionNotAvailableUnsupportedProtocol)OriginProxyRequestResponse)
AsyncEventAsyncShieldCancellationAsyncThreadLock   )AsyncHTTPConnection)AsyncConnectionInterfaceAsyncRequestInterfacec                  R    \ rS rSrS	S jrS
S jrSS jr S   SS jjrSS jrSr	g)AsyncPoolRequest   c                <    Xl         S U l        [        5       U l        g N)request
connectionr   _connection_acquired)selfr   s     A/usr/lib/python3/dist-packages/httpcore/_async/connection_pool.py__init__AsyncPoolRequest.__init__   s    ;?$.L!    c                D    Xl         U R                  R                  5         g r   )r   r   set)r   r   s     r   assign_to_connection%AsyncPoolRequest.assign_to_connection   s    $!!%%'r!   c                0    S U l         [        5       U l        g r   )r   r   r   r   s    r   clear_connection!AsyncPoolRequest.clear_connection   s    $.L!r!   Nc                   #    U R                   c!  U R                  R                  US9I S h  vN   U R                   c   eU R                   $  N7f)Ntimeout)r   r   wait)r   r,   s     r   wait_for_connection$AsyncPoolRequest.wait_for_connection   sN      ??"++000AAA*** Bs   *AA Ac                    U R                   S L $ r   )r   r'   s    r   	is_queuedAsyncPoolRequest.is_queued'   s    $&&r!   )r   r   r   )r   r   returnNone)r   zAsyncConnectionInterface | Noner3   r4   r3   r4   r   )r,   float | Noner3   r   )r3   bool)
__name__
__module____qualname____firstlineno__r   r$   r(   r.   r1   __static_attributes__ r!   r   r   r      s0    1
(1
 '+#	!'r!   r   c                      \ rS rSrSr            S                         SS jjrSS jr\SS j5       rSS jr	SS jr
SS	 jrSS
 jrSS jr   S       SS jjrSS jrSrg)AsyncConnectionPool+   z-
A connection pool for making HTTP requests.
Nc                   Xl         X l        Uc  [        R                  OUU l        Uc  [        R                  OUU l        [        U R                  U R
                  5      U l        XPl        X`l        Xpl	        Xl
        Xl        Xl        Uc
  [        5       OUU l        Xl        / U l        / U l        [%        5       U l        g)aC  
A connection pool for making HTTP requests.

Parameters:
    ssl_context: An SSL context to use for verifying connections.
        If not specified, the default `httpcore.default_ssl_context()`
        will be used.
    max_connections: The maximum number of concurrent HTTP connections that
        the pool should allow. Any attempt to send a request on a pool that
        would exceed this amount will block until a connection is available.
    max_keepalive_connections: The maximum number of idle HTTP connections
        that will be maintained in the pool.
    keepalive_expiry: The duration in seconds that an idle HTTP connection
        may be maintained for before being expired from the pool.
    http1: A boolean indicating if HTTP/1.1 requests should be supported
        by the connection pool. Defaults to True.
    http2: A boolean indicating if HTTP/2 requests should be supported by
        the connection pool. Defaults to False.
    retries: The maximum number of retries when trying to establish a
        connection.
    local_address: Local address to connect from. Can also be used to connect
        using a particular address family. Using `local_address="0.0.0.0"`
        will connect using an `AF_INET` address (IPv4), while using
        `local_address="::"` will connect using an `AF_INET6` address (IPv6).
    uds: Path to a Unix Domain Socket to use instead of TCP sockets.
    network_backend: A backend instance to use for handling network I/O.
    socket_options: Socket options that have to be included
     in the TCP socket when the connection was established.
N)_ssl_context_proxysysmaxsize_max_connections_max_keepalive_connectionsmin_keepalive_expiry_http1_http2_retries_local_address_udsr   _network_backend_socket_options_connections	_requestsr   _optional_thread_lock)r   ssl_contextproxymax_connectionsmax_keepalive_connectionskeepalive_expiryhttp1http2retrieslocal_addressudsnetwork_backendsocket_optionss                r   r   AsyncConnectionPool.__init__0   s    X (*2CKK 	
 )0 KK* 	'
 +.!!4#B#B+
' "2+	 -4KM/ 	  . =?13
 &5%6"r!   c                :   U R                   Gb  U R                   R                  R                  S;   aw  SSKJn  U" U R                   R                  R
                  U R                   R                  UU R                  U R                  U R                  U R                  U R                  S9$ UR                  S:X  ak  SSKJn  U" U R                   R                  R
                  U R                   R                  U R                   R                  UU R                  U R                  S9$ SSKJn  U" U R                   R                  R
                  U R                   R                  U R                   R                  UU R                  U R                  U R                  U R                  U R                  S	9	$ [#        UU R                  U R                  U R                  U R                  U R$                  U R&                  U R(                  U R                  U R*                  S
9
$ )N)s   socks5s   socks5hr   )AsyncSocks5Connection)proxy_origin
proxy_authremote_originrT   rX   rY   rZ   r^   s   http)AsyncForwardHTTPConnection)rc   proxy_headersproxy_ssl_contextre   rX   r^   )AsyncTunnelHTTPConnection)	rc   rg   rh   re   rT   rX   rY   rZ   r^   )
originrT   rX   rY   rZ   r[   r\   r]   r^   r_   )rC   urlschemesocks_proxyrb   rj   authrB   rI   rJ   rK   rO   
http_proxyrf   headersrT   ri   r   rL   rM   rN   rP   )r   rj   rb   rf   ri   s        r   create_connection%AsyncConnectionPool.create_connection   s   ;;"{{%%)@@>,!%!7!7#{{//"( $ 1 1%)%;%;++++$($9$9	 	 ')B1!%!7!7"&++"5"5&*kk&=&="(%)%;%;$($9$9  >,![[__33"kk11"&++"9"9$ --!%!7!7kkkk $ 5 5
 
 #))!33++++MM--		 11//
 	
r!   c                ,    [        U R                  5      $ )a{  
Return a list of the connections currently in the pool.

For example:

```python
>>> pool.connections
[
    <AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 6]>,
    <AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 9]> ,
    <AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>,
]
```
)listrQ   r'   s    r   connectionsAsyncConnectionPool.connections   s      D%%&&r!   c           
       #    UR                   R                  R                  5       nUS:X  a  [        S5      eUS;  a  [        SU S35      eUR                  R                  S0 5      nUR                  SS5      nU R                     [        U5      nU R                  R                  U5        SSS5          U R                     U R                  5       nSSS5        U R                  W5      I Sh  vN   WR                  US	9I Sh  vN n UR                  UR                  5      I Sh  vN n ['        UR(                  [*        R,                  5      (       d   e[/        UR0                  UR2                  [5        UR(                  XPS
9UR                  S9$ ! , (       d  f       N= f! , (       d  f       N= f N N N! [         a    UR!                  5          Of = fGM,  ! ["         at  n	U R                     U R                  R%                  W5        U R                  5       nSSS5        O! , (       d  f       O= fU R                  W5      I Sh  vN    U	SeSn	A	ff = f7f)z
Send an HTTP request, and return an HTTP response.

This is the core implementation that is called into by `.request()` or `.stream()`.
 z;Request URL is missing an 'http://' or 'https://' protocol.)httphttpswswssz)Request URL has an unsupported protocol 'z://'.r,   poolNr+   )streampool_requestr}   )statusrp   content
extensions)rk   rl   decoder	   r   getrS   r   rR   append_assign_requests_to_connections_close_connectionsr.   handle_async_requestr   r   r(   BaseExceptionremove
isinstancer~   typingAsyncIterabler   r   rp   PoolByteStream)
r   r   rl   timeoutsr,   r   closingr   responseexcs
             r   r   (AsyncConnectionPool.handle_async_request   s/     ##**,R<%M  77%;F85I  %%)))R8,,vt,''+G4LNN!!,/ (
!	 // #BBDG 0 --g666 $0#C#CG#C#TT
%/%D%D$,,&  H  (//6+?+?@@@@??$$"\  **
 	
W (' 0/ 7 U  . 4
 !1134 0  	 ++ %%l3>>@	 ,++ ))'2224	 s   BI%'F.I%7G$ F*G$ 1F;2G$ F=	G$ G ,F?-G 1A(I%
F'#I%*
F84G$ =G$ ?G GG$ GG$ $
I".I:,H/&	I/
H=	9IIII""I%c                
   / n[        U R                  5       H  nUR                  5       (       a  U R                  R                  U5        M5  UR	                  5       (       a.  U R                  R                  U5        UR                  U5        Mx  UR                  5       (       d  M  [        U R                   Vs/ s H  o"R                  5       PM     sn5      U R                  :  d  M  U R                  R                  W5        UR                  U5        GM     U R                   Vs/ s H  o3R                  5       (       d  M  UPM     nnU GH  nUR                  R                  R                  nU R                   Vs/ s H4  nUR                  U5      (       d  M  UR                  5       (       d  M2  UPM6     nnU R                   Vs/ s H  o"R                  5       (       d  M  UPM     nnU(       a  US   nUR!                  U5        M  [        U R                  5      U R"                  :  a@  U R%                  U5      nU R                  R                  U5        UR!                  U5        GM#  U(       d  GM-  US   nU R                  R                  U5        UR                  U5        U R%                  U5      nU R                  R                  U5        UR!                  U5        GM     U$ s  snf s  snf s  snf s  snf )a  
Manage the state of the connection pool, assigning incoming
requests to connections as available.

Called whenever a new request is added or removed from the pool.

Any closing connections are returned, allowing the I/O for closing
those connections to be handled seperately.
r   )rt   rQ   	is_closedr   has_expiredr   is_idlelenrG   rR   r1   r   rk   rj   can_handle_requestis_availabler$   rF   rq   )	r   closing_connectionsr   r   queued_requestsr   rj   available_connectionsidle_connectionss	            r   r   3AsyncConnectionPool._assign_requests_to_connections  s    ! t001J##%%!!((4''))!!((4#**:6""$$@Q@QR@Q*++-@QRS112 !!((4#**:6 2$ 37..X.wDUDUDW7.X+L!))--44F #'"3"3%"3J008 =G=T=T=V "3 " % .2->-> ->zBTBTBV
->    %215
11*=T&&'$*?*??!33F;
!!((411*=!!-a0
!!((4#**:6!33F;
!!((411*=E ,H #"[ S Y%
 s0   :K1
)K6K6K;K;6K;L (L c                   #    [        5          U H  nUR                  5       I S h  vN   M     S S S 5        g  N! , (       d  f       g = f7fr   )r   aclose)r   r   r   s      r   r   &AsyncConnectionPool._close_connectionsU  s:     $&%
 ''))) & '&) '&s%   A:8:	A:
AAc                   #    U R                      [        U R                  5      n/ U l        S S S 5        U R                  W5      I S h  vN   g ! , (       d  f       N(= f N7fr   )rS   rt   rQ   r   )r   r   s     r   r   AsyncConnectionPool.aclose[  sS      ''"&t'8'8"9 "D ( %%&9::: (' 	;s'   A!AA!A	A!
AA!c                   #    U $ 7fr   r=   r'   s    r   
__aenter__AsyncConnectionPool.__aenter__c  s
     s   c                @   #    U R                  5       I S h  vN   g  N7fr   )r   )r   exc_type	exc_value	tracebacks       r   	__aexit__AsyncConnectionPool.__aexit__f  s      kkms   c                   U R                   R                  nU R                     U R                   Vs/ s H  o"R	                  5       PM     nnU R
                   Vs/ s H  oDR                  5       PM     nnUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      n	S S S 5        SW SW S3n
SW SW	 S3nSU S	U
 S
U S3$ s  snf s  snf ! , (       d  f       N6= f)NFTz
Requests: z	 active, z queuedzConnections: z idle<z [z | z]>)	__class__r8   rS   rR   r1   rQ   r   count)r   
class_namer   request_is_queuedr   connection_is_idlenum_active_requestsnum_queued_requestsnum_active_connectionsnum_idle_connectionsrequests_infoconnection_infos               r   __repr__AsyncConnectionPool.__repr__n  s   ^^,,
''DHNN SN!2!2!4N S7;7H7H"7H""$7H  " #4"9"9%"@"3"9"9$"?%7%=%=e%D"#5#;#;D#A  ( ,-Y7J6K7S 	 239=Q<RRWX 	 :,bs?2C2FF# !T" ('s)   C*C C*C%4AC* 
C**
C8)rQ   rJ   rK   rI   rM   rF   rG   rO   rS   rC   rR   rL   rP   rB   rN   )NN
   NNTFr   NNNN)rT   zssl.SSLContext | NonerU   zProxy | NonerV   
int | NonerW   r   rX   r6   rY   r7   rZ   r7   r[   intr\   
str | Noner]   r   r^   zAsyncNetworkBackend | Noner_   z%typing.Iterable[SOCKET_OPTION] | Noner3   r4   )rj   r
   r3   r   )r3   list[AsyncConnectionInterface])r   r   r3   r   )r   r   r3   r4   r5   )r3   r?   )NNN)r   ztype[BaseException] | Noner   zBaseException | Noner   ztypes.TracebackType | Noner3   r4   )r3   str)r8   r9   r:   r;   __doc__r   rq   propertyru   r   r   r   r   r   r   r   r<   r=   r!   r   r?   r?   +   s4    .2"&(04)-$(6:@DN7*N7 N7 $	N7
 $.N7 'N7 N7 N7 N7 "N7 N7 4N7 >N7 
N7`3
j ' '"E
NE#N*;
 04*.04	, ( .	
 
Gr!   r?   c                  B    \ rS rSr        SS jrSS jrS	S jrSrg)
r   i  c                6    Xl         X l        X0l        SU l        g )NF)_stream_pool_request_pool_closed)r   r~   r   r}   s       r   r   PoolByteStream.__init__  s     )
r!   c                  #     U R                     S h  vN nU7v   M   N
 g ! [         a!  nU R                  5       I S h  vN    US eS nAff = f7fr   )r   r   r   )r   partr   s      r   	__aiter__PoolByteStream.__aiter__  sJ     	 "ll d
l 	 ++-4	 sH   A$ " "$ "$ A
AA
AA

AAc                @  #    U R                   (       d  SU l         [        5          [        U R                  S5      (       a"  U R                  R	                  5       I S h  vN   S S S 5        U R
                  R                     U R
                  R                  R                  U R                  5        U R
                  R                  5       nS S S 5        U R
                  R                  W5      I S h  vN   g g  N! , (       d  f       N= f! , (       d  f       NF= f N*7f)NTr   )r   r   hasattrr   r   r   rS   rR   r   r   r   r   )r   r   s     r   r   PoolByteStream.aclose  s     ||DL(*4<<22,,--/// + 11

$$++D,>,>?**DDF 2 **//888  0 +* 21 9sS   #D9C:C8C:#DA
D&D1D2D8C::
DD
DD)r   r   r   r   N)r~   ztyping.AsyncIterable[bytes]r   r   r}   r?   r3   r4   )r3   ztyping.AsyncIterator[bytes]r5   )r8   r9   r:   r;   r   r   r   r<   r=   r!   r   r   r     s7    	+	 '	 "		
 
	 9r!   r   )
__future__r   sslrD   typesr   _backends.autor   _backends.baser   r   _exceptionsr   r	   _modelsr
   r   r   r   _synchronizationr   r   r   r   r   
interfacesr   r   r   r?   r   r=   r!   r   <module>r      sU    " 
 
   ( ? E 6 6 S S + G' '4WG/ WGt
9 9r!   