ó â\e[c@sdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZddlmZmZmZmZddlmZmZmZdd lmZmZdd lmZdd lmZmZdd l m!Z!m"Z"m#Z#m$Z$dd l%m&Z&ddl'm(Z(ddlm)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0ddlm1Z1ej2dkr¾y ej3Z4Wne5k rºej6Z4nXn ejZ4e d„Z7e d„Z8de9fd„ƒYZ:de:fd„ƒYZ;d„Z<dS(s“ requests.session ~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). iÿÿÿÿN(t timedeltai(t_basic_auth_str(t cookielibtis_py3t OrderedDictturljointurlparsetMapping(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t default_hookst dispatch_hook(tto_native_string(tto_key_val_listtdefault_headers(tTooManyRedirectst InvalidSchematChunkedEncodingErrortContentDecodingError(tCaseInsensitiveDict(t HTTPAdapter(t requote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_urlt rewind_body(tcodes(tREDIRECT_STATItwin32cCs´|dkr|S|dkr |St|tƒo;t|tƒsB|S|t|ƒƒ}|jt|ƒƒg|jƒD]\}}|dkrt|^qt}x|D] }||=qŸW|S(sèDetermines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` N(tNonet isinstanceRRtupdatetitems(trequest_settingtsession_settingt dict_classtmerged_settingtktvt none_keystkey((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt merge_setting1s  1  cCsZ|dks!|jdƒgkr%|S|dksF|jdƒgkrJ|St|||ƒS(s©Properly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. tresponseN(R#tgetR/(t request_hookst session_hooksR)((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt merge_hooksPs !!tSessionRedirectMixincBsGeZd„Zededded„Zd„Zd„Zd„Z RS(cCs?|jr;|jd}tr.|jdƒ}nt|dƒSdS(s7Receives a Response. Returns a redirect URI or ``None``tlocationtlatin1tutf8N(t is_redirecttheadersRtencodeRR#(tselftrespR6((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytget_redirect_targetas    c ks9g} |j|ƒ} t|jƒj} x | r4|jƒ} | j|ƒ| d|_y |jWn-tt t fk r|j j dt ƒnXt|jƒ|jkrÅtd|jd|ƒ‚n|jƒ| jdƒr t|jƒ}dt|jƒ| f} nt| ƒ}|jdkr?| r?|jd| ƒ}n|jrT|j} n|jƒ} |js„t|jt| ƒƒ} n t| ƒ} t| ƒ| _|j| |ƒ|jtjtjfkrd}x!|D]}| jj |dƒq×Wd| _"n| j}y |d =Wnt#k r'nXt$| j%||j ƒt&| j%|j'ƒ| j(| j%ƒ|j)| |ƒ}|j*| |ƒ| j+dk o§d |kp§d |k}|r½t,| ƒn| }|rÑ|Vq*|j-|d |d|d|d|d|dt | }t$|j'| |j ƒ|j|ƒ} |Vq*WdS(sBReceives a Response. Returns a generator of Responses or Requests.itdecode_contentsExceeded %s redirects.R0s//s%s:%sttfragmentsContent-Lengths Content-TypesTransfer-EncodingtCookietstreamttimeouttverifytcerttproxiestallow_redirectsN(sContent-Lengths Content-TypesTransfer-Encoding(.R>RturlRAtcopytappendthistorytcontentRRt RuntimeErrortrawtreadtFalsetlent max_redirectsRtcloset startswithRtschemet_replacetgeturltnetlocRRtrebuild_methodt status_codeR ttemporary_redirecttpermanent_redirectR:tpopR#tbodytKeyErrorR t_cookiesR tcookiestprepare_cookiestrebuild_proxiest rebuild_autht_body_positionRtsend(R<R=treqRCRDRERFRGtyield_requeststadapter_kwargsthistRItprevious_fragmenttprepared_requestt parsed_rurltparsedtpurged_headerstheaderR:t rewindable((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytresolve_redirectsvs|                   cCs–|j}|j}d|kr[t|jjƒ}t|ƒ}|j|jkr[|d=q[n|jrpt|ƒnd}|dk r’|j|ƒndS(séWhen being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. t AuthorizationN( R:RIRtrequestthostnamet trust_envRR#t prepare_auth(R<RmR0R:RItoriginal_parsedtredirect_parsedtnew_auth((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyReçs      c Cs5|dk r|ni}|j}|j}t|ƒj}|jƒ}|jdƒ}t|d|ƒ}|jr¿| r¿t |d|ƒ} | j|| jdƒƒ} | r¿|j || ƒq¿nd|krÕ|d=nyt ||ƒ\} } Wnt k rd\} } nX| r1| r1t | | ƒ|dRQR#tTrueRsReRdRZ(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyR5_s  p  )tSessioncBseZdZddddddddd d d d d g Zd„Zd„Zd„Zd„Zd!d!d!d!d!d!d!e d!d!d!d!d!d!d„Z d„Z d„Z d„Z d!d!d„Zd!d„Zd!d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd „ZRS("s~A Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('http://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: >>> s.get('http://httpbin.org/get') R:RbtauthRGthookstparamsRERFtprefetchtadaptersRCRwRScCs¥tƒ|_d|_i|_tƒ|_i|_t|_ t |_ d|_ t |_t |_tiƒ|_tƒ|_|jdtƒƒ|jdtƒƒdS(Nshttps://shttp://(RR:R#RRGRR‘R’RQRCRŽRERFRRSRwRRbRR”tmountR(R<((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt__init__Xs           cCs|S(N((R<((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt __enter__scGs|jƒdS(N(RT(R<targs((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt__exit__’scCs*|jp i}t|tjƒs0t|ƒ}ntttƒ|jƒ|ƒ}|j}|jrƒ| rƒ|j rƒt |j ƒ}nt ƒ}|j d|j jƒd|j d|jd|jd|jdt|j|jdtƒdt|j|jƒd t||jƒd |d t|j|jƒƒ |S( s‹Constructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest RˆRItfilestdatatjsonR:R)R’RRbR‘(RbR$Rt CookieJarRR R RRwRRIR tprepareRˆtupperRšR›RœR/R:RR’R4R‘(R<RuRbtmerged_cookiesRtp((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytprepare_request•s*        cCsÇtd|jƒd|d|d|d|p-id|d|p?id|d |d | ƒ }|j|ƒ}| poi} |j|j| | ||ƒ}i| d 6| d 6}|j|ƒ|j||}|S( sñConstructs a :class:`Request `, prepares it and sends it. Returns :class:`Response ` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :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 allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :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. Defaults to ``True``. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response RˆRIR:RšR›RœR’RRbR‘RDRH(R RŸR¢tmerge_environment_settingsRIR%Rg(R<RˆRIR’R›R:RbRšRRDRHRGR‘RCRERFRœRhtpreptsettingst send_kwargsR=((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyRu½s*)       cKs#|jdtƒ|jd||S(såSends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RHR†(R~RŽRu(R<RItkwargs((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyR1scKs#|jdtƒ|jd||S(séSends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RHtOPTIONS(R~RŽRu(R<RIR§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytoptionsscKs#|jdtƒ|jd||S(sæSends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RHR…(R~RQRu(R<RIR§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytheadscKs|jd|d|d||S(s¬Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response R‡R›Rœ(Ru(R<RIR›RœR§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytpost%s cKs|jd|d||S(sYSends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPUTR›(Ru(R<RIR›R§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytput1s cKs|jd|d||S(s[Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPATCHR›(Ru(R<RIR›R§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytpatch<s cKs|jd||S(sèSends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tDELETE(Ru(R<RIR§((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytdeleteGsc Ks|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒt|tƒrjtdƒ‚n|jdt ƒ}|j dƒ}|j }|j d|j ƒ}tƒ}|j||}tƒ|} td| ƒ|_td |||}|jr1x-|jD]} t|j| j| jƒq Wnt|j||jƒ|j|||} |r{g| D]} | ^qing} | r¯| jd |ƒ| jƒ}| |_n|sôy(t|j||d t |ƒ|_Wqôtk rðqôXn|s|jn|S( sISend a given PreparedRequest. :rtype: requests.Response RCRERFRGs#You can only send PreparedRequests.RHRItsecondsR0iRi(R~RCRERFRGR$R t ValueErrorR^RŽR1R‘t get_adapterRItpreferred_clockRgRtelapsedRRLR RbRuRORstinserttnextt_nextt StopIterationRM( R<RuR§RHRCR‘tadaptertstarttrR¶R=tgenRL((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyRgQsB     %  (  c Cs|jr«|dk r$|jdƒnd}t|d|ƒ}x*|jƒD]\}} |j|| ƒqIW|tks|dkr«tjjdƒp¢tjjdƒ}q«nt ||j ƒ}t ||j ƒ}t ||j ƒ}t ||j ƒ}i|d6|d6|d6|d6S( s^ Check the environment and merge it with some settings. :rtype: dict R|tREQUESTS_CA_BUNDLEtCURL_CA_BUNDLERERGRCRFN(RwR#R1RR&R~RŽtostenvironR/RGRCRERF( R<RIRGRCRERFR|t env_proxiesR+R,((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyR£šs !cCsSx<|jjƒD]+\}}|jƒj|jƒƒr|SqWtd|ƒ‚dS(s~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter s*No connection adapters were found for '%s'N(R”R&tlowerRUR(R<RItprefixR»((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyR´·scCs(x!|jjƒD]}|jƒqWdS(s+Closes all adapters and as such the sessionN(R”tvaluesRT(R<R,((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyRTÅscCso||j|Ös(tdictt __attrs__(R<tstate((R<s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt __getstate__ÕscCs1x*|jƒD]\}}t|||ƒq WdS(N(R&tsetattr(R<RÍRÊtvalue((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt __setstate__ÙsN(RŒRt__doc__RÌR–R—R™R¢R#RŽRuR1R©RªR«R­R¯R±RgR£R´RTR•RÎRÑ(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyR?s2  7   ) D  I    cCstƒS(sQ Returns a :class:`Session` for context-management. :rtype: Session (R(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pytsessionÞs(=RÒRÁtsysttimetdatetimeRRRtcompatRRRRRRRbRR R R tmodelsR R RR‘RRt_internal_utilsRtutilsRRt exceptionsRRRRt structuresRR”RRRRRRRt status_codesR R!tplatformt perf_counterRµtAttributeErrortclockR/R4tobjectR5RRÓ(((s</tmp/pip-install-0xiv62/pip/pip/_vendor/requests/sessions.pyt s:   ."".     àÿ