%PDF- %PDF-
Mini Shell

Mini Shell

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



Rg<(�@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�
cKs8tj||�||_t|ddd��|_dS)NZdispose_funccSs
|j�S)N)�close)�p�r�5/usr/lib/python3/dist-packages/urllib3/poolmanager.py�<lambda>Csz&PoolManager.__init__.<locals>.<lambda>)r
�__init__�connection_pool_kwr�pools)�self�	num_pools�headersr"rrrr!?s		zPoolManager.__init__cCs|S)Nr)r$rrr�	__enter__EszPoolManager.__enter__cCs|j�dS)NF)�clear)r$�exc_typeZexc_valZexc_tbrrr�__exit__Hs
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"�copy�SSL_KEYWORDS�pop)r$�scheme�host�portZpool_cls�kwargs�kwrrr�	_new_poolMs
	
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$rrrr(^szPoolManager.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#�lockr4)r$r0r1r/Zpool_keyZpoolrrr�connection_from_hostgs
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.
        r1r/)rr8r0r1r/)r$�url�urrr�connection_from_url�s	zPoolManager.connection_from_urlTc
Ks9t|�}|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�}	t|	t�sHtj|	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.
        r1r/FZassert_same_host�redirectr&Nri/ZGETZbody�retries�responseZ_poolzRedirecting %s -> %s)rr8r0r1r/r&r,�proxy�urlopenZrequest_uriZget_redirect_locationrZstatusrZ_prepare_for_method_changer6�
isinstancerZfrom_intZremove_headers_on_redirectZis_same_host�list�sixZiterkeys�lowerr.Z	incrementrZraise_on_redirect�log�info)r$�methodr9r<r3r:Zconnr>Zredirect_locationr=r&�headerrrrr@�sH	$


	
"
		

zPoolManager.urlopen)
�__name__�
__module__�__qualname__�__doc__r?r!r'r*r4r(r8r;r@rrrrr!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:%ir5r1rr�_proxyZ_proxy_headers)zhttpr)rArr/r0r1rr	r6�_replacerr?�
proxy_headers�superrr!)r$�	proxy_urlr%r&rOr"r?r1)�	__class__rrr!�s
		

zProxyManager.__init__rcsV|dkr(tt|�j|||�Stt|�j|jj|jj|jj�S)Nr)rPrr8r?r0r1r/)r$r0r1r/)rRrrr8s

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$r9r&Zheaders_rSrrr�_set_proxy_headers
s

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<)rr/r6r&rUrPrr@)r$rGr9r<r3r:r&)rRrrr@s
zProxyManager.urlopen)rIrJrKrLr!r8rUr@rr)rRrr�scKstd||�S)NrQ)r)r9r3rrrr's)rrrrrr)"Z
__future__rZloggingZurllib.parser�ImportErrorZurlparse�_collectionsrrZconnectionpoolrrr	�
exceptionsr
rrrCZrequestr
Zutil.urlrZ
util.retryr�__all__r+Z	getLoggerrIrEr-rrrrrrr�<module>s,
�W

Zerion Mini Shell 1.0