ó `8(Zc@s;dZddlZddlZddlmZddlmZmZddl m Z ddl m Z ddlmZdd lmZmZdd lmZmZmZmZmZmZmZdd lmZdd lmZdd lmZddlm Z!ddlm"Z"ddlm#Z#ddlm$Z%ddlm&Z&ddlm'Z'ddlm(Z)ddlm*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0m(Z(m$Z$m1Z1m2Z2ddl3m4Z4yddl5m6Z6Wne7k ròd„Z6nXe8Z9dZ:dZ;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ÿÿÿÿNi(tResponse(t PoolManagertproxy_from_url(t HTTPResponse(tTimeout(tRetry(turlparset basestring(tDEFAULT_CA_BUNDLE_PATHtget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt urldefragautht select_proxytto_native_string(tCaseInsensitiveDict(tClosedPoolError(tConnectTimeoutError(t HTTPError(t MaxRetryError(tNewConnectionError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(t ResponseError(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutRRt RetryErrort InvalidSchema(t_basic_auth_str(tSOCKSProxyManagercOstdƒ‚dS(Ns'Missing dependencies for SOCKS support.(R(targstkwargs((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR!*si it BaseAdaptercBs8eZdZd„Zededdd„Zd„ZRS(sThe Base Transport AdaptercCstt|ƒjƒdS(N(tsuperR$t__init__(tself((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR&6scCs t‚dS(s°Sends 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) Whether to verify SSL certificates. :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((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pytsend9scCs t‚dS(s!Cleans up adapter specific items.N(R((R'((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pytcloseIsN( t__name__t __module__t__doc__R&tFalsetNonetTrueR/R0(((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR$3s   t HTTPAdaptercBs¹eZdZdddddgZeeeed„Zd„Zd„Z ed „Z d „Z d „Z d „Z dd „Zd„Zd„Zd„Zd„Zededdd„ZRS(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_RETRIESRR4R8tfrom_intR9t proxy_managerR%R7R&R:R;R<tinit_poolmanager(R'tpool_connectionst pool_maxsizeR8t pool_block((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR&ks      cst‡fd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrR5(t.0tattr(R'(s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pys ~s(tdictt __attrs__(R'((R's:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyt __getstate__}scCsbi|_i|_x*|jƒD]\}}t|||ƒqW|j|j|jd|jƒdS(NR>(RAR9titemstsetattrRBR:R;R<(R'tstateRHtvalue((s:/tmp/pip-build-0nEYGB/pip/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(R:R;R<RR6t poolmanager(R't connectionsRRR>t pool_kwargs((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyRBs   c KsØ||jkr|j|}nµ|jƒjdƒrŠt|ƒ\}}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: requests.packages.urllib3.ProxyManager tsockstusernametpasswordRQRRR>t proxy_headers( RAtlowert startswithR R!R:R;R<RZR(R'tproxyt proxy_kwargstmanagerRXRYRZ((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pytproxy_manager_for¡s*     cCsê|jƒjdƒr|rd}|tk r6|}n|sEt}n|sZtdƒ‚nd|_tjj |ƒs||_ q¨||_ nd|_d|_ d|_ |ræt |t ƒsÚ|d|_|d|_qæ||_ndS(s½Verify 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: Whether we should actually verify the certificate. :param cert: The SSL certificate to verify. thttpss4Could not find a suitable SSL CA certificate bundle.t CERT_REQUIREDt CERT_NONEiiN(R[R\R5R6Rt Exceptiont cert_reqstostpathtisdirtca_certst ca_cert_dirt isinstanceRt cert_filetkey_file(R'tconnturlR,R-tcert_loc((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyt cert_verifyÆs(           cCsÂtƒ}t|ddƒ|_tt|diƒƒ|_t|jƒ|_||_|jj |_ t |j t ƒr|j j dƒ|_ n |j |_ t|j||ƒ||_||_|S(s¶Builds 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(RRFR5t status_codeRRsR tencodingtrawtreasonRkRotbytestdecodeRtcookiesR)t connection(R'treqtresptresponse((s:/tmp/pip-build-0nEYGB/pip/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 `. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: requests.packages.urllib3.ConnectionPool thttp(R R R`tconnection_from_urlRtgeturlRT(R'RoR.R]RARntparsed((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pytget_connections   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(RTtclearRAtvalues(R'R]((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR0,s 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 `. :param request: The :class:`PreparedRequest ` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str RaRW( R RoRtschemeR4R[R\tpath_urlR ( R'R)R.R]R‡tis_proxied_http_requesttusing_socks_proxyt proxy_schemeRo((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyt request_url6s  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#((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyt add_headersSs cCs>i}t|ƒ\}}|r:|r:t||ƒ|d`. :param proxies: The url of the proxy being used for this request. :rtype: dict sProxy-Authorization(R R (R'R]RsRXRY((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyRZas  cCsD|j|j|ƒ}|j||j||ƒ|j||ƒ}|j|ƒ|jdkphd|jk } t|t ƒrÔy%|\} } t d| d| ƒ}Wqét k rÐ} dj |ƒ} t | ƒ‚qéXnt d|d|ƒ}yÇ| sI|j d|jd|d|jd|jd td td td td |jd|ƒ }nft|dƒrd|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 ro|jƒ}nXt j!|d|d|d td tƒ}Wn|j"ƒ‚nXWnt#t$j%fk rà} t&| d|ƒ‚nTt'k rŽ} t| j(t)ƒr+t| j(t*ƒs+t+| d|ƒ‚q+nt| j(t,ƒrRt-| d|ƒ‚nt| j(t.ƒryt/| d|ƒ‚nt&| d|ƒ‚n¦t0k r²} t&| d|ƒ‚n‚t.k rÐ} t/| ƒ‚ndt1t2fk r3} t| t1ƒr t3| d|ƒ‚q4t| t4ƒr-t5| d|ƒ‚q4‚nX|j6||ƒS(sÒSends 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) Whether to verify SSL certificates. :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 valuetmethodRotbodyRstredirecttassert_same_hosttpreload_contenttdecode_contenttretriesR+t proxy_pooltskip_accept_encodingisutf-8s s0 t bufferingtpoolR{R)N(7R„RoRqRŒRRR5RsRkttuplet TimeoutSaucet ValueErrortformatturlopenRR4R8thasattrR–t _get_conntDEFAULT_POOL_TIMEOUTt putrequestR6RLt putheadert endheadersR/thextlentencodet getresponset TypeErrorRt from_httplibR0RtsocketterrorRRRwRRRRRt _ProxyErrorRRt _SSLErrort _HTTPErrorRRRR(R'R)R*R+R,R-R.RnRotchunkedRŽR=teterrR}tlow_conntheaderROtitr((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR/wsœ            &       N(R1R2R3RJtDEFAULT_POOLSIZER?tDEFAULT_POOLBLOCKR&RKRPRBR`RqRR5R„R0RŒRRZR4R6R/(((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyR7Ns$      % * %    (AR3tos.pathRfR«tmodelsRtpackages.urllib3.poolmanagerRRtpackages.urllib3.responseRtpackages.urllib3.utilRR›tpackages.urllib3.util.retryRtcompatRRtutilsRR R R R R Rt structuresRtpackages.urllib3.exceptionsRRRR¯RRRR­RRRR®RRzRt exceptionsRRRRRtauthR tpackages.urllib3.contrib.socksR!t ImportErrorR4R¸R·R?R5R¡tobjectR$R7(((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/adapters.pyt sB  44