ó YÐ…_c@sÆdZddlZddlmZddlmZmZddlmZddl m Z ddl m Z dd lmZmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z#ddlm$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m"Z"mZm+Z+ddl,m-Z-e.Z/dZ0dZ1de2fd„ƒYZ3de3fd„ƒYZ4dS(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 urldefragauth(tCaseInsensitiveDict(tConnectTimeoutError(t HTTPError(t MaxRetryError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(t ResponseError(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutRRt RetryError(t_basic_auth_stri it BaseAdaptercBs)eZdZd„Zd„Zd„ZRS(sThe Base Transport AdaptercCstt|ƒjƒdS(N(tsuperRt__init__(tself((s5/usr/lib/python2.7/site-packages/requests/adapters.pyR+scCs t‚dS(N(tNotImplementedError(R((s5/usr/lib/python2.7/site-packages/requests/adapters.pytsend.scCs t‚dS(N(R (R((s5/usr/lib/python2.7/site-packages/requests/adapters.pytclose1s(t__name__t __module__t__doc__RR!R"(((s5/usr/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 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_RETRIESRtFalseR'tfrom_intR(t proxy_managerRR&RR)R*R+tinit_poolmanager(Rtpool_connectionst pool_maxsizeR't pool_block((s5/usr/lib/python2.7/site-packages/requests/adapters.pyRRs      cst‡fd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrtNone(t.0tattr(R(s5/usr/lib/python2.7/site-packages/requests/adapters.pys es(tdictt __attrs__(R((Rs5/usr/lib/python2.7/site-packages/requests/adapters.pyt __getstate__dscCsbi|_i|_x*|jƒD]\}}t|||ƒqW|j|j|jd|jƒdS(NR-(R1R(titemstsetattrR2R)R*R+(RtstateR9tvalue((s5/usr/lib/python2.7/site-packages/requests/adapters.pyt __setstate__hs   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+RtTruet poolmanager(Rt connectionsRCR-t pool_kwargs((s5/usr/lib/python2.7/site-packages/requests/adapters.pyR2ts   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_headersRBRCR-(R1RIRR)R*R+(Rtproxyt proxy_kwargsRI((s5/usr/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 startswithR7RERt Exceptiont cert_reqstca_certst isinstanceRt cert_filetkey_file(Rtconnturltverifytcerttcert_loc((s5/usr/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(RR6R7t status_codeR R_R tencodingtrawtreasonRURYtbytestdecodeRtcookiestrequestt connection(Rtreqtresptresponse((s5/usr/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( tgetRRPtschemeR RLtconnection_from_urltgeturlRF(RRYtproxiesRJR1RXtparsed((s5/usr/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(RFtclear(R((s5/usr/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. RM(RRYRoRnR tpath_url(RRgRrRoRJRY((s5/usr/lib/python2.7/site-packages/requests/adapters.pyt request_urls  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((RRgtkwargs((s5/usr/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(RRJR_tusernametpassword((s5/usr/lib/python2.7/site-packages/requests/adapters.pyRI-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ª| sI|j d|jd|d|jd|jd td td td td |jd|ƒ }nIt|dƒrd|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 r5} t| j't(ƒrùt)| d|ƒ‚nt| j't*ƒr t+| d|ƒ‚nt%| d|ƒ‚n‚t,k rS} t-| ƒ‚ndt.t/fk r¶} t| t.ƒrŒt0| d|ƒ‚q·t| t1ƒr°t2| d|ƒ‚q·‚nX|j3||ƒ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-LengthtconnectR,ssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRYtbodyR_tredirecttassert_same_hosttpreload_contenttdecode_contenttretriesttimeoutt proxy_pooltskip_accept_encodingisutf-8s s0 tpoolRhRgN(4RtRYR]RwRyR~R7R_RUttuplet TimeoutSaucet ValueErrortformatturlopenR}R/R'thasattrR…t _get_connt putrequestRER=t putheadert endheadersR!thextlentencodet getresponseRt from_httplibR"t _put_connRtsocketterrorRRRcRRRRt _ProxyErrorRt _SSLErrort _HTTPErrorRRRRl(RRgtstreamR„RZR[RrRXRYtchunkedR|R,teterrRjtlow_conntheaderR@titr((s5/usr/lib/python2.7/site-packages/requests/adapters.pyR!CsŽ            &      N(R#R$R%R;tDEFAULT_POOLSIZER.tDEFAULT_POOLBLOCKRR<RAR2RLR]RlR7RtR"RwRyRIR/RER!(((s5/usr/lib/python2.7/site-packages/requests/adapters.pyR&5s$       % $     (5R%R˜tmodelsRturllib3.poolmanagerRRturllib3.responseRt urllib3.utilRR‰turllib3.util.retryRtcompatRRtutilsRR R R R t structuresR turllib3.exceptionsRRRœRRRšRRRR›RRfRt exceptionsRRRRtauthRR/R¦R¥R.tobjectRR&(((s5/usr/lib/python2.7/site-packages/requests/adapters.pyt s2 (.