a „oeË'ã@sÊdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZddlmZddlmZd Zd Zd d „ZGd d„dƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. éN)Ú b64encodeé)Úto_native_string)Ú basestringÚstrÚurlparse)Úextract_cookies_to_jar)Úparse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datacCsšt|tƒs&tjd |¡td�t|ƒ}t|tƒsPtjd t|ƒ¡td�t|ƒ}t|tƒrd| d¡}t|tƒrx| d¡}dt t 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ÚtypeÚencoderrÚjoinÚstrip)ÚusernameÚpasswordZauthstr©rú.C:\Program Files\Certbot\pkgs\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__HszAuthBase.__call__N©Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrrEsrc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS©N)rr©rrrrrrÚ__init__OszHTTPBasicAuth.__init__cCs(t|jt|ddƒk|jt|ddƒkgƒS©Nrr©ÚallrÚgetattrr©rÚotherrrrÚ__eq__Ss þÿ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)r0r1r rrrrr&Ls r&c@seZdZdZdd„ZdS)Ú HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|jƒ|jd<|S)NzProxy-Authorizationr3rrrrr fszHTTPProxyAuth.__call__Nr!rrrrr5csr5c@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Ú threadingÚlocalÚ _thread_localr(rrrr)nszHTTPDigestAuth.__init__cCs@t|jdƒs.md5_utf8ZSHAcSs"t|tƒr| d¡}t |¡ ¡SrH)r rrrJÚsha1rKrLrrrÚsha_utf8™s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tƒr| d¡}t |¡ ¡SrH)r rrrJZsha256rKrLrrrÚ sha256_utf8¡s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tƒr| d¡}t |¡ ¡SrH)r rrrJZsha512rKrLrrrÚ sha512_utf8©s  z7HTTPDigestAuth.build_digest_header..sha512_utf8csˆ|›d|›�ƒS)Nú:r)ÚsÚd©Z hash_utf8rrÚ°óz4HTTPDigestAuth.build_digest_header..ú/ú?rSrZ08xrIééZauthú,z:auth:z username="z ", realm="z ", nonce="z", uri="z ", response="ú"z , opaque="z , algorithm="z , digest="z, qop="auth", nc=z , cnonce="zDigest )r9r?ÚgetÚupperrÚpathÚqueryrrr=r>rrÚtimeÚctimeÚosÚurandomrJrOrKÚsplit)rÚmethodÚurlrCrDrErFrGZ _algorithmrNrPrQrRZKDZentdigZp_parsedraZA1ZA2ZHA1ZHA2ZncvaluerTZcnonceZrespdigZnoncebitÚbaserrVrÚbuild_digest_header~s„       ÿÿÿz"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN)Z is_redirectr9rA)rrÚkwargsrrrÚhandle_redirectìszHTTPDigestAuth.handle_redirectcKs&d|jkrdks$nd|j_|S|jjdurB|jj |jj¡|j dd¡}d|  ¡v�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|fi|¤Ž}|j |¡||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response i�iôrNzwww-authenticater;Zdigestézdigest )Úflags)Úcountr2)Z status_coder9rAr@ZrequestÚbodyÚseekr4r_ÚlowerÚreÚcompileÚ IGNORECASEr Úsubr?ZcontentÚcloseÚcopyrZ_cookiesÚrawZprepare_cookiesrkrhriZ connectionÚsendÚhistoryÚappend)rrrlZs_authÚpatZprepZ_rrrrÚ handle_401ñs0    ÿ  zHTTPDigestAuth.handle_401cCs|| ¡|jjr&| |j|j¡|jd<z|j ¡|j_ Wnt yRd|j_ Yn0|  d|j ¡|  d|j ¡d|j_|S)Nr2Zresponser)rBr9r=rkrhrir4rqÚtellr@ÚAttributeErrorZ register_hookrrmrArrrrr s zHTTPDigestAuth.__call__cCs(t|jt|ddƒk|jt|ddƒkgƒSr*r+r.rrrr02s þÿzHTTPDigestAuth.__eq__cCs ||k Sr'rr.rrrr1:szHTTPDigestAuth.__ne__N) r"r#r$r%r)rBrkrmrr r0r1rrrrr6ks n-r6)r%rJrertr7rcrÚbase64rZ_internal_utilsrÚcompatrrrZcookiesrZutilsr ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTrrr&r5r6rrrrÚs$    ,