
    '                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  SSKJr  S	rS
rS r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)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-urlencodedzmultipart/form-datac           	      :   [        U [        5      (       d3  [        R                  " SR	                  U 5      [
        S9  [        U 5      n [        U[        5      (       d<  [        R                  " SR	                  [        U5      5      [
        S9  [        U5      n[        U [        5      (       a  U R                  S5      n [        U[        5      (       a  UR                  S5      nS[        [        SR                  X45      5      R                  5       5      -   nU$ )zReturns 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.latin1zBasic    :)
isinstancer   warningswarnformatDeprecationWarningr   typeencoder	   r   joinstrip)usernamepasswordauthstrs      (platform/bq/third_party/requests/auth.py_basic_auth_strr      s     h
++ x('	
 x=h
++ tH~.'	
 x= (C  ??8,(C  ??8,)$))X01288: G N    c                       \ rS rSrSrS rSrg)AuthBaseI   z4Base class that all auth implementations derive fromc                     [        S5      e)NzAuth hooks must be callable.)NotImplementedErrorselfrs     r   __call__AuthBase.__call__L   s    !"@AAr    N__name__
__module____qualname____firstlineno____doc__r&   __static_attributes__r(   r   r   r   r   I   s    >Br   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	HTTPBasicAuthP   z?Attaches HTTP Basic Authentication to the given Request object.c                     Xl         X l        g N)r   r   r$   r   r   s      r   __init__HTTPBasicAuth.__init__S   s      r   c           	      |    [        U R                  [        USS 5      :H  U R                  [        USS 5      :H  /5      $ Nr   r   allr   getattrr   r$   others     r   __eq__HTTPBasicAuth.__eq__W   >    MMWUJ==MMWUJ==
  	r   c                     X:X  + $ r4   r(   r=   s     r   __ne__HTTPBasicAuth.__ne__]         r   c                 `    [        U R                  U R                  5      UR                  S'   U$ )NAuthorizationr   r   r   headersr#   s     r   r&   HTTPBasicAuth.__call__`   s$    %4T]]DMM%R		/"r   )r   r   N)
r*   r+   r,   r-   r.   r6   r?   rC   r&   r/   r(   r   r   r1   r1   P   s    I!!r   r1   c                       \ rS rSrSrS rSrg)HTTPProxyAuthe   z=Attaches HTTP Proxy Authentication to a given Request object.c                 `    [        U R                  U R                  5      UR                  S'   U$ )NzProxy-AuthorizationrH   r#   s     r   r&   HTTPProxyAuth.__call__h   s%    +:4==$--+X		'(r   r(   Nr)   r(   r   r   rL   rL   e   s
    Gr   rL   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)HTTPDigestAuthm   z@Attaches HTTP Digest Authentication to the given Request object.c                 P    Xl         X l        [        R                  " 5       U l        g r4   )r   r   	threadinglocal_thread_localr5   s      r   r6   HTTPDigestAuth.__init__p   s      &__.r   c                    [        U R                  S5      (       dg  SU R                  l        SU R                  l        SU R                  l        0 U R                  l        S U R                  l        S U R                  l        g g )NinitT r   )hasattrrV   rY   
last_noncenonce_countchalposnum_401_calls)r$   s    r   init_per_thread_state$HTTPDigestAuth.init_per_thread_statev   sn    t))622&*D#,.D)-.D*&(D#%)D"/3D, 3r   c                   ^ U R                   R                  S   nU R                   R                  S   nU R                   R                  R                  S5      nU R                   R                  R                  S5      nU R                   R                  R                  S5      nSmUc  SnOUR                  5       nUS:X  d  US:X  a  S	 n	U	mO#US
:X  a  S n
U
mOUS:X  a  S nUmOUS:X  a  S nUmU4S jnTc  gSn[	        U5      nUR
                  =(       d    SnUR                  (       a  USUR                  -   -  nU R                  < SU< SU R                  < 3nU< SU< 3nT" U5      nT" U5      nX@R                   R                  :X  a   U R                   =R                  S-  sl
        OSU R                   l
        SU R                   R                  -  n[        U R                   R                  5      R                  S5      nUUR                  S5      -  nU[        R                  " 5       R                  S5      -  nU[        R                   " S5      -  n["        R$                  " U5      R'                  5       SS nUS:X  a  T" U< SU< SU< 35      nU(       d  U" UU< SU< 35      nO;US:X  d  SUR)                  S5      ;   a  U< SU< SU< SS< SU< 3	nU" UU5      nOgX@R                   l	        SU R                  < SU< SU< SU< SU< S 3nU(       a  US!U-  -  nU(       a  US"U-  -  nU(       a  US#U-  -  nU(       a  US$U< S%U< S 3-  nS&U-  $ )'z
:rtype: str
realmnonceqop	algorithmopaqueNMD5zMD5-SESSc                     [        U [        5      (       a  U R                  S5      n [        R                  " U 5      R                  5       $ Nutf-8)r   r   r   hashlibmd5	hexdigestxs    r   md5_utf84HTTPDigestAuth.build_digest_header.<locals>.md5_utf8   s4    a%%)A{{1~//11r   SHAc                     [        U [        5      (       a  U R                  S5      n [        R                  " U 5      R                  5       $ rk   )r   r   r   rm   sha1ro   rp   s    r   sha_utf84HTTPDigestAuth.build_digest_header.<locals>.sha_utf8   s4    a%%)A||A0022r   zSHA-256c                     [        U [        5      (       a  U R                  S5      n [        R                  " U 5      R                  5       $ rk   )r   r   r   rm   sha256ro   rp   s    r   sha256_utf87HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8   5    a%%)A~~a(2244r   zSHA-512c                     [        U [        5      (       a  U R                  S5      n [        R                  " U 5      R                  5       $ rk   )r   r   r   rm   sha512ro   rp   s    r   sha512_utf87HTTPDigestAuth.build_digest_header.<locals>.sha512_utf8   r}   r   c                 "   > T" U < SU< 35      $ )N:r(   )sd	hash_utf8s     r   <lambda>4HTTPDigestAuth.build_digest_header.<locals>.<lambda>   s    )q!$45r   /?r   r   z%08xrl         auth,z
username="z
", realm="z
", nonce="z", uri="z", response=""z, opaque="%s"z, algorithm="%s"z, digest="%s"z, qop="auth", nc=z
, cnonce="z	Digest %s)rV   r^   getupperr   pathqueryr   r   r\   r]   r   r   timectimeosurandomrm   rv   ro   split)r$   methodurlrd   re   rf   rg   rh   
_algorithmrr   rw   r{   r   KDentdigp_parsedr   A1A2HA1HA2ncvaluer   cnoncerespdignoncebitbaser   s                              @r   build_digest_header"HTTPDigestAuth.build_digest_header   s   
 ""''0""''0  %%))%0&&++//<	##((,,X6	J"*J*
":2 !I5 3 !I9$5 $I9$5 $I5 C=}}#>>C(..((D==%?%mm&&111**a/*-.D*4--999""../66w?	U\\'""	TZZ\  ))	RZZ],,q/++-cr2##uf=>C45GF]f		#6wH h'G (-% #'--tWNOf,,D&22DOf,,D'6JJDd##r   c                 J    UR                   (       a  SU R                  l        gg)z)Reset num_401_calls counter on redirects.r   N)is_redirectrV   r`   )r$   r%   kwargss      r   handle_redirectHTTPDigestAuth.handle_redirect   s    ==/0D, r   c                 l   SUR                   s=::  a  S:  d  O  SU R                  l        U$ U R                  R                  b9  UR                  R
                  R                  U R                  R                  5        UR                  R                  SS5      nSUR                  5       ;   Gau  U R                  R                  S:  GaZ  U R                  =R                  S-  sl        [        R                  " S[        R                  S	9n[        UR                  SUSS
95      U R                  l        UR                     UR#                  5         UR                  R%                  5       n['        UR(                  UR                  UR*                  5        UR-                  UR(                  5        U R/                  UR0                  UR2                  5      UR                  S'   UR4                  R6                  " U40 UD6nUR8                  R;                  U5        XVl        U$ SU R                  l        U$ )zW
Takes the given response and tries digest-auth, if needed.

:rtype: requests.Response
i  i  r   zwww-authenticaterZ   digest   zdigest )flags)countrG   )status_coderV   r`   r_   requestbodyseekrI   r   lowerrecompile
IGNORECASEr
   subr^   contentclosecopyr   _cookiesrawprepare_cookiesr   r   r   
connectionsendhistoryappend)r$   r%   r   s_authpatprep_rs          r   
handle_401HTTPDigestAuth.handle_401   s    amm)c)/0D,H!!- IINN 2 2 6 67126v||~%$*<*<*J*JQ*N,,1,**Zr}}=C&7FRS8T&UD# IIGGI99>>#D"4==!))QUUC  /,0,D,DTXX-'DLL)""4262BJJa JI+,(r   c                    U R                  5         U R                  R                  (       a3  U R                  UR                  UR
                  5      UR                  S'    UR                  R                  5       U R                  l	        UR                  SU R                  5        UR                  SU R                  5        SU R                  l        U$ ! [         a    S U R                  l	         Nhf = f)NrG   responser   )ra   rV   r\   r   r   r   rI   r   tellr_   AttributeErrorregister_hookr   r   r`   r#   s     r   r&   HTTPDigestAuth.__call__  s    ""$(()-)A)A!((AEE)RAIIo&	*%&VV[[]D" 	

DOO4	
D$8$89+,(  	*
 &*D"	*s    )C C21C2c           	      |    [        U R                  [        USS 5      :H  U R                  [        USS 5      :H  /5      $ r9   r:   r=   s     r   r?   HTTPDigestAuth.__eq__+  rA   r   c                     X:X  + $ r4   r(   r=   s     r   rC   HTTPDigestAuth.__ne__1  rE   r   )rV   r   r   N)r*   r+   r,   r-   r.   r6   ra   r   r   r   r&   r?   rC   r/   r(   r   r   rQ   rQ   m   s0    J/4d$L1
*X(!r   rQ   )r.   r   r   r   rm   rT   r   base64r   compatr   r   r   cookiesr   _internal_utilsr	   utilsr
   CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTr   objectr   r1   rL   rQ   r(   r   r   <module>r      sv    
 	      - - + - $B / )XBv BH *M E!X E!r   