
    nbi                       d dl mZ d dlZd dlZd dl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d	lmZmZ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mZmZ ddl m!Z! ddl"m#Z#m$Z$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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8 ddlm9Z9m:Z: ddl;m<Z< ej=        r
d dl>Z>d dl?m@Z@ g dZA ejB        eC          ZD ejE        d          ZFe9e:dZG G d de          ZH G d  d!eH          ZId(d'ZJdS ))    )annotationsN)TracebackType)urljoin   )HTTPHeaderDict)DEFAULT_BLOCKSIZE)AsyncRequestMethods)
_TYPE_BODY_TYPE_BODY_POSITION_TYPE_TIMEOUTProxyConfig)HttpVersionQuicPreemptiveCacheTypeResponsePromise)port_by_scheme)ProtocolResolver)AsyncBaseResolverAsyncManyResolverAsyncResolverDescription)load_extension)LocationValueErrorMaxRetryErrorProxySchemeUnknownURLSchemeUnknown)SSL_KEYWORDSPoolKeykey_fn_by_scheme)AsyncTrafficPolice)connection_requires_http_tunnel)NOT_FORWARDABLE_HEADERS)Retry)UnavailableTraffic)Urlparse_extension	parse_url   )AsyncHTTPConnectionPoolAsyncHTTPSConnectionPool)AsyncHTTPResponse)Literal)AsyncPoolManagerAsyncProxyManagerproxy_from_url_SelfThttphttpsc                       e Zd ZU dZdZded<   dZded<   	 	 	 	 dOdP fdZdQdZdRdZ		 dSdTd'Z
dUd(Z	 	 	 dVdWd-ZdXd/ZdYd2Z	 dSdZd4Zd[d6Zd\d:Zdd;d]d?Zej        	 d^dAdBd_dH            Zej        	 d^d`dK            Z	 d^dadMZdbdNZ xZS )cr+   a  
    Allows for arbitrary async requests while transparently keeping track of
    necessary connection pools for you.

    :param num_pools:
        Number of connection pools to cache before discarding the least
        recently used pool.

    :param headers:
        Headers to include with all requests, unless other headers are given
        explicitly.

    :param \**connection_pool_kw:
        Additional parameters are used to create fresh
        :class:`urllib3._async.connectionpool.AsyncConnectionPool` instances.

    Example:

    .. code-block:: python

        import urllib3

        http = urllib3.AsyncPoolManager(num_pools=2)

        resp1 = await http.request("GET", "https://google.com/")
        resp2 = await http.request("GET", "https://google.com/mail")
        resp3 = await http.request("GET", "https://yahoo.com/")

        print(len(http.pools))
        # 2

    Nz
Url | NoneproxyzProxyConfig | Noneproxy_config
   	num_poolsintheaderstyping.Mapping[str, str] | Nonepreemptive_quic_cacheQuicPreemptiveCacheType | NoneresolverfAsyncResolverDescription | list[AsyncResolverDescription] | str | list[str] | AsyncBaseResolver | Noneconnection_pool_kw
typing.AnyreturnNonec                p   t                                          |           d|v rJ|d         }t          |t                    s-t          j        |          }|                                }||d<   || _        || _        d|vrdn|d         | _        t          |d          | _
        t          | _        t          j                    | _        || _        t          |t                     | _        |t!          t"          j                  g}nCt          |t&                    rt!          j        |          g}nt          |t                     r|g}g | _        t          |t                    sd}|D ]}t          |t&                    rO| j                            t!          j        |                     | j        d         j        t"          j        k    rd}f| j                            |           | j        d         j        t"          j        k    rd}|s,| j                            t!          j        d                     | j        D ];}	d|v rd|	vr|d         |	d<   d	|v rd	|	vr|d	         |	d	<   d
|v rd
|	vr|d
         |	d
<   <t          |t                    st1          d | j        D              n|| _        d S )NretriesblockFT)concurrencyz system://default?hosts=localhostca_cert_dataca_cert_dirca_certsc                6    g | ]}|                                 S  )new).0rs     q/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/urllib3_future/_async/poolmanager.py
<listcomp>z-AsyncPoolManager.__init__.<locals>.<listcomp>   s     AAAAAAA    )super__init__
isinstancer!   from_intcopyr>   
_num_poolsrD   r   poolspool_classes_by_schemer   _preemptive_quic_cacher   _own_resolverr   r   SYSTEMstrfrom_url
_resolversappendprotocolr   	_resolver)selfr6   r8   r:   r<   r>   rC   can_resolve_localhostresolver_descriptionrd	__class__s             rO   rS   zAsyncPoolManager.__init__]   s    	!!! ***(3Ggu-- 8.11%7%<%<%>%>"07"9-"4# $666EE<Nw<W 	
 CU4C
 C
 C

 '=# 0 5 7 7&;#!+H6G!H!HH01A1HIIJHH#&& 	"09(CCDHH":;; 	" zH:<($566 	*/!(0 1 1$2C88 O**09:NOO   r*37G7NNN04-&&';<<<?2&/3C3JJJ,0)( &&,5:    / 		D 		DB!333!++);N)KB~& 222 **(:=(IB}%///R''%7
%CBzN h(9::AAAAABB 	rQ   rc   r.   c                
   K   | S NrK   rc   s    rO   
__aenter__zAsyncPoolManager.__aenter__   s      rQ   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneLiteral[False]c                >   K   |                                   d {V  dS )NF)clear)rc   rl   rn   rp   s       rO   	__aexit__zAsyncPoolManager.__aexit__   s-       jjllurQ   schemer]   hostportrequest_contextdict[str, typing.Any] | Noner'   c                   | j         |         }|| j                                        }|                    d          
t          |d<   dD ]}|                    |d           |dk    r t          D ]}|                    |d           | j        |d<   | j        	                                s| j        
                                | _        | j        |d<   d|vr
| j        |d<    |||fi |S )a  
        Create a new :class:`urllib3._async.connectionpool.AsyncConnectionPool` based on host, port, scheme, and
        any additional pool keyword arguments.

        If ``request_context`` is provided, it is provided as keyword arguments
        to the pool class used. This method is used to actually create the
        connection pools handed out by :meth:`connection_from_url` and
        companion methods. It is intended to be overridden for customization.
        N	blocksize)rv   rw   rx   r0   r:   r<   maxsize)rY   r>   rV   getr   popr   rZ   rb   is_availablerecyclerW   )rc   rv   rw   rx   ry   pool_clskeykws           rO   	_new_poolzAsyncPoolManager._new_pool   s      372Mf2U""5::<<O {++3+<OK( . 	+ 	+CT****V" . .##B----373N/0~**,, 	6!^3355DN&*n
# O++)-OI&xd66o666rQ   c                   K   | j                                          d{V  | j        r:| j                                        r#| j                                         d{V  dS dS dS )z
        Empty our store of pools and direct them all to close.

        This will not affect in-flight connections, but they will not be
        re-used after completion.
        N)rX   rt   r[   rb   r   closerj   s    rO   rt   zAsyncPoolManager.clear  s       j          	)$."="="?"? 	).&&(((((((((((	) 	) 	) 	)rQ   r0   
str | None
int | Nonepool_kwargsc                  K   |st          d          |                     |          }|pd|d<   |s,t          j        |d                                                   }||d<   ||d<   |                     |           d{V S )a  
        Get a :class:`urllib3._async.connectionpool.AsyncConnectionPool` based on the host, port, and scheme.

        If ``port`` isn't given, it will be derived from the ``scheme`` using
        ``urllib3.connectionpool.port_by_scheme``. If ``pool_kwargs`` is
        provided, it is merged with the instance's ``connection_pool_kw``
        variable and used to create the new connection pool, if one is
        needed.
        zNo host specified.r0   rv   rx   rw   N)r   _merge_pool_kwargsr   r~   lowerconnection_from_context)rc   rw   rx   rv   r   ry   s         rO   connection_from_hostz%AsyncPoolManager.connection_from_host  s      "  	;$%9:::11+>>$*$4f! 	I!%oh&?&E&E&G&GHHD"&"&11/BBBBBBBBBrQ   dict[str, typing.Any]c                  K   d|v r|                     d           |d                                         }| j                            |          }|Gt	          |          \  }}	 t          ||          }|                    |          }| j                            |          }||d<   |                                }d|v r|d         nt                      }t          |                                          dk    rt          j        |vr|                    t          j                   t          j        |vr|                    t          j                   t          j        |vr|                    t          j                   ||d<   n# t          $ r Y nw xY w|st!          |           ||          }	| j        
| j        |d<   |                     |	|           d{V S )a  
        Get a :class:`urllib3._async.connectionpool.AsyncConnectionPool` based on the request context.

        ``request_context`` must at least contain the ``scheme`` key and its
        value must be a key in ``key_fn_by_scheme`` instance variable.
        strictrv   Ndisabled_svn   r:   ry   )r   r   r   r~   r$   r   scheme_to_http_schemesupported_svnsetlenr   h11addh2h3ImportErrorr   rZ   connection_from_pool_key)
rc   ry   rv   pool_key_constructortarget_schemetarget_implementation	extensionr   r   pool_keys
             rO   r   z(AsyncPoolManager.connection_from_context-  s'      &&))) *0022#488@@'3B63J3J0M0?*=:OPP	 #88GG'+'<'@'@'H'H$,2) ) 7 7 9 9 &88 $N33  y..0011Q66"m;;$((999"~]::$((888"~]::$((8882>//7    : $ 	+"6***''88&27;7RO3422o 3 
 
 
 
 
 
 
 
 	
s   &F
 

FFr   r   c                  K   | j         j        r| j                                          | j                             || j                  4 d{V 	 }t          |d          sC|d         }|d         }|d         }|                     ||||          } ||           d{V  n|}	 ddd          d{V  n# 1 d{V swxY w Y   |j        J | j         |j        _        |S )a  
        Get a :class:`urllib3._async.connectionpool.AsyncConnectionPool` based on the provided pool key.

        ``pool_key`` should be a namedtuple that only contains immutable
        objects. At a minimum it must have the ``scheme``, ``host``, and
        ``port`` fields.
        )rD   Nis_idlerv   rw   rx   r   )	rX   busyreleaselocate_or_holdrD   hasattrr   poolparent)rc   r   ry   swapper_or_poolrv   rw   rx   r   s           rO   r   z)AsyncPoolManager.connection_from_pool_keyh  s      :? 	!J   :,,DJ - 
 
 	' 	' 	' 	' 	' 	' 	' 	'?I66 '(2&v.&v.~~D$ &   &od++++++++++&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'  y$$$:	s   AB99
CCurlc                   K   t          |          }|                     |j        |j        |j        |           d{V S )a  
        Similar to :func:`urllib3.async_connection_from_url`.

        If ``pool_kwargs`` is not provided and a new pool needs to be
        constructed, ``self.connection_pool_kw`` is used to initialize
        the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs``
        is provided, it is used instead. Note that if a new pool does not
        need to be created for the request, the provided ``pool_kwargs`` are
        not used.
        rx   rv   r   N)r%   r   rw   rx   rv   )rc   r   r   us       rO   connection_from_urlz$AsyncPoolManager.connection_from_url  s]       cNN..Fk / 
 
 
 
 
 
 
 
 	
rQ   overridec                    | j                                         }rQ|                    d                                 D                        fd|                                D             S |S )a  
        Merge a dictionary of override values for self.connection_pool_kw.

        This does not modify self.connection_pool_kw and returns a new dict.
        Any keys in the override dictionary with a value of ``None`` are
        removed from the merged dictionary.
        c                    i | ]
\  }}|||S ri   rK   )rM   kvs      rO   
<dictcomp>z7AsyncPoolManager._merge_pool_kwargs.<locals>.<dictcomp>  s    DDD$!QamAmmmrQ   c                4    i | ]\  }}|vs|         ||S ri   rK   )rM   r   r   r   s      rO   r   z7AsyncPoolManager._merge_pool_kwargs.<locals>.<dictcomp>  s=       AqH$$(? 1(?(?(?rQ   )r>   rV   updateitems)rc   r   base_pool_kwargss    ` rO   r   z#AsyncPoolManager._merge_pool_kwargs  s      27799 	##DD(.."2"2DDD     ,2244   
  rQ   
parsed_urlr#   boolc                V    | j         dS t          | j         | j        |j                   S )z
        Indicates if the proxy requires the complete destination URL in the
        request.  Normally this is only needed when not using an HTTP CONNECT
        tunnel.
        NF)r3   r   r4   rv   )rc   r   s     rO   !_proxy_requires_url_absolute_formz2AsyncPoolManager._proxy_requires_url_absolute_form  s7     :52J):+<
 
 
 	
rQ   promiser   ResponsePromise | NoneAsyncHTTPResponse | Nonec               "  K   |5t          |t                    s t          dt          |           d          	 | j                            |pt          dd          4 d{V 	 }|                    |           d{V }ddd          d{V  n# 1 d{V swxY w Y   n# t          $ r Y dS w xY w||t          d          |dS d}|r|}n4|j	        r-t          |j	        d	          r|j	        j        r|j	        j        }|t          d
          | j                            |           t          j        t          |                    d                    }t          j        t"          |                    d                    }|r|                                rt          j        t          |                    d                    }t          j        t          j        t(          df         |                    d                    }t          j        t          j        t*          df         |                    d                    }	t          j        t"          |                    d                    }
t          j        t"          |                    d                    }t          j        t          j        t,          df         |                    d                    }t          j        t"          |                    d                    }|                    d          }t          j        t          j        t          t          j        f         |                    d                    }t          j        t"          |                    d                    }t          j        t2          |                    d                    }t          j        t4          |                    d                    }|                                }t          |t                    sJ |j        dk    r2d}d}t+          |	          }	t8          D ]}|	                    |           	 |                    ||||j                  }n4# t@          $ r' |j!        r|"                                 d{V   |cY S w xY w|"                                 d{V  |#                    |           d{V  tH          %                    d||            | j&        |tO          ||          df||	||||d|||
|dd| d{V }|                     |r|nd           d{V S t#          |j(        )                    d                    }t          j        t4          |                    d                    }|*                    ||j        |          rIt          j        t          |                    d                    }t          j        t          j        t(          df         |                    d                    }t          j        t          j        t*          df         |                    d                    }	t          j        t"          |                    d                    }
t          j        t"          |                    d                    }t          j        t          j        t,          df         |                    d                    }t          j        t"          |                    d                    }|                    d          }t          j        t          j        t          t          j        f         |                    d                    }t          j        t"          |                    d                    }t          j        t2          |                    d                    }|                                }t          |t                    sJ 	 |                    ||||j                  }n4# t@          $ r' |j+        r|"                                 d{V   |cY S w xY w|"                                 d{V  |,                    |           d{V  tH          %                    d|            | j&        |tO          ||          df||	||||d|||
|dd| d{V }|                     |r|nd           d{V S |                    d           }|c|j-        \|j        d!k    sd"|j        cxk    rd#k     r?n n<|d$k    s|4| t]          d                      }|/                    |           d{V  |S )%z
        Retrieve the first response available in the pools.
        This method should be called after issuing at least one request with ``multiplexed=True``.
        If none available, return None.
        Nz7get_response only support ResponsePromise but received z] instead. This may occur if you expected the remote peer to support multiplexing but did not.FT)rD   not_idle_onlyr   zPInvoked get_response with promise=... that no connections across pools recognizefrom_promisezPInternal: Unable to identify originating ResponsePromise from a LowLevelResponsemethodpm_redirectpm_urlbodyr8   preload_contentdecode_contenttimeoutassert_same_hostpool_timeoutresponse_kwchunkedbody_posrC   /  GETresponse_poolRedirecting %s -> %s)r   r8   rC   r   r   r   release_connr   r   r   r   multiplexedzRetry-Afterz	Retry: %sr   e      i,  CONNECT)0rT   r   	TypeErrortyperX   borrowget_responser"   
ValueError_fpr   r   forgettypingcastr]   get_parameterr   get_redirect_locationUnionr
   r   r   MutableMappingAnyr   r!   statusr    discard	incrementr   r   raise_on_redirect
drain_connasync_sleep_for_retrylogdebugurlopenr   r8   r~   is_retryraise_on_statusasync_sleepr   r   start_extension)rc   r   r   r   r   r   redirectr   r   r8   r   r   r   r   r   r   r   r   rC   redirect_locationshould_be_removed_headernew_promisehas_retry_afterr   s                           rO   r   zAsyncPoolManager.get_response  s      z'?'K'Kg$w-- g g g  
	z((*?%t )   D D D D D D D D!%!2!27!2!C!CCCCCCCD D D D D D D D D D D D D D D D D D D D D D D D D D D " 	 	 	44	 8#3b   4 	9"LL 9HL.999 L-9
  (|8b   	
,''' S,"<"<X"F"FGG;t\%?%?%N%NOO  L	U6688 L	U+c<#=#=h#G#GHHC;Z-.0J0J60R0R D k^T12**955 G %kl001BCC O $[l001ABB N k]D01<3M3Mi3X3X G  &{l001CDD    (55nEEL +%c6:o6**=99 K k$(B(B9(M(MNNG{#\%?%?
%K%K H k%)C)CI)N)NOOG ( > > @ @/55555#%%(110G > >,OO$<==== !++C((. ,   !      , "--/////////	  %%'''''''''//999999999II,c3DEEE ,.//! !1)!! /- ! !  !! !      K& **'3S;;t*TTTTTTTTT x/33MBBCC+e\%?%?	%J%JKKFHO_EE A	U+c<#=#=h#G#GHHC;Z-.0J0J60R0R D k^T12**955 G %kl001BCC O $[l001ABB N k]D01<3M3Mi3X3X G  &{l001CDD    (55nEEL +%c6:o6**=99 K k$(B(B9(M(MNNG{#\%?%?
%K%K H !) > > @ @/55555 !++C((. ,   !      * "--/////////	  %%'''''''''%%h/////////IIk3''' ,.//! !1)"! /- ! !  !! !      K& **'3S;;t*TTTTTTTTT ..{;;	 X%7%?#%%x,,,,,,,,,y((I,A$ 4t 4 4 6 6I..y999999999sY   *B' &BB' 
BB' "B#B' '
B54B5&R .R65R6!a   .a10a1T.r   r   r   r   r   r)   c               
   K   d S ri   rK   rc   r   r   r   r   r   s         rO   r   zAsyncPoolManager.urlopen          CrQ   Literal[True]r   c               
   K   d S ri   rK   r  s         rO   r   zAsyncPoolManager.urlopen         #rQ   #AsyncHTTPResponse | ResponsePromisec                Z	  K   t          |          }|j        t          j        dt          d           d}d|v r|d         |d         }t                      }i }t          |                                          dk    rt          j	        |                                vr|
                    t          j	                   t          j        |                                vr|
                    t          j                   t          j        |                                vr|
                    t          j                   ||d<   |                     |j        |j        |j        |           d{V }	|j        c|j                                        d	vrHt#          t%          |j                   } |            |d<   |                    |d         j                   d
|d<   d
|d<   d|vr
| j        |d<   |                     |          r |	j        ||fi | d{V }
n |	j        ||j        fi | d{V }
| j                                         d|v rg|d         r_t7          |
t8                    rE|
                    d|           |
                    d|           t7          |
t8                    sJ |
S d
|d<   t7          |
t<                    sJ |o|
                                }|s|
S tA          ||          }|
j!        dk    rDd}d|d<   tE          |d                   |d<   tF          D ]}|d         $                    |           |%                    d|
j&                  }t7          |tN                    stO          j(        ||          }|j)        rp|	*                    |          s[|d         +                                }|d         D ]3}|                                |j)        v r|,                    |d           4||d<   	 |-                    |||
|	          }n4# t\          $ r' |j/        r|
0                                 d{V   |
cY S w xY w||d<   ||d<   tb          2                    d||           |
0                                 d{V   | j        ||fi | d{V S )a_  
        Same as :meth:`urllib3.AsyncHTTPConnectionPool.urlopen`
        with custom cross-host redirect logic and only sends the request-uri
        portion of the ``url``.

        The given ``url`` parameter must be absolute, such that an appropriate
        :class:`urllib3._async.connectionpool.AsyncConnectionPool` can be chosen for it.
        Na	  URLs without a scheme (ie 'https://') are deprecated and will raise an error in a future version of urllib3. To avoid this DeprecationWarning ensure all URLs start with 'https://' or 'http://'. Read more in this issue: https://github.com/urllib3/urllib3/issues/2920r   )category
stacklevelr   r   r   r   r/   Fr   r   r8   r   r   r   r   r   r   rC   )r   r   r   )3r%   rv   warningswarnDeprecationWarningr   r   r   r   r   r   r   r   r   rw   rx   r   r   r$   r   urlopen_kwargsr8   r   r   request_urirX   r   rT   r   set_parameterr)   r   r   r   r   r    r   r~   rC   r!   rU   remove_headers_on_redirectis_same_hostrV   r   r   r   r   r   r   info)rc   r   r   r   r   r   r   r   r   connr   r   r   rC   new_headersheaders                   rO   r   zAsyncPoolManager.urlopen  sc      cNN8MA ,    "K!<;I55LK9**,,--22?)*A*A*C*CCC $$[_555>)@)@)B)BBB $$[^444>)@)@)B)BBB $$[^444*6K'..Fk / 
 
 
 
 
 
 
 
 8AHNN$4$4<M$M$M&(A(ABI'ikkB{OIIbo4555!&:B LByM11!44 	G)T\&#<<<<<<<<<<HH)T\&!-FF2FFFFFFFFH
B2m#4(O44  &&}h???&&x555!(O<<<<< !&B}($566666$I)G)G)I)I  	O $C):;; ?c!!FBvJ*2i=99ByM,C @ @(9%%&>????&&H$455'5)) 	AnWx@@@G
 - 	(d6G6G7
 7
 	( Y-,,..KY- 2 2<<>>W%GGGOOFD111'ByM	''hd'SSGG 	 	 	( ))+++++++++OOO		  9!:'.?@@@!!#########!T\&*;BBrBBBBBBBBBs   
P$ $.QQc                    d                     d | j        j                                        D                       }|r|dz  }d| | j         dS )N; c              3  4   K   | ]}t          |          V  d S ri   reprrM   ps     rO   	<genexpr>z,AsyncPoolManager.__repr__.<locals>.<genexpr>-  (      NN1tAwwNNNNNNrQ    z<AsyncPoolManager >)joinrX   	_registryvaluesrc   
inner_reprs     rO   __repr__zAsyncPoolManager.__repr__,  s]    YYNN
0D0K0K0M0MNNNNN
 	#J=J=
====rQ   )r5   NNN)r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   )rc   r.   r@   r.   )rl   rm   rn   ro   rp   rq   r@   rr   ri   )
rv   r]   rw   r]   rx   r7   ry   rz   r@   r'   )r@   rA   Nr0   N
rw   r   rx   r   rv   r   r   rz   r@   r'   )ry   r   r@   r'   )r   r   ry   r   r@   r'   )r   r]   r   rz   r@   r'   )r   rz   r@   r   )r   r#   r@   r   )r   r   r@   r   Tr   r]   r   r]   r   r   r   rr   r   r?   r@   r)   r   r]   r   r]   r   r   r   r  r   r?   r@   r   
r   r]   r   r]   r   r   r   r?   r@   r  r@   r]   )__name__
__module____qualname____doc__r3   __annotations__r4   rS   rk   ru   r   rt   r   r   r   r   r   r   r   r   overloadr   r&  __classcell__rg   s   @rO   r+   r+   8   sO         B E'+L++++ 37@D g
 g
 g
 g
 g
 g
 g
R       9=/7 /7 /7 /7 /7b
) 
) 
) 
)  #48C C C C C:9
 9
 9
 9
v" " " "J EI
 
 
 
 
$       ,
 
 
 
 48V V V V V Vp _
 	  '*          _  _
 	    _ 7;{C {C {C {C {Cz> > > > > > > >rQ   r+   c                       e Zd ZdZ	 	 	 	 	 	 	 d5d6 fdZ	 	 	 d7d8 fd!Z	 d9d:d$Zej        	 d;d&d'd<d.            Z	ej        	 d;d=d1            Z		 d;d> fd3Z	d?d4Z
 xZS )@r,   a[  
    Behaves just like :class:`PoolManager`, but sends all requests through
    the defined proxy, using the CONNECT method for HTTPS URLs.

    :param proxy_url:
        The URL of the proxy to be used.

    :param proxy_headers:
        A dictionary containing headers that will be sent to the proxy. In case
        of HTTP they are being sent with each request, while in the
        HTTPS/CONNECT case they are sent only once. Could be used for proxy
        authentication.

    :param proxy_ssl_context:
        The proxy SSL context is used to establish the TLS connection to the
        proxy when using HTTPS proxies.

    :param use_forwarding_for_https:
        (Defaults to False) If set to True will forward requests to the HTTPS
        proxy to be made on behalf of the client instead of creating a TLS
        tunnel via the CONNECT method. **Enabling this flag means that request
        and response headers and content will be visible from the HTTPS proxy**
        whereas tunneling keeps request and response headers and content
        private.  IP address, target hostname, SNI, and port are always visible
        to an HTTPS proxy even when this flag is disabled.

    :param proxy_assert_hostname:
        The hostname of the certificate to verify against.

    :param proxy_assert_fingerprint:
        The fingerprint of the certificate to verify against.

    Example:

    .. code-block:: python

        import urllib3

        proxy = urllib3.AsyncProxyManager("https://localhost:3128/")

        resp1 = await proxy.request("GET", "https://google.com/")
        resp2 = await proxy.request("GET", "https://httpbin.org/")

        print(len(proxy.pools))
        # 1

        resp3 = await proxy.request("GET", "https://httpbin.org/")
        resp4 = await proxy.request("GET", "https://twitter.com/")

        print(len(proxy.pools))
        # 3

    r5   NF	proxy_urlr]   r6   r7   r8   r9   proxy_headersproxy_ssl_contextssl.SSLContext | Noneuse_forwarding_for_httpsr   proxy_assert_hostnameNone | str | Literal[False]proxy_assert_fingerprintr   r>   r?   r@   rA   c	                   t          |t                    r|j         d|j         d|j         }
n|}
t          |
          }|j        dvrt          |j                  |j        s0t          j        |j        d          }|	                    |          }|| _
        |pi | _        || _        t          ||||          | _        | j
        |	d<   | j        |	d<   | j        |	d<    t                      j        ||fi |	 d S )	Nz://:r/   P   )rx   _proxy_proxy_headers_proxy_config)rT   r'   rv   rw   rx   r%   r   r   r~   _replacer3   r8  r9  r   r4   rR   rS   )rc   r7  r6   r8   r8  r9  r;  r<  r>  r>   str_proxy_urlr3   rx   rg   s                rO   rS   zAsyncProxyManager.__init__l  s+    i!899 	&(/UUINUUY^UUMM%M-((<000$U\222z 	.!%elB77DNNN--E
*0b!2'$!$	
 
 (,z8$/3/A+,.2.??+GBB/ABBBBBrQ   r0   rw   rx   r   rv   r   rz   r'   c                  K   |dk    r+t                                          ||||           d {V S | j        J t                                          | j        j        | j        j        | j        j        |           d {V S )Nr1   )r   )rR   r   r3   rw   rx   rv   )rc   rw   rx   rv   r   rg   s        rO   r   z&AsyncProxyManager.connection_from_host  s       W55dF 6          z%%%WW11JOJOJ#	 2 
 
 
 
 
 
 
 
 	
rQ   r   typing.Mapping[str, str]c                r    ddi}t          |          j        }|r||d<   |r|                    |           |S )z
        Sets headers needed by proxies: specifically, the Accept and Host
        headers. Only sets headers not provided by the user.
        Acceptz*/*Host)r%   netlocr   )rc   r   r8   headers_rL  s        rO   _set_proxy_headersz$AsyncProxyManager._set_proxy_headers  sM     e$3& 	&%HV 	%OOG$$$rQ   T.r   r   r   r   rr   r   r)   c               
   K   d S ri   rK   r  s         rO   r   zAsyncProxyManager.urlopen  r  rQ   r  r   c               
   K   d S ri   rK   r  s         rO   r   zAsyncProxyManager.urlopen  r  rQ   r  c                  K   t          |          }t          | j        | j        |j                  s4|                    d| j                  }|                     ||          |d<    t                      j	        ||fd|i| d{V S )z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.r8   r   N)
r%   r   r3   r4   rv   r~   r8   rN  rR   r   )rc   r   r   r   r   r   r8   rg   s          rO   r   zAsyncProxyManager.urlopen  s       cNN.tz4;LahWW 	B ffY55G 33CAAByM$UWW_VSJJ8JrJJJJJJJJJrQ   c                    d                     d | j        j                                        D                       }|r|dz  }d| j         d| | j         dS )Nr  c              3  4   K   | ]}t          |          V  d S ri   r  r  s     rO   r  z-AsyncProxyManager.__repr__.<locals>.<genexpr>  r  rQ   r  z<AsyncProxyManager r   )r!  rX   r"  r#  r3   r$  s     rO   r&  zAsyncProxyManager.__repr__  sg    YYNN
0D0K0K0M0MNNNNN
 	#JKTZKK*KdjKKKKrQ   )r5   NNNFNN)r7  r]   r6   r7   r8   r9   r8  r9   r9  r:  r;  r   r<  r=  r>  r   r>   r?   r@   rA   r'  r(  ri   )r   r]   r8   r9   r@   rH  r)  r*  r+  r,  r-  )r.  r/  r0  r1  rS   r   rN  r   r3  r   r&  r4  r5  s   @rO   r,   r,   5  sl       4 4r 379=37).=A/3'C 'C 'C 'C 'C 'C 'CX  #48
 
 
 
 
 
 
, DH    " _
 	  '*          _  _
 	    _ 	K K K K K K K$L L L L L L L LrQ   r,   r   r]   r   r?   r@   c                    t          dd| i|S )Nr7  rK   )r,   )r   r   s     rO   r-   r-     s    11s1b111rQ   )r   r]   r   r?   r@   r,   )K
__future__r   loggingr   r
  typesr   urllib.parser   _collectionsr   	_constantr   _request_methodsr	   _typingr
   r   r   r   backendr   r   r   connectionpoolr   contrib.resolverr   contrib.resolver._asyncr   r   r   contrib.webextensions._asyncr   
exceptionsr   r   r   r   poolmanagerr   r   r   util._async.traffic_policer   
util.proxyr   util.requestr    
util.retryr!   util.traffic_policer"   util.urlr#   r$   r%   r'   r(   r   r)   TYPE_CHECKINGssltyping_extensionsr*   __all__	getLoggerr.  r   TypeVarr.   rY   r+   r,   r-   rK   rQ   rO   <module>rp     s0   " " " " " "                      ) ) ) ) ) ) ) ) ) ) ) ) 2 2 2 2 2 2 Q Q Q Q Q Q Q Q Q Q Q Q K K K K K K K K K K + + + + + + / / / / / /         
 : 9 9 9 9 9            B A A A A A A A A A ; ; ; ; ; ; 8 8 8 8 8 8 2 2 2 2 2 2       4 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 M M M M M M M M ' ' ' ' ' '	 *JJJ))))))
E
E
E g!!		!	! $%  z> z> z> z> z>* z> z> z>ztL tL tL tL tL( tL tL tLn2 2 2 2 2 2rQ   