Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
wiperf / usr / local / lib / python3.7 / dist-packages / requests / __pycache__ / sessions.cpython-37.pyc
Size: Mime:
B

òßÑ@¨‰©ã@s dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZddlmZmZmZmZdd	lmZmZmZdd
lmZmZddlmZddlmZm Z m!Z!dd
l"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddlm+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4dkrVy
ej5Z6Wne7k
rRej8Z6YnXnejZ6efdd„Z9efdd„Z:Gdd„de;ƒZ<Gdd„de<ƒZ=dd„Z>dS)z“
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
éN)Ú	timedelta)ÚOrderedDicté)Ú_basic_auth_str)Ú	cookielibÚis_py3ÚurljoinÚurlparseÚMapping)Úcookiejar_from_dictÚextract_cookies_to_jarÚRequestsCookieJarÚ
merge_cookies)ÚRequestÚPreparedRequestÚDEFAULT_REDIRECT_LIMIT)Ú
default_hooksÚ
dispatch_hook)Úto_native_string)Úto_key_val_listÚdefault_headersÚ
DEFAULT_PORTS)ÚTooManyRedirectsÚ
InvalidSchemaÚChunkedEncodingErrorÚContentDecodingError)ÚCaseInsensitiveDict)ÚHTTPAdapter)Úrequote_uriÚget_environ_proxiesÚget_netrc_authÚshould_bypass_proxiesÚget_auth_from_urlÚrewind_body)Úcodes)ÚREDIRECT_STATIÚwin32cCst|dkr|S|dkr|St|tƒr,t|tƒs0|S|t|ƒƒ}| t|ƒ¡dd„| ¡Dƒ}x|D]
}||=qbW|S)zè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`
    NcSsg|]\}}|dkr|‘qS)N©)Ú.0ÚkÚvr'r'ú7/tmp/pip-install-z4i6eiy2/requests/requests/sessions.pyú
<listcomp>Jsz!merge_setting.<locals>.<listcomp>)Ú
isinstancer
rÚupdateÚitems)Úrequest_settingÚsession_settingÚ
dict_classÚmerged_settingÚ	none_keysÚkeyr'r'r+Ú
merge_setting2s



r6cCs@|dks| d¡gkr|S|dks0| d¡gkr4|St|||ƒS)z©Properly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    NÚresponse)Úgetr6)Ú
request_hooksÚ
session_hooksr2r'r'r+Úmerge_hooksQs
r;c@s>eZdZdd„Zdd„Zddd	„Zd
d„Zdd
„Zdd„ZdS)ÚSessionRedirectMixincCs,|jr(|jd}tr| d¡}t|dƒSdS)z7Receives a Response. Returns a redirect URI or ``None``ÚlocationÚlatin1Úutf8N)Úis_redirectÚheadersrÚencoder)ÚselfÚrespr=r'r'r+Úget_redirect_targetbs


z(SessionRedirectMixin.get_redirect_targetcCsšt|ƒ}t|ƒ}|j|jkr dS|jdkrL|jdkrL|jdkrL|jdkrLdS|j|jk}|j|jk}t |jd¡df}|s’|j|kr’|j|kr’dS|p˜|S)zFDecide whether Authorization header should be removed when redirectingTÚhttp)éPNÚhttps)i»NFN)r	ÚhostnameÚschemeÚportrr8)rCÚold_urlÚnew_urlÚ
old_parsedÚ
new_parsedÚchanged_portÚchanged_schemeÚdefault_portr'r'r+Úshould_strip_authws
z&SessionRedirectMixin.should_strip_authFNTc	
ksRg}
| |¡}t|jƒj}x0|rL| ¡}
|
 |¡|
dd…|_y
|jWn(tt	t
fk
rv|jjddYnXt
|jƒ|jkrœtd |j¡|d‚| ¡| d¡rÌt|jƒ}d t|jƒ|g¡}t|ƒ}|jd	krð|rð|j|d
}n|jrü|j}| ¡}|jst|jt|ƒƒ}nt|ƒ}t|ƒ|
_| |
|¡|jtjtjfkrxd}x|D]}|
j  !|d¡qZWd|
_"|
j }| !dd¡t#|
j$||jƒt%|
j$|j&ƒ|
 '|
j$¡| (|
|¡}| )|
|¡|
j*dk	oèd
|kpèd|k}|røt+|
ƒ|
}|r
|Vq|j,|f|||||ddœ|	—Ž}t#|j&|
|jƒ| |¡}|VqWdS)zBReceives a Response. Returns a generator of Responses or Requests.rNF)Údecode_contentzExceeded {} redirects.)r7z//ú:Ú)Úfragment)zContent-LengthzContent-TypezTransfer-EncodingÚCookiezContent-LengthzTransfer-Encoding)ÚstreamÚtimeoutÚverifyÚcertÚproxiesÚallow_redirects)-rEr	ÚurlrWÚcopyÚappendÚhistoryÚcontentrrÚRuntimeErrorÚrawÚreadÚlenÚ
max_redirectsrÚformatÚcloseÚ
startswithÚjoinrrJÚ_replaceÚgeturlÚnetlocrrÚrebuild_methodÚstatus_coder$Útemporary_redirectÚpermanent_redirectrAÚpopÚbodyrÚ_cookiesrÚcookiesÚprepare_cookiesÚrebuild_proxiesÚrebuild_authÚ_body_positionr#Úsend)rCrDÚreqrYrZr[r\r]Úyield_requestsÚadapter_kwargsÚhistr_Úprevious_fragmentÚprepared_requestÚparsed_rurlÚparsedÚpurged_headersÚheaderrAÚ
rewindabler'r'r+Úresolve_redirectssv








z&SessionRedirectMixin.resolve_redirectscCsR|j}|j}d|kr*| |jj|¡r*|d=|jr8t|ƒnd}|dk	rN| |¡dS)zé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.
        Ú
AuthorizationN)rAr_rSÚrequestÚ	trust_envr Úprepare_auth)rCr‚r7rAr_Únew_authr'r'r+rzþsz!SessionRedirectMixin.rebuild_authc
CsÖ|dk	r|ni}|j}|j}t|ƒj}| ¡}| d¡}t||d}|jr||s|t||d}	|	 ||	 d¡¡}
|
r|| 	||
¡d|krŠ|d=yt
||ƒ\}}Wntk
rºd\}}YnX|rÒ|rÒt||ƒ|d<|S)a°This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).

        This method also replaces the Proxy-Authorization header where
        necessary.

        :rtype: dict
        NÚno_proxy)rŽÚallzProxy-Authorization)NN)
rAr_r	rJr`r8r!r‹rÚ
setdefaultr"ÚKeyErrorr)
rCr‚r]rAr_rJÚnew_proxiesrŽÚbypass_proxyÚenviron_proxiesÚproxyÚusernameÚpasswordr'r'r+rys*


z$SessionRedirectMixin.rebuild_proxiescCsX|j}|jtjkr|dkrd}|jtjkr6|dkr6d}|jtjkrN|dkrNd}||_dS)z‚When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        ÚHEADÚGETÚPOSTN)Úmethodrqr$Ú	see_otherÚfoundÚmoved)rCr‚r7r›r'r'r+rp:sz#SessionRedirectMixin.rebuild_method)FNTNNF)	Ú__name__Ú
__module__Ú__qualname__rErSrˆrzryrpr'r'r'r+r<`s
m)r<c@sÌeZdZdZdddddddd	d
ddd
gZdd„Zdd„Zdd„Zdd„Zd6dd„Z	dd„Z
dd„Zdd„Zd7d d!„Z
d8d"d#„Zd9d$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„ZdS):ÚSessiona€A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> s.get('https://httpbin.org/get')
      <Response [200]>

    Or as a context manager::

      >>> with requests.Session() as s:
      ...     s.get('https://httpbin.org/get')
      <Response [200]>
    rArwÚauthr]ÚhooksÚparamsr[r\ÚadaptersrYr‹rhcCsrtƒ|_d|_i|_tƒ|_i|_d|_d|_d|_	t
|_d|_t
iƒ|_tƒ|_| dtƒ¡| dtƒ¡dS)NFTzhttps://zhttp://)rrAr£r]rr¤r¥rYr[r\rrhr‹rrwrr¦Úmountr)rCr'r'r+Ú__init__js
zSession.__init__cCs|S)Nr')rCr'r'r+Ú	__enter__¡szSession.__enter__cGs| ¡dS)N)rj)rCÚargsr'r'r+Ú__exit__¤szSession.__exit__c
Cs²|jpi}t|tjƒst|ƒ}tttƒ|jƒ|ƒ}|j}|jrR|sR|jsRt	|j
ƒ}tƒ}|j|j
 ¡|j
|j|j|jt|j|jtdt|j|jƒt||jƒ|t|j|jƒd
|S)a‹Constructs a :class:`PreparedRequest <PreparedRequest>` for
        transmission and returns it. The :class:`PreparedRequest` has settings
        merged from the :class:`Request <Request>` instance and those of the
        :class:`Session`.

        :param request: :class:`Request` instance to prepare with this
            session's settings.
        :rtype: requests.PreparedRequest
        )r2)
r›r_ÚfilesÚdataÚjsonrAr¥r£rwr¤)rwr-rÚ	CookieJarrrr
r£r‹r r_rÚpreparer›Úupperr¬r­r®r6rArr¥r;r¤)rCrŠrwÚmerged_cookiesr£Úpr'r'r+Úprepare_request§s*



zSession.prepare_requestNTcCstt| ¡||||pi||pi|||d
}| |¡}|p8i}| |j||
||¡}|	|
dœ}| |¡|j|f|Ž}|S)aConstructs a :class:`Request <Request>`, prepares it and sends it.
        Returns :class:`Response <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, list of tuples, 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) <timeouts>` 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›r_rAr¬r­r®r¥r£rwr¤)rZr^)rr±r´Úmerge_environment_settingsr_r.r|)rCr›r_r¥r­rArwr¬r£rZr^r]r¤rYr[r\r®r}ÚprepÚsettingsÚsend_kwargsrDr'r'r+rŠÏs()

zSession.requestcKs| dd¡|jd|f|ŽS)zå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
        r^Tr™)rrŠ)rCr_Úkwargsr'r'r+r8szSession.getcKs| dd¡|jd|f|ŽS)zé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
        r^TÚOPTIONS)rrŠ)rCr_r¹r'r'r+Úoptions!szSession.optionscKs| dd¡|jd|f|ŽS)zæ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
        r^Fr˜)rrŠ)rCr_r¹r'r'r+Úhead,szSession.headcKs|jd|f||dœ|—ŽS)aÈSends a POST request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, 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®)rŠ)rCr_r­r®r¹r'r'r+Úpost7szSession.postcKs|jd|fd|i|—ŽS)auSends a PUT request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        ÚPUTr­)rŠ)rCr_r­r¹r'r'r+ÚputDs
zSession.putcKs|jd|fd|i|—ŽS)awSends a PATCH request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        ÚPATCHr­)rŠ)rCr_r­r¹r'r'r+ÚpatchPs
z
Session.patchcKs|jd|f|ŽS)zè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
        ÚDELETE)rŠ)rCr_r¹r'r'r+Údelete\szSession.deletec
Ks€| d|j¡| d|j¡| d|j¡| d|j¡t|tƒrJtdƒ‚| dd¡}| 	d¡}|j
}|j|jd}t
ƒ}|j|f|Ž}t
ƒ|}	t|	d	|_td
||f|Ž}|jrÖx |jD]}
t|j|
j|
jƒq¼Wt|j||jƒ|r|j||f|Ž}dd„|Dƒ}ng}|r0| d
|¡| ¡}||_|spy"t|j||fddi|—Žƒ|_Wntk
rnYnX|s||j|S)zISend a given PreparedRequest.

        :rtype: requests.Response
        rYr[r\r]z#You can only send PreparedRequests.r^T)r_)Úsecondsr7cSsg|]}|‘qSr'r')r(rDr'r'r+r,™sz Session.send.<locals>.<listcomp>rr~)rrYr[r\r]r-rÚ
ValueErrorrtr8r¤Úget_adapterr_Úpreferred_clockr|rÚelapsedrrbrrwrŠrerˆÚinsertÚnextÚ_nextÚ
StopIterationrc)
rCrŠr¹r^rYr¤ÚadapterÚstartÚrrÈrDÚgenrbr'r'r+r|fsF


"zSession.sendc
Cs°|jrr|dk	r| d¡nd}t||d}x | ¡D]\}}	| ||	¡q2W|dksZ|dkrrtj d¡pptj d¡}t||jƒ}t||j	ƒ}t||j
ƒ}t||jƒ}||||dœS)z^
        Check the environment and merge it with some settings.

        :rtype: dict
        NrŽ)rŽTÚREQUESTS_CA_BUNDLEÚCURL_CA_BUNDLE)r[r]rYr\)r‹r8rr/rÚosÚenvironr6r]rYr[r\)
rCr_r]rYr[r\rŽÚenv_proxiesr)r*r'r'r+rµ±sz"Session.merge_environment_settingscCs@x,|j ¡D]\}}| ¡ | ¡¡r|SqWtd |¡ƒ‚dS)z~
        Returns the appropriate connection adapter for the given URL.

        :rtype: requests.adapters.BaseAdapter
        z*No connection adapters were found for {!r}N)r¦r/Úlowerrkrri)rCr_ÚprefixrÍr'r'r+rÆÎszSession.get_adaptercCs x|j ¡D]}| ¡qWdS)z+Closes all adapters and as such the sessionN)r¦Úvaluesrj)rCr*r'r'r+rjÜsz
Session.closecsB||jˆ<‡fdd„|jDƒ}x|D]}|j |¡|j|<q$WdS)zwRegisters a connection adapter to a prefix.

        Adapters are sorted in descending order by prefix length.
        cs g|]}t|ƒtˆƒkr|‘qSr')rg)r(r))r×r'r+r,çsz!Session.mount.<locals>.<listcomp>N)r¦rt)rCr×rÍÚkeys_to_mover5r')r×r+r§ás

z
Session.mountcs‡fdd„ˆjDƒ}|S)Ncsi|]}tˆ|dƒ|“qS)N)Úgetattr)r(Úattr)rCr'r+ú
<dictcomp>ísz(Session.__getstate__.<locals>.<dictcomp>)Ú	__attrs__)rCÚstater')rCr+Ú__getstate__ìszSession.__getstate__cCs&x | ¡D]\}}t|||ƒq
WdS)N)r/Úsetattr)rCrÞrÛÚvaluer'r'r+Ú__setstate__ðszSession.__setstate__)NNNNNNNTNNNNNN)NN)N)N)rŸr r¡Ú__doc__rÝr¨r©r«r´rŠr8r»r¼r½r¿rÁrÃr|rµrÆrjr§rßrâr'r'r'r+r¢Qs27)
D



Kr¢cCstƒS)aZ
    Returns a :class:`Session` for context-management.

    .. deprecated:: 1.0.0

        This method has been deprecated since version 1.0.0 and is only kept for
        backwards compatibility. New code should use :class:`~requests.sessions.Session`
        to create a session. This may be removed at a future date.

    :rtype: Session
    )r¢r'r'r'r+Úsessionõsrä)?rãrÓÚsysÚtimeÚdatetimerÚcollectionsrr£rÚcompatrrrr	r
rwrrr
rÚmodelsrrrr¤rrÚ_internal_utilsrÚutilsrrrÚ
exceptionsrrrrÚ
structuresrr¦rrrr r!r"r#Ústatus_codesr$r%ÚplatformÚperf_counterrÇÚAttributeErrorÚclockr6r;Úobjectr<r¢rär'r'r'r+Ú<module>	sB 
r'