usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyo000064400000045043147205654250021066 0ustar00 abc@s5dZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd 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 rdZ5nXe7Z8dZ9dZ:dZ<de=fdYZ>de>fd YZ?dS(!s requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iN(t PoolManagertproxy_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(tConnectionErrortConnectTimeoutt ReadTimeoutR R t RetryErrort InvalidSchema(t_basic_auth_str(tSOCKSProxyManagercOstddS(Ns'Missing dependencies for SOCKS support.(R(targstkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR +si it BaseAdaptercBs8eZdZdZededddZdZRS(sThe Base Transport AdaptercCstt|jdS(N(tsuperR#t__init__(tself((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%7scCs tdS(sCSends PreparedRequest object. Returns Response object. :param request: The :class:`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) ` 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 tdS(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   t HTTPAdaptercBseZdZdddddgZeeeedZdZdZ ed Z d Z d Z d Z dd ZdZdZdZdZededddZRS(sThe 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 ` 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) t max_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      cstfdjDS(Nc3s'|]}|t|dfVqdS(N(tgetattrR4(t.0tattr(R&(sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pys s(tdictt __attrs__(R&((R&sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt __getstate__scCsbi|_i|_x*|jD]\}}t|||qW|j|j|jd|jdS(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 `. :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;RR5t poolmanager(R&t connectionsRQR=t pool_kwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRAs   c Ks||jkr|j|}n|jjdrt|\}}t|d|d|d|jd|jd|j|}|j|`. :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_fors*     cCs|jjdr|rd }|tk r6|}n|sEt}n| s_tjj| rwtdj |nd|_ tjj |s||_ q||_ nd|_ d |_ d |_ |rt|ts|d|_|d|_n||_d |_|jrCtjj|j rCtdj |jn|jrtjj|j rtdj |jqnd 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 `. :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_certst ca_cert_dirt isinstanceRt cert_filetkey_file(R&tconnturlR+R,tcert_loc((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt cert_verifys8                cCst}t|dd|_tt|di|_t|j|_||_|jj |_ t |j t r|j j d|_ n |j |_ t|j||||_||_|S(sBuilds a :class:`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 ` :param req: The :class:`PreparedRequest ` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response tstatustheaderssutf-8N(RRER4t status_codeRRtRtencodingtrawtreasonRlRptbytestdecodeRtcookiesR(t connection(R&treqtresptresponse((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytbuild_responses     cCsst||}|rEt|d}|j|}|j|}n*t|}|j}|jj|}|S(sReturns 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 `. :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|jjx!|jjD]}|jqWdS(sDisposes 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 Cst|j|}t|jj}|o3|dk}t}|rit|jj}|jd}n|j}|r| rt|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 `. :param request: The :class:`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\Rtis_proxied_http_requesttusing_socks_proxyt proxy_schemeRp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt request_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 `. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`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.pyt add_headers`s cCs8i}t|\}}|r4t|||d`. :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 ry%|\} } t d| d| }Wqt k r} dj |} t | qXn't|t rnt d|d|}y| s[|j d|jd|d|jd|jd td td td td |jd| }nft|drv|j}n|jdt}y"|j|j|dtx-|jjD]\}}|j||qW|jx^|jD]S}|jtt|djd|jd|j||jdqW|jdy|jdt}Wntk r|j}nXt j!|d|d|d td t}Wn|j"nXWnt#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.rt/| d|nt| j(t0rt1| d|nt&| d|nt2k r} t&| d|nt.k r } t/| ndt0t3fk rl} t| t0rBt1| d|qmt| t4rft5| d|qmnX|j6||S(sSends PreparedRequest object. Returns Response object. :param request: The :class:`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) ` 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(7RRpRrRRRR4RtRlttuplet TimeoutSaucet ValueErrorRgturlopenRR3R7thasattrRt _get_conntDEFAULT_POOL_TIMEOUTt putrequestR5RKt putheadert endheadersR.thextlentencodet getresponset TypeErrorRt from_httplibR/R tsocketterrorRRRxRR RRRt _ProxyErrorR t _SSLErrorR Rt _HTTPErrorR RR(R&R(R)R*R+R,R-RoRptchunkedRR<teterrR~tlow_conntheaderRNtitr((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR.s            &       N(R0R1R2RItDEFAULT_POOLSIZER>tDEFAULT_POOLBLOCKR%RJRORAR_RrRR4RR/RRRYR3R5R.(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR6Qs$      % 4 %    (@R2tos.pathRcRtpip._vendor.urllib3.poolmanagerRRtpip._vendor.urllib3.responseRtpip._vendor.urllib3.utilRRtpip._vendor.urllib3.util.retryRtpip._vendor.urllib3.exceptionsRRRRRR R RR R R RRtmodelsRtcompatRRtutilsRRRRRRt structuresRR{Rt exceptionsRRRRRtauthRt!pip._vendor.urllib3.contrib.socksR t ImportErrorR3RRR>R4RtobjectR#R6(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt sB  .4