o Ec'@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd d ZGd ddeZGdddeZGdddeZGdddeZdS)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. N) b64encode)urlparsestr basestring)extract_cookies_to_jar)to_native_string)parse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datacCst|tstjd|tdt|}t|ts(tjdt|tdt|}t|tr2|d}t|tr<|d}dt t d ||f }|S)zReturns a Basic Auth string.zNon-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.)categoryzNon-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 :) isinstancerwarningswarnformatDeprecationWarningrtypeencoderrjoinstrip)usernamepasswordZauthstrrL/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/requests/auth.py_basic_auth_strs,       rc@eZdZdZddZdS)AuthBasez4Base class that all auth implementations derive fromcCstd)NzAuth hooks must be callable.)NotImplementedErrorselfrrrr__call__KszAuthBase.__call__N__name__ __module__ __qualname____doc__r!rrrrrH rc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dSN)rrrrrrrr__init__Rs zHTTPBasicAuth.__init__cC(t|jt|ddk|jt|ddkgSNrrallrgetattrrrotherrrr__eq__VzHTTPBasicAuth.__eq__cC ||k Sr)rr1rrr__ne__\ zHTTPBasicAuth.__ne__cCt|j|j|jd<|S)N Authorizationrrrheadersrrrrr!_zHTTPBasicAuth.__call__N)r#r$r%r&r+r3r6r!rrrrr(Os  r(c@r) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCr8)NzProxy-Authorizationr:rrrrr!gr<zHTTPProxyAuth.__call__Nr"rrrrr=dr'r=c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_t|_dSr))rr threadingZlocal _thread_localr*rrrr+oszHTTPDigestAuth.__init__cCsDt|jds d|j_d|j_d|j_i|j_d|j_d|j_dSdS)NinitTr)hasattrr@rA last_nonce nonce_countchalpos num_401_calls)rrrrinit_per_thread_stateus  z$HTTPDigestAuth.init_per_thread_statecs|jjd}|jjd}|jjd}|jjd}|jjd}d|dur*d}n|}|dks6|dkr=d d } | n |d krHd d } | n|dkrSdd} | n |dkr]dd} | fdd} duridSd}t|}|jpsd}|jr~|d|j7}d|j||jf}d||f}|}|}||jj kr|jj d7_ nd|j_ d|jj }t |jj  d}|| d7}|t  d7}|td7}t|dd}|dkrd|||f}|s| |d||f}n|dksd|d vr d!|||d|f}| ||}ndS||j_ d"|j||||f}|r&|d#|7}|r/|d$|7}|r8|d%|7}|rC|d&||f7}d'|S)(z :rtype: str realmnonceqop algorithmopaqueNZMD5zMD5-SESScS"t|tr |d}t|SNutf-8)r rrhashlibZmd5 hexdigestxrrrmd5_utf8  z4HTTPDigestAuth.build_digest_header..md5_utf8ZSHAcSrOrP)r rrrRsha1rSrTrrrsha_utf8rWz4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSrOrP)r rrrRZsha256rSrTrrr sha256_utf8rWz7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSrOrP)r rrrRZsha512rSrTrrr sha512_utf8rWz7HTTPDigestAuth.build_digest_header..sha512_utf8csd||fS)N%s:%sr)sdZ hash_utf8rrsz4HTTPDigestAuth.build_digest_header../?z%s:%s:%sr\rz%08xrQZauth,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)r@rFgetupperrpathqueryrrrDrErrtimectimeosurandomrRrXrSsplit)rmethodurlrJrKrLrMrNZ _algorithmrVrYrZr[ZKDZentdigZp_parsedrhZA1ZA2ZHA1ZHA2Zncvaluer]ZcnonceZrespdigZnoncebitbaserr_rbuild_digest_headers            z"HTTPDigestAuth.build_digest_headercKs|jr d|j_dSdS)z)Reset num_401_calls counter on redirects.rN)Z is_redirectr@rH)rr kwargsrrrhandle_redirects zHTTPDigestAuth.handle_redirectcKs"d|jkr dksnd|j_|S|jjdur!|jj|jj|jdd}d| vr|jjdkr|jjd7_t j d t j d }t |jd|dd |j_|j||j}t|j|j|j||j||j|j|jd <|jj|fi|}|j|||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iirNzwww-authenticaterBZdigestzdigest )flags)countr9)Z status_coder@rHrGZrequestbodyseekr;rflowerrecompile IGNORECASEr subrFZcontentclosecopyrZ_cookiesrawZprepare_cookiesrrrorpZ connectionsendhistoryappend)rr rsZs_authpatZprepZ_rrrr handle_401s0      zHTTPDigestAuth.handle_401cCs|||jjr||j|j|jd<z |j|j_ Wn t y)d|j_ Ynw| d|j | d|j d|j_|S)Nr9Zresponser)rIr@rDrrrorpr;rxtellrGAttributeErrorZ register_hookrrtrHrrrrr!s  zHTTPDigestAuth.__call__cCr,r-r.r1rrrr3*r4zHTTPDigestAuth.__eq__cCr5r)rr1rrrr60r7zHTTPDigestAuth.__ne__N) r#r$r%r&r+rIrrrtrr!r3r6rrrrr>ls f, r>)r&rlr{rjrRr?rbase64rcompatrrrZcookiesrZ_internal_utilsrZutilsr ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTrobjectrr(r=r>rrrrs&    ,