Viewing File: /opt/alt/python35/lib/python3.5/site-packages/urllib3/__pycache__/poolmanager.cpython-35.pyc



V%@sIddlmZddlZyddlmZWn"ek
rTddlmZYnXddlmZddl	m
Z
mZddl	mZddl
mZmZmZdd	lmZdd
lmZddlmZdd
dgZejeZdZde
deiZGdddeZGdd
d
eZddZdS))absolute_importN)urljoin)RecentlyUsedContainer)HTTPConnectionPoolHTTPSConnectionPool)port_by_scheme)LocationValueError
MaxRetryErrorProxySchemeUnknown)RequestMethods)	parse_url)RetryPoolManagerProxyManagerproxy_from_urlkey_file	cert_file	cert_reqsca_certsssl_versionca_cert_dirhttphttpsc@seZdZdZdZddddZddZdd	Zd
dZdd
Z	ddddZ
ddZdddZ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
cKsAtj||||_t|ddd|_t|_dS)NZdispose_funccSs
|jS)N)close)pr/poolmanager.py<lambda>Bsz&PoolManager.__init__.<locals>.<lambda>)r__init__connection_pool_kwrpoolspool_classes_by_scheme)self	num_poolsheadersr!rrrr >s
		zPoolManager.__init__cCs|S)Nr)r$rrr	__enter__GszPoolManager.__enter__cCs|jdS)NF)clear)r$exc_typeexc_valexc_tbrrr__exit__Js
zPoolManager.__exit__cCsb|j|}|j}|dkrR|jj}xtD]}|j|dq8W||||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)r#r!copySSL_KEYWORDSpop)r$schemehostportZpool_clskwargskwrrr	_new_poolOs
	
zPoolManager._new_poolcCs|jjdS)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}|jjC|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.rPN)r	rgetr"lockr5)r$r1r2r0Zpool_keypoolrrrconnection_from_hostis
z PoolManager.connection_from_hostcCs.t|}|j|jd|jd|jS)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.
        r2r0)r
r:r1r2r0)r$urlurrrconnection_from_urls	zPoolManager.connection_from_urlTc

Kst|}|j|jd|jd|j}d|d<d|d<d|kr]|j|d<|jdk	r|jdkr|j|||}n|j||j|}|o|j	}|s|St
||}|jd	krd
}|jd}	t
|	tstj|	d|}	y"|	j||d|d
|}	Wn"tk
rd|	jr\|SYnX|	|d<||d<tjd|||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.
        r2r0FZassert_same_hostredirectr&Nri/GETretriesresponseZ_poolzRedirecting %s -> %s)r
r:r1r2r0r&proxyurlopenZrequest_uriZget_redirect_locationrstatusr7
isinstancerZfrom_intZ	incrementr
Zraise_on_redirectloginfo)
r$methodr;r>r4r<connrAZredirect_locationr@rrrrCs8	$


"
		

zPoolManager.urlopen)
__name__
__module____qualname____doc__rBr r'r,r5r(r:r=rCrrrrr s		csmeZdZdZdddfddZddfddZdd	d
Zdfdd
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

    rNcst|tr+d|j|j|jf}t|}|jsgtj|jd}|jd|}|jdkrt	|j||_
|pi|_|j
|d<|j|d<tt
|j|||dS)	Nz
%s://%s:%ir6r2rr_proxyZ_proxy_headers)zhttpr)rErr0r1r2r
rr7_replacerrB
proxy_headerssuperrr )r$	proxy_urlr%r&rPr!rBr2)	__class__rrr s
		

zProxyManager.__init__rcsV|dkr(tt|j|||Stt|j|jj|jj|jjS)Nr)rQrr:rBr1r2r0)r$r1r2r0)rSrrr: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
netlocupdate)r$r;r&Zheaders_rTrrr_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>)r
r0r7r&rVrQrrC)r$rHr;r>r4r<r&)rSrrrC
s
zProxyManager.urlopen)rJrKrLrMr r:rVrCrr)rSrrscKstd||S)NrR)r)r;r4rrrrs)rrrrrr) Z
__future__rloggingZurllib.parserImportErrorurlparse_collectionsrZconnectionpoolrrr
exceptionsr	r
rZrequestrZutil.urlr
Z
util.retryr__all__	getLoggerrJrFr.r#rrrrrrr<module>s*
W
Back to Directory File Manager