ž 7’Re9c@s€dZddlZddlmZddlmZmZddlmZddl m Z ddl m Z mZmZmZdd lmZmZmZmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZ ddl!m"Z"ddl#m$Z$m Z mZmZddl%m&Z&dZ(dZ)dZ*Gdd„de+ƒZ,Gdd„de,ƒZ-dS(u‰ requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iNi(uResponse(u PoolManageruproxy_from_url(u HTTPResponse(uTimeout(uurlparseu basestringu urldefraguunquote(uDEFAULT_CA_BUNDLE_PATHuget_encoding_from_headersuprepend_scheme_if_neededuget_auth_from_url(uCaseInsensitiveDict(u MaxRetryError(u TimeoutError(uSSLError(u HTTPError(u ProxyError(uextract_cookies_to_jar(uConnectionErroruTimeoutuSSLErroru ProxyError(u_basic_auth_stri csD|EeZdZdZ‡fdd†Zdd„Zdd„Z‡S(u BaseAdapteruThe Base Transport Adaptercstt|ƒjƒdS(N(usuperu BaseAdapteru__init__(uself(u __class__(u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu__init__&suBaseAdapter.__init__cCs t‚dS(N(uNotImplementedError(uself((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyusend)suBaseAdapter.sendcCs t‚dS(N(uNotImplementedError(uself((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyuclose,suBaseAdapter.close(u__name__u __module__u __qualname__u__doc__u__init__usenduclose(u __locals__((u __class__u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu BaseAdapter#s u BaseAdaptercsζ|EeZdZdZdddddgZeeee‡fdd†Zd d „Z d d „Z ed d„Z dd„Z dd„Z ddd„Zdd„Zdd„Zdd„Zdd„Zd dd!dddd„Z‡S("u HTTPAdapteru’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 ` 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 int max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed connections and timeouts, never to requests where the server returns a response. :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) u max_retriesuconfigu_pool_connectionsu _pool_maxsizeu _pool_blockcsc||_i|_i|_tt|ƒjƒ||_||_||_|j ||d|ƒdS(Nublock( u max_retriesuconfigu proxy_managerusuperu HTTPAdapteru__init__u_pool_connectionsu _pool_maxsizeu _pool_blockuinit_poolmanager(uselfupool_connectionsu pool_maxsizeu max_retriesu pool_block(u __class__(u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu__init__Is      uHTTPAdapter.__init__cs t‡fdd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(ugetattruNone(u.0uattr(uself(u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu Ysu+HTTPAdapter.__getstate__..(udictu __attrs__(uself((uselfu6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu __getstate__XsuHTTPAdapter.__getstate__cCsbi|_i|_x*|jƒD]\}}t|||ƒqW|j|j|jd|jƒdS(Nublock(u proxy_manageruconfiguitemsusetattruinit_poolmanageru_pool_connectionsu _pool_maxsizeu _pool_block(uselfustateuattruvalue((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu __setstate__\s   uHTTPAdapter.__setstate__cCs=||_||_||_td|d|d|ƒ|_dS(u΄Initializes 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. u num_poolsumaxsizeublockN(u_pool_connectionsu _pool_maxsizeu _pool_blocku PoolManageru poolmanager(uselfu connectionsumaxsizeublock((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyuinit_poolmanagerhs   uHTTPAdapter.init_poolmanagercCsΓ|jƒjdƒro|rod}|dk r6|}n|sEt}n|sZtdƒ‚nd|_||_nd|_d|_|rΏt|t ƒs³|d|_ |d|_ qΏ||_ ndS( u½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. uhttpsu4Could not find a suitable SSL CA certificate bundle.u CERT_REQUIREDu CERT_NONEiiNT( uloweru startswithuNoneuTrueuDEFAULT_CA_BUNDLE_PATHu Exceptionu cert_reqsuca_certsu isinstanceu basestringu cert_fileukey_file(uselfuconnuurluverifyucertucert_loc((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu cert_verifyys"         uHTTPAdapter.cert_verifycCsΒtƒ}t|ddƒ|_tt|diƒƒ|_t|jƒ|_||_|jj |_ t |j t ƒr|j j dƒ|_ n |j |_ t|j||ƒ||_||_|S(u”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. ustatusuheadersuutf-8N(uResponseugetattruNoneu status_codeuCaseInsensitiveDictuheadersuget_encoding_from_headersuencodingurawureasonu isinstanceuurlubytesudecodeuextract_cookies_to_jarucookiesurequestu connection(uselfurequrespuresponse((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyubuild_responsežs     uHTTPAdapter.build_responsec CsΫ|p i}|jt|jƒƒjƒ}|r­t|dƒ}|j|ƒ}||jkr”t|d|d|jd|j d|j ƒ|j|`. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. uhttpu proxy_headersu num_poolsumaxsizeublock(ugetuurlparseuloweruschemeuprepend_scheme_if_neededu proxy_headersu proxy_manageruproxy_from_urlu_pool_connectionsu _pool_maxsizeu _pool_blockuconnection_from_urlugeturlu poolmanager(uselfuurluproxiesuproxyu proxy_headersuconnuparsed((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyuget_connectionΒs"     uHTTPAdapter.get_connectioncCs|jjƒdS(u‡Disposes of any internal state. Currently, this just closes the PoolManager, which closes pooled connections. N(u poolmanageruclear(uself((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyucloseβsuHTTPAdapter.closecCsd|p i}t|jƒj}|j|ƒ}|rW|dkrWt|jƒ\}}n |j}|S(uObtain 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 to proxy URLs. uhttps(uurlparseuurluschemeugetu urldefragupath_url(uselfurequestuproxiesuschemeuproxyuurlu_((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu request_urlκs  uHTTPAdapter.request_urlcKsdS(u"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((uselfurequestukwargs((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu add_headerss uHTTPAdapter.add_headerscCs>i}t|ƒ\}}|r:|r:t||ƒ|d`. :param proxies: The url of the proxy being used for this request. :param kwargs: Optional additional keyword arguments. uProxy-Authorization(uget_auth_from_urlu_basic_auth_str(uselfuproxyuheadersuusernameupassword((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu proxy_headerss  uHTTPAdapter.proxy_headerscCsZ|j|j|ƒ}|j||j||ƒ|j||ƒ}|j|ƒ|jdkphd|jk } td|d|ƒ}y±| sα|j d|j d|d|jd|jddd dd dd dd |j d |ƒ } nPt |dƒrό|j}n|jd |ƒ} yώ| j|j |ddƒx-|jjƒD]\} } | j| | ƒq:W| jƒxd|jD]Y}| jtt|ƒƒdd…jdƒƒ| jdƒ| j|ƒ| jdƒqnW| jdƒ| jƒ}tj|d|d| d dd dƒ} Wn| jƒ‚YnX|j| ƒWntjk rn}zt |d|ƒ‚WYdd}~Xnάt!k r€}zt |d|ƒ‚WYdd}~Xn¦t"k rΤ}zt#|ƒ‚WYdd}~Xnvt$t%fk rI}zPt&|t$ƒrt'|d|ƒ‚n't&|t(ƒr4t)|d|ƒ‚n‚WYdd}~XnX|j*|| ƒS(uSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) The timeout on the request. :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. uContent-Lengthuconnectureadumethoduurlubodyuheadersuredirectuassert_same_hostupreload_contentudecode_contenturetriesutimeoutu proxy_pooluskip_accept_encodingiNuutf-8s s0 upoolu connectionurequestFT(+uget_connectionuurlu cert_verifyu request_urlu add_headersubodyuNoneuheadersu TimeoutSauceuurlopenumethoduFalseu max_retriesuhasattru proxy_poolu _get_connu putrequestuTrueuitemsu putheaderu endheadersusenduhexulenuencodeu getresponseu HTTPResponseu from_httplibucloseu _put_connusocketuerroruConnectionErroru MaxRetryErroru _ProxyErroru ProxyErroru _SSLErroru _HTTPErroru isinstanceuSSLErroru TimeoutErroruTimeoutubuild_response(uselfurequestustreamutimeoutuverifyucertuproxiesuconnuurluchunkedurespulow_connuheaderuvalueuiurusockerrue((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyusend&sv           ,      $$uHTTPAdapter.sendNFT(u__name__u __module__u __qualname__u__doc__u __attrs__uDEFAULT_POOLSIZEuDEFAULT_RETRIESuDEFAULT_POOLBLOCKu__init__u __getstate__u __setstate__uinit_poolmanageru cert_verifyubuild_responseuNoneuget_connectionucloseu request_urlu add_headersu proxy_headersuFalseuTrueusend(u __locals__((u __class__u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu HTTPAdapter0s"     % $    u HTTPAdapterF(.u__doc__usocketumodelsuResponseupackages.urllib3.poolmanageru PoolManageruproxy_from_urlupackages.urllib3.responseu HTTPResponseupackages.urllib3.utiluTimeoutu TimeoutSauceucompatuurlparseu basestringu urldefraguunquoteuutilsuDEFAULT_CA_BUNDLE_PATHuget_encoding_from_headersuprepend_scheme_if_neededuget_auth_from_urlu structuresuCaseInsensitiveDictupackages.urllib3.exceptionsu MaxRetryErroru TimeoutErroruSSLErroru _SSLErroru HTTPErroru _HTTPErroru ProxyErroru _ProxyErrorucookiesuextract_cookies_to_jaru exceptionsuConnectionErroruauthu_basic_auth_struFalseuDEFAULT_POOLBLOCKuDEFAULT_POOLSIZEuDEFAULT_RETRIESuobjectu BaseAdapteru HTTPAdapter(((u6/tmp/pip-zej_zi-build/pip/_vendor/requests/adapters.pyu s* """