ó `8(Zc@sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZmZddlmZd 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((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt_basic_auth_strs)tAuthBasecBseZdZd„ZRS(s4Base class that all auth implementations derive fromcCstdƒ‚dS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt__call__(s(t__name__t __module__t__doc__R(((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyR%st HTTPBasicAuthcBs2eZdZd„Zd„Zd„Zd„ZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(R R (RR R ((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt__init__/s cCs:t|jt|ddƒk|jt|ddƒkgƒS(NR R (tallR tgetattrtNoneR (Rtother((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt__eq__3scCs ||k S(N((RR((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt__ne__9scCs t|j|jƒ|jd<|S(Nt Authorization(R R R theaders(RR((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyR<s(RRRRRRR(((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/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((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyRDs(RRRR(((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyR AstHTTPDigestAuthcBsVeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( s@Attaches HTTP Digest Authentication to the given Request object.cCs%||_||_tjƒ|_dS(N(R R t threadingtlocalt _thread_local(RR R ((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyRLs  cCsat|jdƒs]t|j_d|j_d|j_i|j_d|j_d|j_ ndS(Ntinitti( thasattrR$tTrueR%t last_noncet nonce_counttchalRtpost num_401_calls(R((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pytinit_per_thread_stateRs     csN|jjd}|jjd}|jjjdƒ}|jjjdƒ}|jjjdƒ}d‰|dkrzd}n |jƒ}|dksž|dkr°d„} | ‰n|d krÎd „} | ‰n‡fd †} ˆdkrídSd} t|ƒ} | jp d }| jr+|d | j7}nd|j||j f}d||f}ˆ|ƒ}ˆ|ƒ}||jj kr“|jj d7_ n d|j_ d|jj }t |jj ƒj dƒ}||j dƒ7}|tjƒj dƒ7}|tjdƒ7}tj|ƒjƒd }|dkrJˆd|||fƒ}n|sl| |d||fƒ}nP|dksd|jdƒkr¸d|||d|f}| ||ƒ}ndS||j_ d|j||||f}|rû|d|7}n|r|d|7}n| r)|d| 7}n|rF|d||f7}nd|S(s :rtype: str trealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(t isinstanceRRthashlibtmd5t hexdigest(tx((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pytmd5_utf8nstSHAcSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(R5RRR6tsha1R8(R9((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pytsha_utf8tscsˆd||fƒS(Ns%s:%s((tstd(t hash_utf8(s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pytzst/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 %sN(R$R+tgetRtupperRtpathtqueryR R R)R*RRttimetctimetosturandomR6R<R8tsplit(RtmethodturlR/R0R1R2R3t _algorithmR:R=tKDtentdigtp_parsedRHtA1tA2tHA1tHA2tncvalueR>tcnoncetrespdigtnoncebittbase((R@s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pytbuild_digest_header\sr               ! cKs|jrd|j_ndS(s)Reset num_401_calls counter on redirects.iN(t is_redirectR$R-(RRtkwargs((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pythandle_redirect¶s cKs_|jjd k r.|jjj|jjƒn|jjddƒ}d|jƒkrO|jj dkrO|jj d7_ t j ddt j ƒ}t |jd|ddƒƒ|j_|j|jƒ|jjƒ}t|j|j|jƒ|j|jƒ|j|j|jƒ|jd <|jj||}|jj|ƒ||_|Sd|j_ |S( so Takes the given response and tries digest-auth, if needed. :rtype: requests.Response swww-authenticateR&tdigestiisdigest tflagstcountRN(R$R,RtrequesttbodytseekRRFtlowerR-tretcompilet IGNORECASERtsubR+tcontenttclosetcopyRt_cookiestrawtprepare_cookiesR^RORPt connectiontsendthistorytappend(RRR`ts_authtpattprept_r((s6/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/auth.pyt handle_401»s($$   cCs§|jƒ|jjr8|j|j|jƒ|jds"