Current File : //usr/lib/python2.7/site-packages/urllib3/poolmanager.pyc
�
�!gc@s�ddlZddlZddlZyddlmZWn!ek
r[ddlmZnXddlmZddl	m
Z
mZddl	mZddl
mZmZddlmZdd	lmZdd
lmZddd
gZeje�Zd%Zejdd&�Zejdejd'�Zejdeje�Zd�Z iej!e e�d 6ej!e e�d!6Z"ie
d 6ed!6Z#defd"��YZ$de$fd#��YZ%d$�Z&dS((i����N(turljoini(tRecentlyUsedContainer(tHTTPConnectionPooltHTTPSConnectionPool(tport_by_scheme(tLocationValueErrort
MaxRetryError(tRequestMethods(t	parse_url(tRetrytPoolManagertProxyManagertproxy_from_urltkey_filet	cert_filet	cert_reqstca_certstssl_versiontca_cert_dirtBasePoolKeytschemethosttporttHTTPPoolKeyttimeouttretrieststricttblocktsource_addresstHTTPSPoolKeycCs_i}x$|jD]}|j|�||<qW|dj�|d<|dj�|d<||�S(s�
    Create a pool key of type ``key_class`` for a request.

    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.

    :param request_context:
        A dictionary-like object that contain the context for a request.
        It should contain a key for each field in the :class:`HTTPPoolKey`
    RR(t_fieldstgettlower(t	key_classtrequest_contexttcontexttkey((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt_default_key_normalizer.sthttpthttpscBs}eZdZd
Zdd
d�Zd�Zd�Zd�Zd�Z	d
dd�Z
d	�Zd
�Zd�Z
ed�ZRS(s$
    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

    i
cKsMtj||�||_t|dd��|_t|_tj�|_dS(Ntdispose_funccSs
|j�S(N(tclose(tp((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt<lambda>xs(Rt__init__tconnection_pool_kwRtpoolstpool_classes_by_schemetkey_fn_by_schemetcopy(tselft	num_poolstheadersR-((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR,ts			cCs|S(N((R2((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt	__enter__scCs|j�tS(N(tcleartFalse(R2texc_typetexc_valtexc_tb((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt__exit__�s
cCsbt|}|j}|dkrR|jj�}x!tD]}|j|d�q5Wn||||�S(s
        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.
        R&N(R/R-R1tSSL_KEYWORDStpoptNone(R2RRRtpool_clstkwargstkw((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt	_new_pool�s
	
cCs|jj�dS(s�
        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.R6(R2((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR6�sR&cCsz|std��n|jj�}|p-d|d<|sYtj|dj�d�}n||d<||d<|j|�S(s�
        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``.
        sNo host specified.R&RiPRR(RR-R1RRR tconnection_from_context(R2RRRR"((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pytconnection_from_host�s

cCs6|dj�}|j|}||�}|j|�S(s�
        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.
        R(R R0tconnection_from_pool_key(R2R"Rtpool_key_constructortpool_key((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRC�s
cCs^|jj�L|jj|�}|r)|S|j|j|j|j�}||j|<WdQX|S(s�
        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.
        N(R.tlockRRBRRR(R2RGtpool((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRE�s
cCs.t|�}|j|jd|jd|j�S(s*
        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.
        RR(RRDRRR(R2turltu((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pytconnection_from_url�s	c
Ks�t|�}|j|jd|jd|j�}t|d<t|d<d|krf|jj�|d<n|jd
k	r�|jdkr�|j
|||�}n|j
||j|�}|o�|j�}|s�|St
||�}|jdkr�d}n|jd	�}	t|	t�s-tj|	d|�}	n|	jrq|j|�rqx(|	jD]}
|dj|
d
�qPWny"|	j||d
|d|�}	Wn!tk
r�|	jr��n|SX|	|d	<||d<tjd||f�|j
|||�S(s]
        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.
        RRtassert_same_hosttredirectR4R&i/tGETRtresponset_poolsRedirecting %s -> %sN(RRDRRRR7R4R1tproxyR>turlopentrequest_uritget_redirect_locationRtstatusRt
isinstanceR	tfrom_inttremove_headers_on_redirecttis_same_hostR=t	incrementRtraise_on_redirecttlogtinfo(R2tmethodRJRNRARKtconnRPtredirect_locationRtheader((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRS�s@	$

		"
	

N(t__name__t
__module__t__doc__R>RRR,R5R;RBR6RDRCRERLtTrueRS(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR
Vs						
		cBsGeZdZdddd�Zddd�Zdd�Zed�ZRS(sw
    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

    i
cKs�t|t�r.d|j|j|jf}nt|�}|jsmtj|jd�}|jd|�}n|jd	ks�t	d|j��||_
|p�i|_|j
|d<|j|d<tt
|�j|||�dS(
Ns
%s://%s:%iiPRR&R'sNot supported proxy scheme %st_proxyt_proxy_headers(shttpR'(RWRRRRRRRt_replacetAssertionErrorRRt
proxy_headerstsuperRR,(R2t	proxy_urlR3R4RkR-RRR((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR,:s		

R&cCsV|dkr(tt|�j|||�Stt|�j|jj|jj|jj�S(NR'(RlRRDRRRRR(R2RRR((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRDQs

cCsIidd6}t|�j}|r/||d<n|rE|j|�n|S(s�
        Sets headers needed by proxies: specifically, the Accept and Host
        headers. Only sets headers not provided by the user.
        s*/*tAccepttHost(Rtnetloctupdate(R2RJR4theaders_Rp((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt_set_proxy_headersYs

cKskt|�}|jdkrI|jd|j�}|j||�|d<ntt|�j||d||�S(s@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.R&R4RN(RRRR4RsRlRRS(R2R_RJRNRARKR4((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRShs
N(	RcRdReR>R,RDRsRfRS(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRscKstd||�S(NRm(R(RJRA((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRvs(R
RRRRR(sschemeshostsport(RsretriessstrictsblockR('tcollectionst	functoolstloggingturllib.parseRtImportErrorturlparset_collectionsRtconnectionpoolRRRt
exceptionsRRtrequestRtutil.urlRt
util.retryR	t__all__t	getLoggerRcR]R<t
namedtupleRRRRR%tpartialR0R/R
RR(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt<module>sB
	
	
�W