%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/2940/usr/lib/python3/dist-packages/urllib3/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/2940/usr/lib/python3/dist-packages/urllib3/__pycache__/poolmanager.cpython-36.pyc

3

&�[h�F�@sddlmZddlZddlZddlZddlmZmZddlm	Z	m
Z
ddlmZddlm
Z
mZmZddlZddlmZdd	lmZdd
lmZddlmZdd
dgZeje�Zd4Zd5Zejd-e�Z d.d/�Z!ej"e!e �ej"e!e �d0�Z#e	e
d0�Z$Gd1d�de�Z%Gd2d
�d
e%�Z&d3d�Z'dS)6�)�absolute_importN�)�HTTPHeaderDict�RecentlyUsedContainer)�HTTPConnectionPool�HTTPSConnectionPool)�port_by_scheme)�LocationValueError�
MaxRetryError�ProxySchemeUnknown)�urljoin)�RequestMethods)�	parse_url)�Retry�PoolManager�ProxyManager�proxy_from_url�key_file�	cert_file�	cert_reqs�ca_certs�ssl_version�ca_cert_dir�ssl_context�
key_scheme�key_host�key_port�key_timeout�key_retries�
key_strict�	key_block�key_source_address�key_key_file�
key_cert_file�
key_cert_reqs�key_ca_certs�key_ssl_version�key_ca_cert_dir�key_ssl_context�key_maxsize�key_headers�
key__proxy�key__proxy_headers�key_socket_options�key__socks_options�key_assert_hostname�key_assert_fingerprint�PoolKeycCs�|j�}|dj�|d<|dj�|d<x4d	D],}||kr.||dk	r.t||j��||<q.W|jd�}|dk	r|t|�|d<x&t|j��D]}|j|�|d|<q�Wx|j	D]}||kr�d||<q�W|f|�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_optionsNZsocket_optionsZkey_)r4r5r6)
�copy�lower�	frozenset�items�get�tuple�list�keys�pop�_fields)Z	key_class�request_context�context�keyZsocket_optsZfield�rD�5/usr/lib/python3/dist-packages/urllib3/poolmanager.py�_default_key_normalizer:s

rF)�http�httpsc@sxeZdZdZdZddd�Zdd�Zdd	�Zdd
d�Zdd
�Z	ddd�Z
dd�Zddd�Zd dd�Z
dd�Zd!dd�ZdS)"ra$
    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::

        >>> manager = PoolManager(num_pools=2)
        >>> r = manager.request('GET', 'http://google.com/')
        >>> r = manager.request('GET', 'http://google.com/mail')
        >>> r = manager.request('GET', 'http://yahoo.com/')
        >>> len(manager.pools)
        2

    N�
cKs~tj||�d|krR|d}t|t�sR|dk	}tj|dd�}||_|j�}||d<||_t|dd�d�|_	t
|_
tj�|_dS)N�retriesF)�redirectcSs|j�S)N)�close)�prDrDrE�<lambda>�sz&PoolManager.__init__.<locals>.<lambda>)Zdispose_func)r
�__init__�
isinstancer�from_int�raise_on_redirectr7�connection_pool_kwr�pools�pool_classes_by_scheme�key_fn_by_scheme)�self�	num_poolsr4rSrJrRrDrDrErO�s
	zPoolManager.__init__cCs|S)NrD)rWrDrDrE�	__enter__�szPoolManager.__enter__cCs|j�dS)NF)�clear)rW�exc_typeZexc_valZexc_tbrDrDrE�__exit__�szPoolManager.__exit__cCsf|j|}|dkr|jj�}xdD]}|j|d�q"W|dkrXxtD]}|j|d�qDW|||f|�S)a�
        Create a new :class:`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.
        Nr2r3�portrG)r2r3r])rUrSr7r?�SSL_KEYWORDS)rWr2r3r]rAZpool_clsrC�kwrDrDrE�	_new_pool�s




zPoolManager._new_poolcCs|jj�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)rTrZ)rWrDrDrErZ�szPoolManager.clearrGcCsT|std��|j|�}|pd|d<|s:tj|dj�d�}||d<||d<|j|�S)a�
        Get a :class:`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.rGr2�Pr]r3)r	�_merge_pool_kwargsrr;r8�connection_from_context)rWr3r]r2�pool_kwargsrArDrDrE�connection_from_host�s
z PoolManager.connection_from_hostcCs,|dj�}|j|}||�}|j||d�S)z�
        Get a :class:`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.
        r2)rA)r8rV�connection_from_pool_key)rWrAr2Zpool_key_constructor�pool_keyrDrDrErc�s
z#PoolManager.connection_from_contextc
Cs`|jj�N|jj|�}|r|S|d}|d}|d}|j||||d�}||j|<WdQRX|S)z�
        Get a :class:`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.
        r2r3r])rAN)rT�lockr;r`)rWrgrAZpoolr2r3r]rDrDrErfs
z$PoolManager.connection_from_pool_keycCs 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]r2rd)rrer3r]r2)rW�urlrd�urDrDrE�connection_from_urlszPoolManager.connection_from_urlcCsZ|jj�}|rVxF|j�D]:\}}|dkrJy
||=WqRtk
rFYqRXq|||<qW|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)rSr7r:�KeyError)rW�overrideZbase_pool_kwargsrC�valuerDrDrErb*s

zPoolManager._merge_pool_kwargsTcKs�t|�}|j|j|j|jd�}d|d<d|d<d|krD|jj�|d<|jdk	rj|jdkrj|j||f|�}n|j||j	f|�}|o�|j
�}|s�|St||�}|jdkr�d	}d|d
<t
|d�j�|d<|jd|j�}	t|	t�s�tj|	|d�}	|	jo�|j|��r@ttj|d��}
x.|
D]&}|j�|	jk�r|dj|d��qWy|	j||||d
�}	Wn tk
�rv|	j�rr�|SX|	|d<||d<tjd||�|j||f|�S)a]
        Same as :meth:`urllib3.connectionpool.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.
        )r]r2FZassert_same_hostrKr4NrGi/ZGETZbodyrJ)rK)�responseZ_poolzRedirecting %s -> %s) rrer3r]r2r4r7�proxy�urlopenZrequest_uriZget_redirect_locationrZstatusrZ_prepare_for_method_changer;rJrPrrQZremove_headers_on_redirectZis_same_hostr=�sixZiterkeysr8r?Z	incrementr
rR�log�info)rW�methodrirKr_rjZconnroZredirect_locationrJr4�headerrDrDrErq>sH	



zPoolManager.urlopen)rIN)N)NrGN)N)N)T)�__name__�
__module__�__qualname__�__doc__rprOrYr\r`rZrercrfrkrbrqrDrDrDrErzs

	


csHeZdZdZd�fdd�	Zd�fdd�	Zdd	d
�Zd�fdd
�	Z�ZS)raw
    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 contaning 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.

    Example:
        >>> proxy = urllib3.ProxyManager('http://localhost:3128/')
        >>> r1 = proxy.request('GET', 'http://google.com/')
        >>> r2 = proxy.request('GET', 'http://httpbin.org/')
        >>> len(proxy.pools)
        1
        >>> r3 = proxy.request('GET', 'https://httpbin.org/')
        >>> r4 = proxy.request('GET', 'https://twitter.com/')
        >>> len(proxy.pools)
        3

    rINcs�t|t�rd|j|j|jf}t|�}|jsFtj|jd�}|j|d�}|jdkrZt	|j��||_
|pfi|_|j
|d<|j|d<tt
|�j||f|�dS)	Nz
%s://%s:%ira)r]rGrH�_proxyr5)rGrH)rPrr2r3r]rrr;�_replacerrp�
proxy_headers�superrrO)rW�	proxy_urlrXr4r}rSrpr])�	__class__rDrErO�s








zProxyManager.__init__rGcsD|dkr tt|�j||||d�Stt|�j|jj|jj|jj|d�S)NrH)rd)r~rrerpr3r]r2)rWr3r]r2rd)r�rDrEre�s


z!ProxyManager.connection_from_hostcCs0ddi}t|�j}|r||d<|r,|j|�|S)z�
        Sets headers needed by proxies: specifically, the Accept and Host
        headers. Only sets headers not provided by the user.
        ZAcceptz*/*ZHost)r�netloc�update)rWrir4Zheaders_r�rDrDrE�_set_proxy_headers�s

zProxyManager._set_proxy_headersTcsNt|�}|jdkr0|jd|j�}|j||�|d<tt|�j||fd|i|��S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rGr4rK)rr2r;r4r�r~rrq)rWrurirKr_rjr4)r�rDrErq�s

zProxyManager.urlopen)rINN)NrGN)N)T)	rwrxryrzrOrer�rq�
__classcell__rDrD)r�rErs
cKstfd|i|��S)Nr)r)rir_rDrDrEr�s)rrrrrrr)rrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0)(Z
__future__r�collections�	functoolsZlogging�_collectionsrrZconnectionpoolrrr�
exceptionsr	r
rrrZsix.moves.urllib.parserZrequestr
Zutil.urlrZ
util.retryr�__all__Z	getLoggerrwrsr^Z_key_fields�
namedtupler1rF�partialrVrUrrrrDrDrDrE�<module>sd

6
W

Zerion Mini Shell 1.0