HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/urllib3/__pycache__/poolmanager.cpython-310.pyc
o

;jW]�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZdd	lmZmZmZdd
lmZmZmZmZddlmZddlmZdd
lmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ej'rddl(Z(ddl)m*Z*gd�Z+e�,e-�Z.dZ/dZ0Gdd�dej1�Z2d)dd�Z3e�4e3e2�e�4e3e2�d�Z5eed�Z6Gdd �d e�Z7Gd!d"�d"e7�Z8d*d'd(�Z9dS)+�)�annotationsN)�
TracebackType)�urljoin�)�HTTPHeaderDict�RecentlyUsedContainer)�RequestMethods)�ProxyConfig)�HTTPConnectionPool�HTTPSConnectionPool�port_by_scheme)�LocationValueError�
MaxRetryError�ProxySchemeUnknown�URLSchemeUnknown)�BaseHTTPResponse)�_TYPE_SOCKET_OPTIONS)�connection_requires_http_tunnel)�Retry)�Timeout)�Url�	parse_url)�Self)�PoolManager�ProxyManager�proxy_from_url)�key_file�	cert_file�	cert_reqs�ca_certsZca_cert_data�ssl_versionZssl_minimum_versionZssl_maximum_versionZca_cert_dirZssl_contextZkey_password�server_hostnamei@c@s�eZdZUdZded<ded<ded<ded<d	ed
<ded<d
ed<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<d ed!<d"ed#<d ed$<d%ed&<d'ed(<d ed)<d*ed+<ded,<ded-<ded.<d/S)0�PoolKeyz�
    All known keyword arguments that could be provided to the pool manager, its
    pools, or the underlying connections.

    All custom key schemes should include the fields in this key at a minimum.
    �strZ
key_schemeZkey_host�
int | NoneZkey_portzTimeout | float | int | NoneZkey_timeoutzRetry | bool | int | NoneZkey_retrieszbool | NoneZ	key_blockztuple[str, int] | NoneZkey_source_address�
str | NoneZkey_key_fileZkey_key_passwordZ
key_cert_fileZ
key_cert_reqsZkey_ca_certszstr | bytes | NoneZkey_ca_cert_datazint | str | NoneZkey_ssl_versionzssl.TLSVersion | NoneZkey_ssl_minimum_versionZkey_ssl_maximum_versionZkey_ca_cert_dir�ssl.SSLContext | NoneZkey_ssl_contextZkey_maxsizez!frozenset[tuple[str, str]] | NoneZkey_headers�
Url | NoneZ
key__proxyZkey__proxy_headers�ProxyConfig | NoneZkey__proxy_configz_TYPE_SOCKET_OPTIONS | NoneZkey_socket_optionsZkey__socks_optionszbool | str | NoneZkey_assert_hostnameZkey_assert_fingerprintZkey_server_hostname�
key_blocksizeN)�__name__�
__module__�__qualname__�__doc__�__annotations__�r/r/�G/opt/saltstack/salt/lib/python3.10/site-packages/urllib3/poolmanager.pyr"8s>
r"�	key_class�
type[PoolKey]�request_context�dict[str, typing.Any]�returncCs�|��}|d��|d<|d��|d<dD]}||vr,||dur,t||���||<q|�d�}|dur<t|�|d<t|���D]}|�|�|d|<qB|j	D]
}||vr[d||<qQ|�d�durgt
|d<|di|��S)	a�
    Create a pool key out of a request context dictionary.

    According to RFC 3986, both the scheme and host are case-insensitive.
    Therefore, this function normalizes both before constructing the pool
    key for an HTTPS request. If you wish to change this behaviour, provide
    alternate callables to ``key_fn_by_scheme``.

    :param key_class:
        The class to use when constructing the key. This should be a namedtuple
        with the ``scheme`` and ``host`` keys at a minimum.
    :type  key_class: namedtuple
    :param request_context:
        A dictionary-like object that contain the context for a request.
    :type  request_context: dict

    :return: A namedtuple that can be used as a connection pool key.
    :rtype:  PoolKey
    �scheme�host)�headers�_proxy_headersZ_socks_optionsNZsocket_optionsZkey_r)r/)�copy�lower�	frozenset�items�get�tuple�list�keys�pop�_fields�_DEFAULT_BLOCKSIZE)r1r3�context�keyZsocket_opts�fieldr/r/r0�_default_key_normalizer_s&�

�rH��http�httpscs�eZdZUdZdZded<dZded<		dHdI�fdd�
ZdJdd�ZdKdd�Z		dLdMd%d&�Z
dNd'd(�Z		)	dOdPd-d.�ZdQd0d1�Z
dRd4d5�Z	dLdSd7d8�ZdTd:d;�ZdUd?d@�Z	AdVdWdFdG�Z�ZS)XraV
    Allows for arbitrary 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.connectionpool.ConnectionPool` instances.

    Example:

    .. code-block:: python

        import urllib3

        http = urllib3.PoolManager(num_pools=2)

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

        print(len(http.pools))
        # 2

    Nr'�proxyr(�proxy_config�
�	num_pools�intr8�typing.Mapping[str, str] | None�connection_pool_kw�
typing.Anyr5�Nonecsht��|�d|vr |d}t|t�s t�|�}|��}||d<||_|t|�|_t	|_	t
��|_
dS)N�retries)�super�__init__�
isinstancer�from_intr:rRr�pools�pool_classes_by_scheme�key_fn_by_scheme)�selfrOr8rRrU��	__class__r/r0rW�s	


zPoolManager.__init__rcCs|S�Nr/�r]r/r/r0�	__enter__�szPoolManager.__enter__�exc_type�type[BaseException] | None�exc_val�BaseException | None�exc_tb�TracebackType | None�typing.Literal[False]cCs|��dS)NF)�clear)r]rcrergr/r/r0�__exit__�szPoolManager.__exit__r6r#r7�portr3�dict[str, typing.Any] | Noner
cCsx|j|}|dur|j��}|�d�durt|d<dD]}|�|d�q|dkr3tD]}|�|d�q*|||fi|��S)a�
        Create a new :class:`urllib3.connectionpool.ConnectionPool` 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)r6r7rlrJ)r[rRr:r>rDrB�SSL_KEYWORDS)r]r6r7rlr3Zpool_clsrF�kwr/r/r0�	_new_pool�s

zPoolManager._new_poolcCs|j��dS)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)rZrjrar/r/r0rjszPoolManager.clearrJr%r$�pool_kwargscCsT|std��|�|�}|pd|d<|st�|d��d�}||d<||d<|�|�S)a�
        Get a :class:`urllib3.connectionpool.ConnectionPool` 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.
        zNo host specified.rJr6�Prlr7)r
�_merge_pool_kwargsrr>r;�connection_from_context)r]r7rlr6rrr3r/r/r0�connection_from_host"s

z PoolManager.connection_from_hostr4cCsXd|vrt�dt�|�d�|d��}|j�|�}|s!t|��||�}|j||d�S)z�
        Get a :class:`urllib3.connectionpool.ConnectionPool` 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.
        �strictzbThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v3.0.r6�r3)	�warnings�warn�
FutureWarningrBr;r\r>r�connection_from_pool_key)r]r3r6Zpool_key_constructor�pool_keyr/r/r0ru?s	�
z#PoolManager.connection_from_contextr}r"cCs�|jj�4|j�|�}|r|Wd�S|d}|d}|d}|j||||d�}||j|<Wd�|S1s;wY|S)a
        Get a :class:`urllib3.connectionpool.ConnectionPool` 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.
        Nr6r7rlrx)rZ�lockr>rq)r]r}r3�poolr6r7rlr/r/r0r|Xs

�
��z$PoolManager.connection_from_pool_key�urlcCs t|�}|j|j|j|j|d�S)a�
        Similar to :func:`urllib3.connectionpool.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.
        )rlr6rr)rrvr7rlr6)r]r�rr�ur/r/r0�connection_from_urlrs
�zPoolManager.connection_from_url�overridec	CsR|j��}|r'|��D]\}}|dur"z||=Wqty!Yqw|||<q|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.
        N)rRr:r=�KeyError)r]r�Zbase_pool_kwargsrF�valuer/r/r0rt�s


�
zPoolManager._merge_pool_kwargs�
parsed_urlr�boolcCs"|jdurdSt|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)rLrrMr6)r]r�r/r/r0�!_proxy_requires_url_absolute_form�s

�z-PoolManager._proxy_requires_url_absolute_formT�method�redirectrprcKs�t|�}|jdurtjdtdd�|j|j|j|jd�}d|d<d|d<d	|vr-|j|d	<|�	|�r=|j
||fi|��}n|j
||jfi|��}|oM|��}|sR|St
||�}|jd
krld}d|d<t|d	���|d	<|�d
|j�}	t|	t�stj|	|d�}	|	jr�|�|�s�|d	��}
|d	D]}|��|	jvr�|
�|d�q�|
|d	<z|	j||||d�}	Wnty�|	jr�|���|YSw|	|d
<||d<t� d||�|��|j
||fi|��S)aN
        Same as :meth:`urllib3.HTTPConnectionPool.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.connectionpool.ConnectionPool` can be chosen for it.
        Nz�URLs without a scheme (ie 'https://') are deprecated and will raise an error in urllib3 v3.0. To avoid this FutureWarning ensure all URLs start with 'https://' or 'http://'. Read more in this issue: https://github.com/urllib3/urllib3/issues/2920�)�category�
stacklevel)rlr6FZassert_same_hostr�r8i/ZGET�bodyrU)r�)�responseZ_poolzRedirecting %s -> %s)!rr6ryrzr{rvr7rlr8r��urlopenZrequest_uriZget_redirect_locationr�statusrZ_prepare_for_method_changer>rUrXrrYZremove_headers_on_redirectZis_same_hostr:r;rBZ	incrementrZraise_on_redirectZ
drain_conn�log�info)r]r�r�r�rpr��connr�Zredirect_locationrUZnew_headers�headerr/r/r0r��s`
�	





���zPoolManager.urlopen)rNN)rOrPr8rQrRrSr5rT)r5r)rcrdrerfrgrhr5rir`)
r6r#r7r#rlrPr3rmr5r
)r5rT�NrJN�
r7r%rlr$r6r%rrrmr5r
)r3r4r5r
)r}r"r3r4r5r
)r�r#rrrmr5r
)r�rmr5r4)r�rr5r��T�
r�r#r�r#r�r�rprSr5r)r*r+r,r-rLr.rMrWrbrkrqrjrvrur|r�rtr�r��
__classcell__r/r/r^r0r�s0
!�

�
&�

�

�rcsheZdZdZ							d/d0�fdd�
Z			d1d2�fd"d#�
Z	d3d4d&d'�Z	(d5d6�fd-d.�
Z�ZS)7ra�
    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.ProxyManager("https://localhost:3128/")

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

        # One pool was shared by both plain HTTP requests.
        print(len(proxy.pools))
        # 1

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

        # A separate pool was added for each HTTPS target.
        print(len(proxy.pools))
        # 3

    rNNF�	proxy_urlr#rOrPr8rQ�
proxy_headers�proxy_ssl_contextr&�use_forwarding_for_httpsr��proxy_assert_hostname�"None | str | typing.Literal[False]�proxy_assert_fingerprintr%rRrSr5rTc	
s�t|t�r|j�d|j�d|j��}
n|}
t|
�}|jdvr#t|j��|js3t�|jd�}|j	|d�}||_
|p9i|_||_t
||||�|_|j
|	d<|j|	d<|j|	d<t�j||fi|	��dS)	Nz://�:rIrs)rl�_proxyr9Z
_proxy_config)rXr
r6r7rlrrrr>�_replacerLr�r�r	rMrVrW)
r]r�rOr8r�r�r�r�r�rRZ
str_proxy_urlrLrlr^r/r0rW3s,



�


zProxyManager.__init__rJr7rlr$r6rrrmr
cs<|dkrt�j||||d�St�j|jj|jj|jj|d�S)NrK)rr)rVrvrLr7rlr6)r]r7rlr6rrr^r/r0rv\s��z!ProxyManager.connection_from_hostr��typing.Mapping[str, str]cCs0ddi}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.
        ZAcceptz*/*�Host)r�netloc�update)r]r�r8Zheaders_r�r/r/r0�_set_proxy_headersls

zProxyManager._set_proxy_headersTr�r�rprcsRt|�}t|j|j|j�s|�d|j�}|�||�|d<t�j	||fd|i|��S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.r8r�)
rrrLrMr6r>r8r�rVr�)r]r�r�r�rpr�r8r^r/r0r�}s
zProxyManager.urlopen)rNNNNFNN)r�r#rOrPr8rQr�rQr�r&r�r�r�r�r�r%rRrSr5rTr�r�r`)r�r#r8rQr5r�r�r�)	r*r+r,r-rWrvr�r�r�r/r/r^r0r�s$;�,���rr�r#rprScKstdd|i|��S)Nr�r/)r)r�rpr/r/r0r�sr)r1r2r3r4r5r")r�r#rprSr5r):�
__future__r�	functools�logging�typingry�typesr�urllib.parser�_collectionsrrZ_request_methodsr�
connectionr	Zconnectionpoolr
rr�
exceptionsr
rrrr�rZutil.connectionrZ
util.proxyrZ
util.retryrZutil.timeoutrZutil.urlrr�
TYPE_CHECKING�sslZtyping_extensionsr�__all__�	getLoggerr*r�rorD�
NamedTupler"rH�partialr\r[rrrr/r/r/r0�<module>sJ

'
<
�
Z