
    k"g'                         d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZ d	Zd
Zd Z G d d      Z G d de      Z G d de      Z G d de      Zy)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-urlencodedzmultipart/form-datac           	         t        | t              s5t        j                  dj	                  |       t
               t        |       } t        |t              s>t        j                  dj	                  t        |            t
               t        |      }t        | t              r| j                  d      } t        |t              r|j                  d      }dt        t        dj                  | |f            j                               z   }|S )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      R/var/www/html/djangosite/lib/python3.12/site-packages/pip/_vendor/requests/auth.py_basic_auth_strr      s     h
+ x('	
 x=h
+ tH~.'	
 x= (C ??8,(C ??8,)$))Xx01288: G N    c                       e Zd ZdZd Zy)AuthBasez4Base class that all auth implementations derive fromc                     t        d      )NzAuth hooks must be callable.)NotImplementedErrorselfrs     r   __call__zAuthBase.__call__H   s    !"@AAr   N__name__
__module____qualname____doc__r%    r   r   r   r   E   s    >Br   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.c                      || _         || _        y N)r   r   r#   r   r   s      r   __init__zHTTPBasicAuth.__init__O   s      r   c           	      |    t        | j                  t        |dd       k(  | j                  t        |dd       k(  g      S Nr   r   allr   getattrr   r#   others     r   __eq__zHTTPBasicAuth.__eq__S   >    
D!AA
D!AA
 	
r   c                     | |k(   S r/   r+   r7   s     r   __ne__zHTTPBasicAuth.__ne__[       5=  r   c                 `    t        | j                  | j                        |j                  d<   |S )NAuthorizationr   r   r   headersr"   s     r   r%   zHTTPBasicAuth.__call__^   s$    %4T]]DMM%R		/"r   N)r'   r(   r)   r*   r1   r9   r<   r%   r+   r   r   r-   r-   L   s    I!
!r   r-   c                       e Zd ZdZd Zy)HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c                 `    t        | j                  | j                        |j                  d<   |S )NzProxy-Authorizationr@   r"   s     r   r%   zHTTPProxyAuth.__call__f   s%    +:4==$--+X		'(r   Nr&   r+   r   r   rC   rC   c   s
    Gr   rC   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.c                 R    || _         || _        t        j                         | _        y r/   )r   r   	threadinglocal_thread_localr0   s      r   r1   zHTTPDigestAuth.__init__n   s      &__.r   c                     t        | j                  d      sgd| j                  _        d| j                  _        d| j                  _        i | j                  _        d | j                  _        d | j                  _        y y )NinitT r   )hasattrrJ   rL   
last_noncenonce_countchalposnum_401_calls)r#   s    r   init_per_thread_statez$HTTPDigestAuth.init_per_thread_statet   sk    t))62&*D#,.D)-.D*&(D#%)D"/3D, 3r   c                 B   | j                   j                  d   }| j                   j                  d   }| j                   j                  j                  d      }| j                   j                  j                  d      }| j                   j                  j                  d      }d|d}n|j                         }|dk(  s|dk(  rd	 }	|	n |d
k(  rd }
|
n|dk(  rd }|n
|dk(  rd }|fd}yd}t	        |      }|j
                  xs d}|j                  r|d|j                   z  }| j                   d| d| j                   }| d| } |      } |      }|| j                   j                  k(  r | j                   xj                  dz  c_
        nd| j                   _
        | j                   j                  d}t        | j                   j                        j                  d      }||j                  d      z  }|t        j                         j                  d      z  }|t        j                   d      z  }t#        j$                  |      j'                         dd }|dk(  r | d| d|       }|s ||| d|       }n0|dk(  sd|j)                  d      v r| d| d| d| } |||      }ny|| j                   _	        d| j                   d| d| d| d | d!}|r	|d"| d!z  }|r	|d#| d!z  }|r	|d$| d!z  }|r|d%| d&| d!z  }d'| S )(z
        :rtype: str
        realmnonceqop	algorithmopaqueNMD5zMD5-SESSc                     t        | t              r| j                  d      } t        j                  |       j                         S Nutf-8)r   r   r   hashlibmd5	hexdigestxs    r   md5_utf8z4HTTPDigestAuth.build_digest_header.<locals>.md5_utf8   s1    a%)A{{1~//11r   SHAc                     t        | t              r| j                  d      } t        j                  |       j                         S r]   )r   r   r   r_   sha1ra   rb   s    r   sha_utf8z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8   s1    a%)A||A0022r   zSHA-256c                     t        | t              r| j                  d      } t        j                  |       j                         S r]   )r   r   r   r_   sha256ra   rb   s    r   sha256_utf8z7HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8   2    a%)A~~a(2244r   zSHA-512c                     t        | t              r| j                  d      } t        j                  |       j                         S r]   )r   r   r   r_   sha512ra   rb   s    r   sha512_utf8z7HTTPDigestAuth.build_digest_header.<locals>.sha512_utf8   rl   r   c                      |  d|       S )N:r+   )sd	hash_utf8s     r   <lambda>z4HTTPDigestAuth.build_digest_header.<locals>.<lambda>   s    )qc1#J/ r   /?rq   r   08xr^         auth,z:auth:z
username="z
", realm="z
", nonce="z", uri="z", response=""z
, opaque="z, algorithm="z
, digest="z, qop="auth", nc=z
, cnonce="zDigest )rJ   rQ   getupperr   pathqueryr   r   rO   rP   r   r   timectimeosurandomr_   rg   ra   split)r#   methodurlrV   rW   rX   rY   rZ   
_algorithmrd   rh   rk   ro   KDentdigp_parsedr   A1A2HA1HA2ncvaluerr   cnoncerespdignoncebitbasert   s                              @r   build_digest_headerz"HTTPDigestAuth.build_digest_header~   s   
 ""''0""''0  %%))%0&&++//<	##((,,X6	J"*J*
":2
 !I5 3
 !I9$5
 $I9$5
 $I/ C=}}#>>a'((Dawa7xqmmD&&111**a/*-.D*''33C8""../66w?	U\\'""	TZZ\  ))	RZZ]a**,Sb1#se1UG1VH56Cq./GF]f		#6'!F86#?Hh'G (-% z%
5' J6wiq2 	 j**DmI;a00Dj**D'y
6(!DDDr   c                 @    |j                   rd| j                  _        yy)z)Reset num_401_calls counter on redirects.r   N)is_redirectrJ   rS   )r#   r$   kwargss      r   handle_redirectzHTTPDigestAuth.handle_redirect   s    ==/0D, r   c                 l   d|j                   cxk  rdk  sn d| j                  _        |S | j                  j                  9|j                  j
                  j                  | j                  j                         |j                  j                  dd      }d|j                         v rz| j                  j                  dk  r`| j                  xj                  dz  c_        t        j                  dt        j                  	      }t        |j                  d|d
            | j                  _        |j                    |j#                          |j                  j%                         }t'        |j(                  |j                  |j*                         |j-                  |j(                         | j/                  |j0                  |j2                        |j                  d<    |j4                  j6                  |fi |}|j8                  j;                  |       ||_        |S d| j                  _        |S )zo
        Takes the given response and tries digest-auth, if needed.

        :rtype: requests.Response
        i  i  r   zwww-authenticaterM   digest   zdigest )flags)countr?   )status_coderJ   rS   rR   requestbodyseekrA   r~   lowerrecompile
IGNORECASEr
   subrQ   contentclosecopyr	   _cookiesrawprepare_cookiesr   r   r   
connectionsendhistoryappend)r#   r$   r   s_authpatprep_rs          r   
handle_401z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 BJI+,(r   c                    | j                          | j                  j                  r3| j                  |j                  |j
                        |j                  d<   	 |j                  j                         | j                  _	        |j                  d| j                         |j                  d| j                         d| j                  _        |S # t        $ r d | j                  _	        Y gw xY w)Nr?   responser   )rT   rJ   rO   r   r   r   rA   r   tellrR   AttributeErrorregister_hookr   r   rS   r"   s     r   r%   zHTTPDigestAuth.__call__  s    ""$(()-)A)A!((AEE)RAIIo&	*%&VV[[]D" 	

DOO4	
D$8$89+,(  	*
 &*D"	*s   )C C,+C,c           	      |    t        | j                  t        |dd       k(  | j                  t        |dd       k(  g      S r3   r4   r7   s     r   r9   zHTTPDigestAuth.__eq__2  r:   r   c                     | |k(   S r/   r+   r7   s     r   r<   zHTTPDigestAuth.__ne__:  r=   r   N)r'   r(   r)   r*   r1   rT   r   r   r   r%   r9   r<   r+   r   r   rF   rF   k   s0    J/4l \1
+Z(
!r   rF   )r*   r_   r   r   rH   r   r   base64r   _internal_utilsr   compatr   r   r   cookiesr	   utilsr
   CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTr   r   r-   rC   rF   r+   r   r   <module>r      st     	 	     - - - + $B / )XB BH .M P!X P!r   