U ÀÒ.eÞ'ã@sÌdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd d „ZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. éN)Ú b64encodeé)ÚurlparseÚstrÚ basestring)Úextract_cookies_to_jar)Úto_native_string)Úparse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datacCs–t|tƒs&tjd |¡td�t|ƒ}t|tƒsLtjd |¡td�t|ƒ}t|tƒr`| d¡}t|tƒrt| d¡}dtt d  ||f¡ƒ  ¡ƒ}|S)zReturns a Basic Auth string.z·Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({!r}) to a string or bytes object in the near future to avoid problems.)Úcategoryz·Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({!r}) to a string or bytes object in the near future to avoid problems.Úlatin1zBasic ó:) Ú isinstancerÚwarningsÚwarnÚformatÚDeprecationWarningrÚencoderrÚjoinÚstrip)ÚusernameÚpasswordZauthstr©rú=/usr/lib/python3.8/site-packages/pip/_vendor/requests/auth.pyÚ_basic_auth_strs0 ýû ýû    ÿrc@seZdZdZdd„ZdS)ÚAuthBasez4Base class that all auth implementations derive fromcCs tdƒ‚dS)NzAuth hooks must be callable.)ÚNotImplementedError©ÚselfÚrrrrÚ__call__KszAuthBase.__call__N©Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrHsrc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS©N)rr©rrrrrrÚ__init__RszHTTPBasicAuth.__init__cCs(t|jt|ddƒk|jt|ddƒkgƒS©Nrr©ÚallrÚgetattrr©rÚotherrrrÚ__eq__VsþzHTTPBasicAuth.__eq__cCs ||k Sr&rr-rrrÚ__ne__\szHTTPBasicAuth.__ne__cCst|j|jƒ|jd<|S)NÚ Authorization©rrrÚheadersrrrrr_szHTTPBasicAuth.__call__N)r!r"r#r$r(r/r0rrrrrr%Os r%c@seZdZdZdd„ZdS)Ú HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|jƒ|jd<|S)NzProxy-Authorizationr2rrrrrgszHTTPProxyAuth.__call__Nr rrrrr4dsr4c@sPeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dS)ÚHTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_t ¡|_dSr&)rrÚ threadingZlocalÚ _thread_localr'rrrr(oszHTTPDigestAuth.__init__cCs@t|jdƒs.md5_utf8ZSHAcSs"t|tƒr| d¡}t |¡ ¡SrF)r rrrHÚsha1rIrJrrrÚsha_utf8—s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tƒr| d¡}t |¡ ¡SrF)r rrrHZsha256rIrJrrrÚ sha256_utf8�s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tƒr| d¡}t |¡ ¡SrF)r rrrHZsha512rIrJrrrÚ sha512_utf8£s  z7HTTPDigestAuth.build_digest_header..sha512_utf8csˆd||fƒS)Nú%s:%sr)ÚsÚd©Z hash_utf8rrÚ©óz4HTTPDigestAuth.build_digest_header..ú/ú?z%s:%s:%srQrz%08xrGééZauthú,z%s:%s:%s:%s:%sz>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z , opaque="%s"z, algorithm="%s"z , digest="%s"z , qop="auth", nc=%s, cnonce="%s"z Digest %s)r7r=ÚgetÚupperrÚpathZqueryrrr;r<rrÚtimeÚctimeÚosÚurandomrHrMrIÚsplit)rÚmethodÚurlrArBrCrDrEZ _algorithmrLrNrOrPZKDZentdigZp_parsedr^ZA1ZA2ZHA1ZHA2ZncvaluerRZcnonceZrespdigZnoncebitÚbaserrTrÚbuild_digest_headersŠ       ÿ ÿ   z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN)Z is_redirectr7r?)rrÚkwargsrrrÚhandle_redirectåszHTTPDigestAuth.handle_redirectcKs"d|jkrdks$nd|j_|S|jjdk rB|jj |jj¡|j dd¡}d|  ¡k�r|jjdk�r|jjd7_t j d t j d �}t |jd|dd �ƒ|j_|j| ¡|j ¡}t|j|j|jƒ| |j¡| |j|j¡|jd <|jj|f|Ž}|j |¡||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response i�iôrNzwww-authenticater9Zdigestézdigest )Úflags)Úcountr1)Z status_coder7r?r>ZrequestÚbodyÚseekr3r\ÚlowerÚreÚcompileÚ IGNORECASEr Úsubr=ZcontentÚcloseÚcopyrZ_cookiesÚrawZprepare_cookiesrgrdreZ connectionÚsendÚhistoryÚappend)rrrhZs_authZpatZprepZ_rrrrÚ handle_401ês2    ÿ  zHTTPDigestAuth.handle_401cCs~| ¡|jjr&| |j|j¡|jd<z|j ¡|j_ Wnt k rTd|j_ YnX|  d|j ¡|  d|j ¡d|j_|S)Nr1Zresponser)r@r7r;rgrdrer3rmÚtellr>ÚAttributeErrorZ register_hookrzrir?rrrrrszHTTPDigestAuth.__call__cCs(t|jt|ddƒk|jt|ddƒkgƒSr)r*r-rrrr/*sþzHTTPDigestAuth.__eq__cCs ||k Sr&rr-rrrr00szHTTPDigestAuth.__ne__N) r!r"r#r$r(r@rgrirzrr/r0rrrrr5ls f,r5)r$rarpr_rHr6rÚbase64rÚcompatrrrZcookiesrZ_internal_utilsrZutilsr ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTrÚobjectrr%r4r5rrrrÚs$    ,