ó â\e[c@sQdZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlm Z m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0m1Z1mZmZm2Z2m3Z3m4Z4ddl5m6Z6yddl7m8Z8Wne9k rd„Z8nXe:Z;dZ<dZ=dZ?de@fd„ƒYZAd eAfd!„ƒYZBdS("s‰ requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iÿÿÿÿN(t PoolManagertproxy_from_url(t HTTPResponse(t parse_url(tTimeout(tRetry(tClosedPoolError(tConnectTimeoutError(t HTTPError(t MaxRetryError(tNewConnectionError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(t ResponseErrori(tResponse(turlparset basestring(tDEFAULT_CA_BUNDLE_PATHtextract_zipped_pathstget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt urldefragautht select_proxy(tCaseInsensitiveDict(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutRR t RetryErrort InvalidSchematInvalidProxyURL(t_basic_auth_str(tSOCKSProxyManagercOstdƒ‚dS(Ns'Missing dependencies for SOCKS support.(R (targstkwargs((s</tmp/pip-install-0xiv62/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-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR(8scCs t‚dS(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((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pytsend;scCs t‚dS(s!Cleans up adapter specific items.N(R*(R)((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pytcloseMsN( t__name__t __module__t__doc__R(tFalsetNonetTrueR1R2(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR&5s   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_RETRIESRR6R:tfrom_intR;t proxy_managerR'R9R(R<R=R>tinit_poolmanager(R)tpool_connectionst pool_maxsizeR:t pool_block((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR(os      cst‡fd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrR7(t.0tattr(R)(s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pys ‚s(tdictt __attrs__(R)((R)s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyt __getstate__scCsbi|_i|_x*|jƒD]\}}t|||ƒqW|j|j|jd|jƒdS(NR@(RCR;titemstsetattrRDR<R=R>(R)tstateRJtvalue((s</tmp/pip-install-0xiv62/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>RR8t poolmanager(R)t connectionsRTR@t pool_kwargs((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyRD‘s   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: urllib3.ProxyManager tsockstusernametpasswordRSRTR@t proxy_headers( RCtlowert startswithRR#R<R=R>R\R(R)tproxyt proxy_kwargstmanagerRZR[R\((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pytproxy_manager_for¥s*     cCsŠ|jƒjdƒr°|r°d }|tk r6|}n|sKttƒ}n| setjj|ƒ r}t dj |ƒƒ‚nd|_ tjj |ƒs¤||_ qË||_nd|_ d |_ d |_|r†t|tƒsý|d|_|d|_n||_d |_|jrItjj|jƒ rIt dj |jƒƒ‚n|jr†tjj|jƒ r†t dj |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 `. :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(R]R^R7R8RRtostpathtexiststIOErrortformatt cert_reqstisdirtca_certst ca_cert_dirt isinstanceRt cert_filetkey_file(R)tconnturlR.R/tcert_loc((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyt cert_verifyÊs8               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(RRHR7t status_codeRRwRtencodingtrawtreasonRoRstbytestdecodeRtcookiesR+t connection(R)treqtresptresponse((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pytbuild_responseþs     cCs—t||ƒ}|rit|dƒ}t|ƒ}|jsHtdƒ‚n|j|ƒ}|j|ƒ}n*t|ƒ}|jƒ}|j j|ƒ}|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: urllib3.ConnectionPool thttpsFPlease check proxy URL. It is malformed and could be missing the host.( RRRthostR!Rbtconnection_from_urlRtgeturlRV(R)RsR0R_t proxy_urlRCRrtparsed((s</tmp/pip-install-0xiv62/pip/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(RVtclearRCtvalues(R)R_((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR2>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 RcRY( RRsRtschemeR6R]R^tpath_urlR( R)R+R0R_Rtis_proxied_http_requesttusing_socks_proxyt proxy_schemeRs((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyt request_urlHs  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-install-0xiv62/pip/pip/_vendor/requests/adapters.pyt add_headerses cCs8i}t|ƒ\}}|r4t||ƒ|d`. :param proxies: The url of the proxy being used for this request. :rtype: dict sProxy-Authorization(RR"(R)R_RwRZR[((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR\ss cCs›|j|j|ƒ}|j||j||ƒ|j||ƒ}|j|d|d|d|d|d|ƒ|jdkp†d|jk } t|t ƒròy%|\} } t d| d| ƒ}Wqt k rî} d j |ƒ} t | ƒ‚qXn't|t ƒrnt d|d|ƒ}yÇ| sy|j d |jd |d |jd |jdtdtdtdtd|jd|ƒ }nft|dƒr”|j}n|jdtƒ}y"|j|j|dtƒx-|jjƒD]\}}|j||ƒqÒW|jƒx^|jD]S}|jtt|ƒƒdjdƒƒ|jdƒ|j|ƒ|jdƒqW|jdƒy|jdtƒ}Wntk rŸ|jƒ}nXt j!|d|d|dtdtƒ}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,ƒr‚t-| 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 rŠ} t| t0ƒr`t1| d|ƒ‚q‹t| t4ƒr„t5| d|ƒ‚q‹‚nX|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 R,R-R.R/R0sContent-LengthtconnectR?ssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRstbodyRwtredirecttassert_same_hosttpreload_contenttdecode_contenttretriest proxy_pooltskip_accept_encodingisutf-8s s0 t bufferingtpoolRR+N(7RŠRsRuR’R“R–R7RwRottuplet TimeoutSaucet ValueErrorRjturlopenR•R6R:thasattrRœt _get_conntDEFAULT_POOL_TIMEOUTt putrequestR8RNt putheadert endheadersR1thextlentencodet getresponset TypeErrorRt from_httplibR2R tsocketterrorRR R{RR RRRt _ProxyErrorR t _SSLErrorRRt _HTTPErrorR RRƒ(R)R+R,R-R.R/R0RrRstchunkedR”R?teterrRtlow_conntheaderRQtitr((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR1‰s¤+           &       N(R3R4R5RLtDEFAULT_POOLSIZERAtDEFAULT_POOLBLOCKR(RMRRRDRbRuRƒR7RŠR2R’R“R\R6R8R1(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyR9Rs$      % 4 %    (CR5tos.pathRfR°tpip._vendor.urllib3.poolmanagerRRtpip._vendor.urllib3.responseRtpip._vendor.urllib3.utilRRR¡tpip._vendor.urllib3.util.retryRtpip._vendor.urllib3.exceptionsRRRR´R R R R²R R RR³RtmodelsRtcompatRRtutilsRRRRRRRt structuresRR~Rt exceptionsRRRRR R!tauthR"t!pip._vendor.urllib3.contrib.socksR#t ImportErrorR6R½R¼RAR7R¦tobjectR&R9(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/adapters.pyt sD  4: