ó b@RTc@s°dZddlZddlmZddlmZddlmZmZddl m Z ddl m Z dd lmZmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)m"Z"mZddl*m+Z+e,Z-dZ.dZ/de0fd„ƒYZ1de1fd„ƒYZ2dS(s‰ requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iÿÿÿÿNi(tResponse(tRetry(t PoolManagertproxy_from_url(t HTTPResponse(tTimeout(turlparset basestring(tDEFAULT_CA_BUNDLE_PATHtget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt urldefragauth(tCaseInsensitiveDict(tConnectTimeoutError(t HTTPError(t MaxRetryError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutRR(t_basic_auth_stri it BaseAdaptercBs)eZdZd„Zd„Zd„ZRS(sThe Base Transport AdaptercCstt|ƒjƒdS(N(tsuperRt__init__(tself((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR*scCs t‚dS(N(tNotImplementedError(R((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pytsend-scCs t‚dS(N(R(R((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pytclose0s(t__name__t __module__t__doc__RRR (((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR's  t HTTPAdaptercBs¹eZdZdddddgZeeeed„Zd„Zd„Z ed „Z d „Z d „Z d „Z dd „Zd„Zd„Zd„Zd„Zededdd„ZRS(s’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) t max_retriestconfigt_pool_connectionst _pool_maxsizet _pool_blockcCsc||_i|_i|_tt|ƒjƒ||_||_||_|j ||d|ƒdS(Ntblock( R%R&t proxy_managerRR$RR'R(R)tinit_poolmanager(Rtpool_connectionst pool_maxsizeR%t pool_block((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyRMs      cst‡fd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrtNone(t.0tattr(R(s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pys ]s(tdictt __attrs__(R((Rs>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyt __getstate__\scCsbi|_i|_x*|jƒD]\}}t|||ƒqW|j|j|jd|jƒdS(NR*(R+R&titemstsetattrR,R'R(R)(RtstateR3tvalue((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyt __setstate__`s   cKs@||_||_||_td|d|d|||_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*N(R'R(R)Rt poolmanager(Rt connectionsR=R*t pool_kwargs((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR,ls   c Ksc||jkrX|j|ƒ}t|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 t proxy_headersR<R=R*(R+RARR'R(R)(Rtproxyt proxy_kwargsRA((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pytproxy_manager_for€s   cCsÃ|jƒjdƒro|rod}|tk r6|}n|sEt}n|sZtdƒ‚nd|_||_nd|_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( tlowert startswithR1tTrueRt Exceptiont cert_reqstca_certst isinstanceRt cert_filetkey_file(Rtconnturltverifytcerttcert_loc((s>/opt/freeware/lib/python2.7/site-packages/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. tstatustheaderssutf-8N(RR0R1t status_codeR RXR tencodingtrawtreasonRNRRtbytestdecodeRtcookiestrequestt connection(Rtreqtresptresponse((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pytbuild_response¼s     cCsŽ|p i}|jt|jƒƒjƒ}|r`t|dƒ}|j|ƒ}|j|ƒ}n*t|ƒ}|jƒ}|jj|ƒ}|S(seReturns 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. thttp( tgetRRHtschemeR RDtconnection_from_urltgeturlR>(RRRtproxiesRBR+RQtparsed((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pytget_connectionàs   cCs|jjƒdS(s‡Disposes of any internal state. Currently, this just closes the PoolManager, which closes pooled connections. N(R>tclear(R((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR ÷scCs^|p i}t|jƒj}|j|ƒ}|rQ|dkrQt|jƒ}n |j}|S(sObtain 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. RE(RRRRhRgR tpath_url(RR`RkRhRBRR((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyt request_urlÿs  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((RR`tkwargs((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyt add_headerss cCs>i}t|ƒ\}}|r:|r:t||ƒ|d`. :param proxies: The url of the proxy being used for this request. :param kwargs: Optional additional keyword arguments. sProxy-Authorization(R R(RRBRXtusernametpassword((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyRA%s  cCs¬|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¶| sU|j d|jd|d|jd|jd td td td td t|jdtƒd|ƒ }nIt|dƒrp|j}n|jd|ƒ}yø|j|j|dtƒx-|jjƒD]\}}|j||ƒq®W|jƒx^|jD]S}|jtt|ƒƒdjdƒƒ|jdƒ|j|ƒ|jdƒqâW|jdƒ|jƒ}tj |d|d|d td tƒ}Wn|j!ƒ‚nX|j"|ƒWnút#t$j%fk rÏ} t&| d|ƒ‚nÍt'k r} t| j(t)ƒrt*| d|ƒ‚nt&| d|ƒ‚n‚t+k r8} t,| ƒ‚ndt-t.fk r›} t| t-ƒrqt/| d|ƒ‚qœt| t0ƒr•t1| d|ƒ‚qœ‚nX|j2||ƒ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 (`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. sContent-LengthtconnecttreadssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRRtbodyRXtredirecttassert_same_hosttpreload_contenttdecode_contenttretriesttimeoutt proxy_pooltskip_accept_encodingisutf-8s s0 tpoolRaR`N(3RmRRRVRpRrRxR1RXRNttuplet TimeoutSaucet ValueErrortformatturlopenRwtFalseRR%thasattrRt _get_connt putrequestRJR7t putheadert endheadersRthextlentencodet getresponseRt from_httplibR t _put_connRtsocketterrorRRR\RRt _ProxyErrorRt _SSLErrort _HTTPErrorRRRRe(RR`tstreamR~RSRTRkRQRRtchunkedRuRvteterrRctlow_conntheaderR:titr((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR;sŠ           &      N(R!R"R#R5tDEFAULT_POOLSIZEtDEFAULT_RETRIEStDEFAULT_POOLBLOCKRR6R;R,RDRVReR1RmR RpRrRAR‡RJR(((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyR$4s$      % $     (3R#R“tmodelsRtpackages.urllib3Rtpackages.urllib3.poolmanagerRRtpackages.urllib3.responseRtpackages.urllib3.utilRRƒtcompatRRtutilsRR R R R t structuresR tpackages.urllib3.exceptionsRRR—RRR•RRRR–R_Rt exceptionsRRRtauthRR‡R¢R R¡tobjectRR$(((s>/opt/freeware/lib/python2.7/site-packages/requests/adapters.pyt s0 ((