Your IP : 3.12.34.211


Current Path : /lib/python2.7/site-packages/pip/_vendor/requests/
Upload File :
Current File : //lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyc

�
��abc@s5dZddlZddlZddlmZmZddlmZddl	m
Zddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/mZmZm0Z0m1Z1ddl2m3Z3yddl4m5Z5Wne6k
r�d�Z5nXe7Z8dZ9dZ:dZ<de=fd��YZ>de>fd ��YZ?dS(!s�
requests.adapters
~~~~~~~~~~~~~~~~~

This module contains the transport adapters that Requests uses to define
and maintain connections.
i����N(tPoolManagertproxy_from_url(tHTTPResponse(tTimeout(tRetry(tClosedPoolError(tConnectTimeoutError(t	HTTPError(t
MaxRetryError(tNewConnectionError(t
ProxyError(t
ProtocolError(tReadTimeoutError(tSSLError(t
ResponseErrori(tResponse(turlparset
basestring(tDEFAULT_CA_BUNDLE_PATHtget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt
urldefragauthtselect_proxy(tCaseInsensitiveDict(textract_cookies_to_jar(tConnectionErrortConnectTimeouttReadTimeoutR
R
t
RetryErrort
InvalidSchema(t_basic_auth_str(tSOCKSProxyManagercOstd��dS(Ns'Missing dependencies for SOCKS support.(R(targstkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR +si
itBaseAdaptercBs8eZdZd�Zededdd�Zd�ZRS(sThe Base Transport AdaptercCstt|�j�dS(N(tsuperR#t__init__(tself((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%7scCs
t�dS(sCSends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        N(tNotImplementedError(R&trequesttstreamttimeouttverifytcerttproxies((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytsend:scCs
t�dS(s!Cleans up adapter specific items.N(R'(R&((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytcloseLsN(	t__name__t
__module__t__doc__R%tFalsetNonetTrueR.R/(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR#4s
		tHTTPAdaptercBs�eZdZdddddgZeeeed�Zd�Zd�Z	ed	�Z
d
�Zd�Zd�Z
dd
�Zd�Zd�Zd�Zd�Zededdd�ZRS(s�The built-in HTTP Adapter for urllib3.

    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.

    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.

    Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    tmax_retriestconfigt_pool_connectionst
_pool_maxsizet_pool_blockcCs�|tkr$tddt�|_ntj|�|_i|_i|_tt|�j	�||_
||_||_|j
||d|�dS(Nitreadtblock(tDEFAULT_RETRIESRR3R7tfrom_intR8t
proxy_managerR$R6R%R9R:R;tinit_poolmanager(R&tpool_connectionstpool_maxsizeR7t
pool_block((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%ns					cst�fd��jD��S(Nc3s'|]}|t�|d�fVqdS(N(tgetattrR4(t.0tattr(R&(sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pys	<genexpr>�s(tdictt	__attrs__(R&((R&sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt__getstate__�scCsbi|_i|_x*|j�D]\}}t|||�qW|j|j|jd|j�dS(NR=(R@R8titemstsetattrRAR9R:R;(R&tstateRGtvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt__setstate__�s		c
KsF||_||_||_td|d|d|dt|�|_dS(sInitializes a urllib3 PoolManager.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
        t	num_poolstmaxsizeR=tstrictN(R9R:R;RR5tpoolmanager(R&tconnectionsRQR=tpool_kwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRA�s

			c
Ks�||jkr|j|}n�|j�jd�r�t|�\}}t|d|d|d|jd|jd|j|�}|j|<nJ|j|�}t	|d|d|jd|jd|j|�}|j|<|S(s�Return urllib3 ProxyManager for the given proxy.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        :rtype: urllib3.ProxyManager
        tsockstusernametpasswordRPRQR=t
proxy_headers(
R@tlowert
startswithRR R9R:R;RYR(R&tproxytproxy_kwargstmanagerRWRXRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytproxy_manager_for�s*				cCs�|j�jd�r�|r�d	}|tk	r6|}n|sEt}n|s_tjj|�rwtdj	|���nd|_
tjj|�s�||_q�||_
nd|_
d	|_d	|_
|r�t|t�s�|d|_|d|_n||_d	|_|jrCtjj|j�rCtdj	|j���n|jr�tjj|j�r�tdj	|j���q�nd	S(
sAVerify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: The SSL certificate to verify.
        thttpssFCould not find a suitable TLS CA certificate bundle, invalid path: {0}t
CERT_REQUIREDt	CERT_NONEiis:Could not find the TLS certificate file, invalid path: {0}s2Could not find the TLS key file, invalid path: {0}N(RZR[R4R5RtostpathtexiststIOErrortformatt	cert_reqstisdirtca_certstca_cert_dirt
isinstanceRt	cert_filetkey_file(R&tconnturlR+R,tcert_loc((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytcert_verify�s8							
				cCs�t�}t|dd�|_tt|di��|_t|j�|_||_|jj	|_	t
|jt�r�|jj
d�|_n|j|_t|j||�||_||_|S(s�Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`

        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        tstatustheaderssutf-8N(RRER4tstatus_codeRRtRtencodingtrawtreasonRlRptbytestdecodeRtcookiesR(t
connection(R&treqtresptresponse((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytbuild_response�s
				cCsst||�}|rEt|d�}|j|�}|j|�}n*t|�}|j�}|jj|�}|S(s�Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        thttp(RRR_tconnection_from_urlRtgeturlRS(R&RpR-R\R@Rotparsed((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytget_connection"s	cCs5|jj�x!|jj�D]}|j�qWdS(s�Disposes of any internal state.

        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        N(RStclearR@tvalues(R&R\((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR/9s
c	Cs�t|j|�}t|j�j}|o3|dk}t}|rit|�jj�}|jd�}n|j}|r�|r�t|j�}n|S(s?Obtain the url to use when making the final request.

        If the message is being sent through a HTTP proxy, the full URL has to
        be used. Otherwise, we should only use the path portion of the URL.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
        :rtype: str
        R`RV(	RRpRtschemeR3RZR[tpath_urlR(	R&R(R-R\R�tis_proxied_http_requesttusing_socks_proxytproxy_schemeRp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytrequest_urlCs	
cKsdS(s"Add any headers needed by the connection. As of v2.0 this does
        nothing by default, but is left for overriding by users that subclass
        the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
        :param kwargs: The keyword arguments from the call to send().
        N((R&R(R"((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytadd_headers`scCs8i}t|�\}}|r4t||�|d<n|S(s
Returns a dictionary of the headers to add to any request sent
        through a proxy. This works with urllib3 magic to ensure that they are
        correctly sent to the proxy, rather than in a tunnelled request if
        CONNECT is being used.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param proxies: The url of the proxy being used for this request.
        :rtype: dict
        sProxy-Authorization(RR(R&R\RtRWRX((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRYns
cCs}|j|j|�}|j||j||�|j||�}|j|�|jdkphd|jk}	t|t	�r�y%|\}
}t
d|
d|�}Wq�tk
r�}dj|�}
t|
��q�Xn't|t
�r�nt
d|d|�}y�|	s[|j
d|jd|d|jd|jd	td
tdtdtd
|jd|�
}nft|d�rv|j}n|jdt�}y"|j|j|dt�x-|jj�D]\}}|j||�q�W|j�x^|jD]S}|jtt|��djd��|jd�|j|�|jd�q�W|jd�y|jdt�}Wntk
r�|j�}nXt j!|d|d|dtdt�}Wn|j"��nXWn�t#t$j%fk
r�}
t&|
d|��n{t'k
r�}t|j(t)�r=t|j(t*�s=t+|d|��q=nt|j(t,�rdt-|d|��nt|j(t.�r�t/|d|��nt|j(t0�r�t1|d|��nt&|d|��n�t2k
r�}t&|d|��n�t.k
r	}t/|��ndt0t3fk
rl}t|t0�rBt1|d|��qmt|t4�rft5|d|��qm�nX|j6||�S(sSends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple or urllib3 Timeout object
        :param verify: (optional) Either a boolean, in which case it controls whether
            we verify the server's TLS certificate, or a string, in which case it
            must be a path to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        :rtype: requests.Response
        sContent-LengthtconnectR<ssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRptbodyRttredirecttassert_same_hosttpreload_contenttdecode_contenttretriesR*t
proxy_pooltskip_accept_encodingisutf-8s
s0

t	bufferingtpoolR|R(N(7R�RpRrR�R�R�R4RtRlttupletTimeoutSaucet
ValueErrorRgturlopenR�R3R7thasattrR�t	_get_conntDEFAULT_POOL_TIMEOUTt
putrequestR5RKt	putheadert
endheadersR.thextlentencodetgetresponset	TypeErrorRtfrom_httplibR/RtsocketterrorRRRxRR	RRRt_ProxyErrorR
t	_SSLErrorR
Rt
_HTTPErrorRRR�(R&R(R)R*R+R,R-RoRptchunkedR�R<teterrR~tlow_conntheaderRNtitr((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR.�s�
						
&





N(R0R1R2RItDEFAULT_POOLSIZER>tDEFAULT_POOLBLOCKR%RJRORAR_RrR�R4R�R/R�R�RYR3R5R.(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR6Qs$				%	4	%	
			(@R2tos.pathRcR�tpip._vendor.urllib3.poolmanagerRRtpip._vendor.urllib3.responseRtpip._vendor.urllib3.utilRR�tpip._vendor.urllib3.util.retryRtpip._vendor.urllib3.exceptionsRRRR�RR	R
R�RRR
R�RtmodelsRtcompatRRtutilsRRRRRRt
structuresRR{Rt
exceptionsRRRRRtauthRt!pip._vendor.urllib3.contrib.socksR tImportErrorR3R�R�R>R4R�tobjectR#R6(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt<module>	sB.4



?>