0{Y9@sdZddlZddlmZddlmZmZddlmZddl 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)Gddde*Z+Gddde+Z,dS)z requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. N)Response) PoolManagerproxy_from_url) HTTPResponse)Timeout)urlparse basestring urldefragunquote)DEFAULT_CA_BUNDLE_PATHget_encoding_from_headersprepend_scheme_if_neededget_auth_from_url)CaseInsensitiveDict) MaxRetryError) TimeoutError)SSLError) HTTPError) ProxyError)extract_cookies_to_jar)ConnectionErrorrrr)_basic_auth_strF cs@eZdZdZfddZddZddZS) BaseAdapterzThe Base Transport Adaptercstt|jdS)N)superr__init__)self) __class__8/tmp/pip-ok8sy_ze-build/pip/_vendor/requests/adapters.pyr&szBaseAdapter.__init__cCs tdS)N)NotImplementedError)rrrr send)szBaseAdapter.sendcCs tdS)N)r!)rrrr close,szBaseAdapter.close)__name__ __module__ __qualname____doc__rr"r#rr)rr r#s  rcseZdZdZdddddgZeeeefddZd d Z d d Z ed dZ ddZ ddZ dddZddZddZddZddZdddddd d!ZS)" HTTPAdapteraThe 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) max_retriesconfig_pool_connections _pool_maxsize _pool_blockcsc||_i|_i|_tt|j||_||_||_|j ||d|dS)Nblock) r)r* proxy_managerrr(rr+r,r-init_poolmanager)rpool_connections pool_maxsizer) pool_block)rrr rIs      zHTTPAdapter.__init__cs tfddjDS)Nc3s'|]}|t|dfVqdS)N)getattr).0attr)rrr Ysz+HTTPAdapter.__getstate__..)dict __attrs__)rr)rr __getstate__XszHTTPAdapter.__getstate__cCsbi|_i|_x*|jD]\}}t|||qW|j|j|jd|jdS)Nr.)r/r*itemssetattrr0r+r,r-)rstater6valuerrr __setstate__\s   zHTTPAdapter.__setstate__cCs=||_||_||_td|d|d||_dS)aInitializes 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. num_poolsmaxsizer.N)r+r,r-r poolmanager)r connectionsrAr.rrr r0hs   zHTTPAdapter.init_poolmanagercCs|jjdro|rod}|dk r6|}n|sEt}n|sZtdnd|_||_nd|_d|_|rt|ts|d|_|d|_ q||_ndS) aVerify 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. httpsNTz4Could not find a suitable SSL CA certificate bundle. CERT_REQUIRED CERT_NONErr) lower startswithr Exception cert_reqsca_certs isinstancer cert_filekey_file)rconnurlverifycertcert_locrrr cert_verifyys"         zHTTPAdapter.cert_verifycCst}t|dd|_tt|di|_t|j|_||_|jj|_t |j t r|j j d|_ n |j |_ t |j||||_||_|S)aBuilds 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. statusNheaderszutf-8)rr4 status_coderrVr encodingrawreasonrLrPbytesdecodercookiesrequest connection)rreqrespresponserrr build_responses     zHTTPAdapter.build_responseNc Cs|p i}|jt|jj}|rt|d}|j|}||jkrt|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. http proxy_headersr@rAr.)getrrGschemerrer/rr+r,r-connection_from_urlgeturlrB)rrPproxiesproxyrerOparsedrrr get_connections"     zHTTPAdapter.get_connectioncCs|jjdS)zDisposes of any internal state. Currently, this just closes the PoolManager, which closes pooled connections. N)rBclear)rrrr r#szHTTPAdapter.closecCsd|p i}t|jj}|j|}|rW|dkrWt|j\}}n |j}|S)aObtain 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. rD)rrPrgrfr path_url)rr^rjrgrkrP_rrr request_urls  zHTTPAdapter.request_urlcKsdS)a"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(). Nr)rr^kwargsrrr add_headerss zHTTPAdapter.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. zProxy-Authorization)rr)rrkrVusernamepasswordrrr res  zHTTPAdapter.proxy_headersFTcCsZ|j|j|}|j||j|||j||}|j||jdkphd|jk } td|d|}y| s|jd|j d|d|jd|jd d d d d d d d d|j d| } nPt |dr|j }n|j d|} y| j|j |ddx-|jjD]\} } | j| | q:W| jxd|jD]Y}| jtt|ddjd| jd| j|| jdqnW| jd| j}tj|d|d| d d d d } Wn| jYnX|j| Wntjk rn}zt|d|WYdd}~Xntk r}zt|d|WYdd}~Xntk r}zt |WYdd}~Xnvt!t"fk rI}zPt#|t!rt$|d|n't#|t%r4t&|d|nWYdd}~XnX|j'|| S)aSends 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. NzContent-LengthconnectreadmethodrPbodyrVredirectFassert_same_hostpreload_contentdecode_contentretriestimeout proxy_poolskip_accept_encodingTzutf-8s s0 poolr_r^)(rmrPrTrqrsryrV TimeoutSauceurlopenrxr)hasattrr _get_conn putrequestr; putheader endheadersr"hexlenencode getresponser from_httplibr# _put_connsocketerrorrr _ProxyErrorr _SSLError _HTTPErrorrLrrrrc)rr^streamrrQrRrjrOrPchunkedralow_connheaderr>irsockerrerrr r"&sv           ,      $$zHTTPAdapter.send)r$r%r&r'r9DEFAULT_POOLSIZEDEFAULT_RETRIESDEFAULT_POOLBLOCKrr:r?r0rTrcrmr#rqrsrer"rr)rr r(0s"      % $    r()-r'rmodelsrZpackages.urllib3.poolmanagerrrZpackages.urllib3.responserZpackages.urllib3.utilrrcompatrr r r utilsr r rr structuresrZpackages.urllib3.exceptionsrrrrrrrrr]r exceptionsrauthrrrrobjectrr(rrrr  s* """