
    6=g;B                        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   )SyncBackend)SOCKET_OPTIONNetworkBackend)ConnectionNotAvailableUnsupportedProtocol)OriginProxyRequestResponse)EventShieldCancellation
ThreadLock   )HTTPConnection)ConnectionInterfaceRequestInterfacec                  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)PoolRequest   c                <    Xl         S U l        [        5       U l        g N)request
connectionr   _connection_acquired)selfr   s     @/usr/lib/python3/dist-packages/httpcore/_sync/connection_pool.py__init__PoolRequest.__init__   s    6:$)G!    c                D    Xl         U R                  R                  5         g r   )r   r   set)r   r   s     r   assign_to_connection PoolRequest.assign_to_connection   s    $!!%%'r!   c                0    S U l         [        5       U l        g r   )r   r   r   r   s    r   clear_connectionPoolRequest.clear_connection   s    $)G!r!   Nc                    U R                   c  U R                  R                  US9  U R                   c   eU R                   $ )Ntimeout)r   r   wait)r   r,   s     r   wait_for_connectionPoolRequest.wait_for_connection   s?     ??"%%**7*;***r!   c                    U R                   S L $ r   )r   r'   s    r   	is_queuedPoolRequest.is_queued'   s    $&&r!   )r   r   r   )r   r   returnNone)r   zConnectionInterface | 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    ,
(,
 '+#	'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)ConnectionPool+   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   ConnectionPool.__init__0   s    X (*2CKK 	
 )0 KK* 	'
 +.!!4#B#B+
' "2+	 -4KM/ 	  . 8:,.
 &0\"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   )Socks5Connection)proxy_origin
proxy_authremote_originrT   rX   rY   rZ   r^   s   http)ForwardHTTPConnection)rc   proxy_headersproxy_ssl_contextre   rX   r^   )TunnelHTTPConnection)	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 ConnectionPool.create_connection   s   ;;"{{%%)@@9'!%!7!7#{{//"( $ 1 1%)%;%;++++$($9$9	 	 ')=,!%!7!7"&++"5"5&*kk&=&="(%)%;%;$($9$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      $ )al  
Return a list of the connections currently in the pool.

For example:

```python
>>> pool.connections
[
    <HTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 6]>,
    <HTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 9]> ,
    <HTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>,
]
```
)listrQ   r'   s    r   connectionsConnectionPool.connections   s      D%%&&r!   c           
     x   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        WR                  US	9n UR                  UR                  5      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! [         a    UR!                  5          Of = fGM  ! ["         ak  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        U	SeSn	A	ff = 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_requestr   r   r(   BaseExceptionremove
isinstancer~   typingIterabler   r   rp   PoolByteStream)
r   r   rl   timeoutsr,   r   closingr   responseexcs
             r   r   ConnectionPool.handle_request   s    ##**,R<%M  77%;F85I  %%)))R8,,vt,''&w/LNN!!,/ (
!	 // #BBDG 0 ''0 *==g=N
)88$,, H  (//6??;;;;??$$"\  **
 	
W (' 0/ . 4
 !1134 0  	 ++ %%l3>>@	 ,++ ##G,4	 sr   'E?5G F(G <F! ?
F
FG !F>;G =F>>G 
H9H4,H	H4
H	H44H9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   .ConnectionPool._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         M     S S S 5        g ! , (       d  f       g = fr   )r   close)r   r   r   s      r   r   !ConnectionPool._close_connectionsU  s*    !%
  " & "!!s   .
<c                    U R                      [        U R                  5      n/ U l        S S S 5        U R                  W5        g ! , (       d  f       N = fr   )rS   rt   rQ   r   )r   r   s     r   r   ConnectionPool.close[  sE     ''"&t'8'8"9 "D ( 	 34 ('s   A
Ac                    U $ r   r=   r'   s    r   	__enter__ConnectionPool.__enter__c  s    r!   c                $    U R                  5         g r   )r   )r   exc_type	exc_value	tracebacks       r   __exit__ConnectionPool.__exit__f  s     	

r!   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__ConnectionPool.__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NetworkBackend | Noner_   z%typing.Iterable[SOCKET_OPTION] | Noner3   r4   )rj   r
   r3   r   )r3   list[ConnectionInterface])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)-$(15@DN2*N2 N2 $	N2
 $.N2 'N2 N2 N2 N2 "N2 N2 /N2 >N2 
N2`3
j ' '"E
NE#N#5
 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                    H  nUv   M	     g ! [         a  nU R                  5         US eS nAff = f7fr   )r   r   r   )r   partr   s      r   __iter__PoolByteStream.__iter__  s=     	 
 % 	 JJL4	 s   A A
>9>Ac                   U R                   (       d  SU l         [        5          [        U R                  S5      (       a  U R                  R	                  5         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        g g ! , (       d  f       N= f! , (       d  f       N<= f)NTr   )r   r   hasattrr   r   r   rS   rR   r   r   r   r   )r   r   s     r   r   PoolByteStream.close  s    ||DL#%4<<11LL&&( & 11

$$++D,>,>?**DDF 2 JJ))'2 %% 21s   6C&7A
C7&
C47
D)r   r   r   r   N)r~   ztyping.Iterable[bytes]r   r   r}   r?   r3   r4   )r3   ztyping.Iterator[bytes]r5   )r8   r9   r:   r;   r   r   r   r<   r=   r!   r   r   r     s7    	&	 "	 		
 
	 3r!   r   )
__future__r   sslrD   typesr   _backends.syncr   _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 D D & =' '4WG% WGt
3 3r!   