ó –ee[c@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZd Zd Zd „Zd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(s] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iÿÿÿÿN(t b64encodei(turlparsetstr(textract_cookies_to_jar(tparse_dict_headertto_native_string(tcodess!application/x-www-form-urlencodedsmultipart/form-datacCs3dttd||fjdƒƒjƒƒ}|S(sReturns a Basic Auth string.sBasic s%s:%stlatin1(RRtencodetstrip(tusernametpasswordtauthstr((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyt_basic_auth_strs)tAuthBasecBseZdZd„ZRS(s4Base class that all auth implementations derive fromcCstdƒ‚dS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyt__call__'s(t__name__t __module__t__doc__R(((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR$st HTTPBasicAuthcBs eZdZd„Zd„ZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(R R (RR R ((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyt__init__-s cCs t|j|jƒ|jd<|S(Nt Authorization(R R R theaders(RR((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR1s(RRRRR(((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR+s t HTTPProxyAuthcBseZdZd„ZRS(s=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|jƒ|jd<|S(NsProxy-Authorization(R R R R(RR((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR8s(RRRR(((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR6stHTTPDigestAuthcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s@Attaches HTTP Digest Authentication to the given Request object.cCsC||_||_d|_d|_i|_d|_d|_dS(Ntii(R R t last_noncet nonce_counttchaltNonetpost num_401_calls(RR R ((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyR?s      cs-|jd}|jd}|jjdƒ}|jjdƒ}|jjdƒ}|dkred}n |jƒ}|dks‰|dkr›d„} | ‰n|d kr¹d „} | ‰n‡fd †} ˆdkrØdSd} t|ƒ} | jpöd }| jr|d | j7}nd|j||jf}d||f}ˆ|ƒ}ˆ|ƒ}||j krx|j d7_ n d|_ d|j }t |j ƒj dƒ}||j dƒ7}|t jƒj dƒ7}|tjdƒ7}tj|ƒjƒd }|dkr&ˆd|||fƒ}n|dkrN| |d||fƒ}nP|dksod|jdƒkršd|||d|f}| ||ƒ}ndS||_ d|j||||f}|rÚ|d|7}n|rñ|d|7}n| r|d| 7}n|r%|d||f7}nd|S(Ntrealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(t isinstanceRRthashlibtmd5t hexdigest(tx((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pytmd5_utf8VstSHAcSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(R)RRR*tsha1R,(R-((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pytsha_utf8\scsˆd||fƒS(Ns%s:%s((tstd(t hash_utf8(sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pytbst/t?s%s:%s:%ss%s:%sis%08xsutf-8iitautht,s%s:%s:%s:%s:%ss>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s , opaque="%s"s, algorithm="%s"s , digest="%s"s , qop="auth", nc=%s, cnonce="%s"s Digest %s(RtgetR tupperRtpathtqueryR R RRRRttimetctimetosturandomR*R0R,tsplit(RtmethodturlR#R$R%R&R't _algorithmR.R1tKDtentdigtp_parsedR<tA1tA2tHA1tHA2tncvalueR2tcnoncetrespdigtnoncebittbase((R4sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pytbuild_digest_headerHsp                   ! cKs|jrd|_ndS(s)Reset num_401_calls counter on redirects.iN(t is_redirectR"(RRtkwargs((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pythandle_redirectžs cKs_|jd k r(|jjj|jƒnt|ddƒ}|jjddƒ}d|jƒkrR|dkrR|j d7_ t j ddt j ƒ}t |jd|d dƒƒ|_|j|jjƒ|jjƒ}t|j|j|jƒ|j|jƒ|j|j|jƒ|jd <|jj||}|jj|ƒ||_|Sd|_ |S( s:Takes the given response and tries digest-auth, if needed.R"iswww-authenticateRtdigestisdigest tflagstcountRN(R!R trequesttbodytseektgetattrRR:tlowerR"tretcompilet IGNORECASERtsubRtcontenttrawt release_conntcopyRt_cookiestprepare_cookiesRRRCRDt connectiontsendthistorytappend(RRRTR"ts_authtpattprept_r((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyt handle_401£s*!   cCsˆ|jr+|j|j|jƒ|jdR*tbase64RtcompatRRtcookiesRtutilsRRt status_codesRtCONTENT_TYPE_FORM_URLENCODEDtCONTENT_TYPE_MULTI_PARTR tobjectRRRR(((sC/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/auth.pyts