HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/urllib3/__pycache__/poolmanager.cpython-310.pyc
o

��h:]�@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_certs�ca_cert_data�ssl_version�ssl_minimum_version�ssl_maximum_version�ca_cert_dir�ssl_context�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.
    �str�
key_scheme�key_host�
int | None�key_portzTimeout | float | int | None�key_timeoutzRetry | bool | int | None�key_retrieszbool | None�	key_blockztuple[str, int] | None�key_source_address�
str | None�key_key_file�key_key_password�
key_cert_file�
key_cert_reqs�key_ca_certszstr | bytes | None�key_ca_cert_datazint | str | None�key_ssl_versionzssl.TLSVersion | None�key_ssl_minimum_version�key_ssl_maximum_version�key_ca_cert_dir�ssl.SSLContext | None�key_ssl_context�key_maxsizez!frozenset[tuple[str, str]] | None�key_headers�
Url | None�
key__proxy�key__proxy_headers�ProxyConfig | None�key__proxy_configz_TYPE_SOCKET_OPTIONS | None�key_socket_options�key__socks_optionszbool | str | None�key_assert_hostname�key_assert_fingerprint�key_server_hostname�
key_blocksizeN)�__name__�
__module__�__qualname__�__doc__�__annotations__�rQrQ�I/usr/local/CyberPanel/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_headers�_socks_optionsN�socket_options�key_rKrQ)�copy�lower�	frozenset�items�get�tuple�list�keys�pop�_fields�_DEFAULT_BLOCKSIZE)rSrU�context�key�socket_opts�fieldrQrQrR�_default_key_normalizer_s&�

�rn��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

    NrA�proxyrD�proxy_config�
�	num_pools�intrZ�typing.Mapping[str, str] | None�connection_pool_kw�
typing.AnyrW�Nonecszt��|�d|vr)|d}t|t�s)|du}tj|dd�}||_|��}||d<||_|t|�|_	t
|_
t��|_dS)N�retriesF��redirect)�super�__init__�
isinstancer�from_int�raise_on_redirectr_rxr�pools�pool_classes_by_scheme�key_fn_by_scheme)�selfrurZrxr{r���	__class__rQrRr�s
	
zPoolManager.__init__rcCs|S�NrQ�r�rQrQrR�	__enter__�szPoolManager.__enter__�exc_type�type[BaseException] | None�exc_val�BaseException | None�exc_tb�TracebackType | None�typing.Literal[False]cCs|��dS)NF)�clear)r�r�r�r�rQrQrR�__exit__�szPoolManager.__exit__rXr)rY�portrU�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)rXrYr�rp)r�rxr_rcrirg�SSL_KEYWORDS)r�rXrYr�rU�pool_clsrk�kwrQrQrR�	_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)r�r�r�rQrQrRr�szPoolManager.clearrpr2r,�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.rprX�Pr�rY)r
�_merge_pool_kwargsrrcr`�connection_from_context)r�rYr�rXr�rUrQrQrR�connection_from_host$s

z PoolManager.connection_from_hostrVcCsXd|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.
        �strictzdThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v2.1.0.rX�rU)	�warnings�warn�DeprecationWarningrgr`r�rcr�connection_from_pool_key)r�rUrX�pool_key_constructor�pool_keyrQrQrRr�As	�
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.
        NrXrYr�r�)r��lockrcr�)r�r�rU�poolrXrYr�rQrQrRr�Zs

�
��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.
        )r�rXr�)rr�rYr�rX)r�r�r��urQrQrR�connection_from_urlts
�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)rxr_rb�KeyError)r�r��base_pool_kwargsrk�valuerQrQrRr��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)rrrrsrX)r�r�rQrQrR�!_proxy_requires_url_absolute_form�s

�z-PoolManager._proxy_requires_url_absolute_formT�methodr}r�rc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.
        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/2920�)�category�
stacklevel)r�rXF�assert_same_hostr}rZi/�GET�bodyr{r|)�response�_poolzRedirecting %s -> %s)!rrXr�r�r�r�rYr�rZr��urlopen�request_uri�get_redirect_locationr�statusr�_prepare_for_method_changercr{r�rr��remove_headers_on_redirect�is_same_hostr_r`rg�	incrementrr��
drain_conn�log�info)r�r�r�r}r�r��connr��redirect_locationr{�new_headers�headerrQrQrRr��s`
�	





���zPoolManager.urlopen)rtN)rurvrZrwrxryrWrz)rWr)r�r�r�r�r�r�rWr�r�)
rXr)rYr)r�rvrUr�rWr
)rWrz�NrpN�
rYr2r�r,rXr2r�r�rWr
)rUrVrWr
)r�r(rUrVrWr
)r�r)r�r�rWr
)r�r�rWrV)r�rrWr��T�
r�r)r�r)r}r�r�ryrWr)rLrMrNrOrrrPrsrr�r�r�r�r�r�r�r�r�r�r��
__classcell__rQrQr�rRr�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", "https://google.com/")
        resp2 = proxy.request("GET", "https://httpbin.org/")

        print(len(proxy.pools))
        # 1

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

        print(len(proxy.pools))
        # 3

    rtNF�	proxy_urlr)rurvrZrw�
proxy_headers�proxy_ssl_contextr=�use_forwarding_for_httpsr��proxy_assert_hostname�"None | str | typing.Literal[False]�proxy_assert_fingerprintr2rxryrWrzc	
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://�:ror�)r��_proxyr[�
_proxy_config)r�r
rXrYr�rrrrc�_replacerrr�r�r	rsr~r)
r�r�rurZr�r�r�r�r�rx�
str_proxy_urlrrr�r�rQrRr3s,



�


zProxyManager.__init__rprYr�r,rXr�r�r
cs<|dkrt�j||||d�St�j|jj|jj|jj|d�S)Nrq)r�)r~r�rrrYr�rX)r�rYr�rXr�r�rQrRr�\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.
        �Acceptz*/*�Host)r�netloc�update)r�r�rZ�headers_r�rQrQrR�_set_proxy_headersls

zProxyManager._set_proxy_headersTr�r}r�rcsRt|�}t|j|j|j�s|�d|j�}|�||�|d<t�j	||fd|i|��S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rZr})
rrrrrsrXrcrZr�r~r�)r�r�r�r}r�r�rZr�rQrRr�}s
zProxyManager.urlopen)rtNNNFNN)r�r)rurvrZrwr�rwr�r=r�r�r�r�r�r2rxryrWrzr�r�r�)r�r)rZrwrWr�r�r�)	rLrMrNrOrr�r�r�r�rQrQr�rRr�s$9�,���rr�r)r�rycKstdd|i|��S)Nr�rQ)r)r�r�rQrQrRr�sr)rSrTrUrVrWr()r�r)r�ryrWr):�
__future__r�	functools�logging�typingr��typesr�urllib.parser�_collectionsrr�_request_methodsr�
connectionr	�connectionpoolr
rr�
exceptionsr
rrrr�r�util.connectionr�
util.proxyr�
util.retryr�util.timeoutr�util.urlrr�
TYPE_CHECKING�ssl�typing_extensionsr�__all__�	getLoggerrLr�r�ri�
NamedTupler(rn�partialr�r�rrrrQrQrQrR�<module>sJ

'
<
�
\