3 ”Reß'ã@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&tjdj|ƒtd�t|ƒ}t|tƒsPtjdjt|ƒƒtd�t|ƒ}t|tƒrd|jdƒ}t|tƒrx|jdƒ}dt t dj ||fƒƒj ƒƒ}|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ÚtypeÚencoderrÚjoinÚstrip)ÚusernameÚpasswordÚauthstr©rúˆ/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/requests/auth.pyÚ_basic_auth_strs&      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__r rrrrrHsrc@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__VszHTTPBasicAuth.__eq__cCs ||k S)Nr)rr)rrrÚ__ne__\szHTTPBasicAuth.__ne__cCst|j|jƒ|jd<|S)NÚ Authorization)rrrÚheaders)rrrrrr _szHTTPBasicAuth.__call__N)r!r"r#r$r&r*r+r rrrrr%Os r%c@seZdZdZdd„ZdS)Ú HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|jƒ|jd<|S)NzProxy-Authorization)rrrr-)rrrrrr gszHTTPProxyAuth.__call__N)r!r"r#r$r rrrrr.dsr.c@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||_||_tjƒ|_dS)N)rrÚ threadingÚlocalÚ _thread_local)rrrrrrr&oszHTTPDigestAuth.__init__cCs@t|jdƒs.md5_utf8ÚSHAcSs"t|tƒr|jdƒ}tj|ƒjƒS)Nzutf-8)r rrrBÚsha1rD)rErrrÚsha_utf8—s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tƒr|jdƒ}tj|ƒjƒS)Nzutf-8)r rrrBÚsha256rD)rErrrÚ sha256_utf8�s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tƒr|jdƒ}tj|ƒjƒS)Nzutf-8)r rrrBÚsha512rD)rErrrÚ sha512_utf8£s  z7HTTPDigestAuth.build_digest_header..sha512_utf8csˆd||fƒS)Nz%s:%sr)ÚsÚd)Ú hash_utf8rrÚ©sz4HTTPDigestAuth.build_digest_header..ú/ú?z%s:%s:%sz%s:%srz%08xzutf-8ééÚauthú,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)r2r8ÚgetÚupperrÚpathÚqueryrrr6r7rrÚtimeÚctimeÚosÚurandomrBrHrDÚsplit)rÚmethodÚurlr<r=r>r?r@Ú _algorithmrFrIrKrMÚKDÚentdigÚp_parsedrZÚA1ÚA2ÚHA1ÚHA2ÚncvaluerNÚcnonceÚrespdigÚnoncebitÚbaser)rPrÚbuild_digest_headers~           z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN)Ú is_redirectr2r:)rrÚkwargsrrrÚhandle_redirectåszHTTPDigestAuth.handle_redirectcKs"d|jkodkns&d|j_|S|jjdk rD|jjj|jjƒ|jjddƒ}d|j ƒkoh|jjdk�r|jjd7_t j d t j d �}t |jd|dd �ƒ|j_|j|jƒ|jjƒ}t|j|j|jƒ|j|jƒ|j|j|jƒ|jd <|jj|f|Ž}|jj|ƒ||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response i�iôrNzwww-authenticater4Údigestézdigest )Úflags)Úcountr,)Ú status_coder2r:r9ÚrequestÚbodyÚseekr-rXÚlowerÚreÚcompileÚ IGNORECASEr Úsubr8ÚcontentÚcloseÚcopyrÚ_cookiesÚrawÚprepare_cookiesrprarbÚ connectionÚsendÚhistoryÚappend)rrrrÚs_authÚpatÚprepÚ_rrrrÚ handle_401ês.     zHTTPDigestAuth.handle_401c Cs~|jƒ|jjr&|j|j|jƒ|jd<y|jjƒ|j_ Wnt k rTd|j_ YnX|j d|j ƒ|j d|j ƒd|j_|S)Nr,Úresponser)r;r2r6rprarbr-rzÚtellr9ÚAttributeErrorÚ register_hookr�rsr:)rrrrrr szHTTPDigestAuth.__call__cCs(t|jt|ddƒk|jt|ddƒkgƒS)Nrr)r'rr(r)rr)rrrr**szHTTPDigestAuth.__eq__cCs ||k S)Nr)rr)rrrr+0szHTTPDigestAuth.__ne__N) r!r"r#r$r&r;rprsr�r r*r+rrrrr/ls f,r/)r$r^r}r\rBr0rÚbase64rÚcompatrrrÚcookiesrÚ_internal_utilsrÚutilsr ÚCONTENT_TYPE_FORM_URLENCODEDÚCONTENT_TYPE_MULTI_PARTrÚobjectrr%r.r/rrrrÚs$    ,