
     f'                         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dS )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                    s=t          j        d                    |           t
                     t          |           } t          |t                    sJt          j        d                    t          |                    t
                     t          |          }t          | t                    r|                     d          } t          |t                    r|                    d          }dt          t          d                    | |f                                                              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      \/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/pip/_vendor/requests/auth.py_basic_auth_strr      s6    h
++ ! x(('	
 	
 	
 	
 x==h
++ ! tH~~..'	
 	
 	
 	
 x== (C   -??8,,(C   -??8,,)$))Xx0112288::  G N    c                       e Zd ZdZd ZdS )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AAr   N__name__
__module____qualname____doc__r%    r   r   r   r   E   s.        >>B B B B Br   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.c                 "    || _         || _        d S 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   E    
D!A!AA
D!A!AA
 
 	
r   c                     | |k     S r/   r+   r7   s     r   __ne__zHTTPBasicAuth.__ne__[       5=  r   c                 J    t          | j        | j                  |j        d<   |S )NAuthorizationr   r   r   headersr"   s     r   r%   zHTTPBasicAuth.__call__^   s!    %4T]DM%R%R	/"r   N)r'   r(   r)   r*   r1   r9   r<   r%   r+   r   r   r-   r-   L   sV        II! ! !
 
 
! ! !    r   r-   c                       e Zd ZdZd ZdS )HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c                 J    t          | j        | j                  |j        d<   |S )NzProxy-Authorizationr@   r"   s     r   r%   zHTTPProxyAuth.__call__f   s"    +:4=$-+X+X	'(r   Nr&   r+   r   r   rC   rC   c   s)        GG    r   rC   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.c                 R    || _         || _        t          j                    | _        d S r/   )r   r   	threadinglocal_thread_localr0   s      r   r1   zHTTPDigestAuth.__init__n   s&      &_..r   c                     t          | j        d          sJd| j        _        d| j        _        d| j        _        i | j        _        d | j        _        d | j        _        d S d S )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   si    t)622 	4&*D#,.D)-.D*&(D#%)D"/3D,,,	4 	4r   c                    | j         j        d         }| j         j        d         }| j         j                            d          }| j         j                            d          }| j         j                            d          }d|d}n|                                }|dk    s|dk    rd	 }	|	n#|d
k    rd }
|
n|dk    rd }|n|dk    rd }|fd}dS d}t	          |          }|j        p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
                                      d          }||                    d          z  }|t          j                                        d          z  }|t          j        d          z  }t#          j        |                                          dd         }|dk    r | d| d|           }|s ||| d|           }n9|dk    sd|                    d          v r| d| d| d| } |||          }ndS || 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|                     d          } t          j        |                                           S Nutf-8)r   r   r   hashlibmd5	hexdigestxs    r   md5_utf8z4HTTPDigestAuth.build_digest_header.<locals>.md5_utf8   s?    a%% *))A{1~~//111r   SHAc                     t          | t                    r|                     d          } t          j        |                                           S r]   )r   r   r   r_   sha1ra   rb   s    r   sha_utf8z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8   s?    a%% *))A|A00222r   zSHA-256c                     t          | t                    r|                     d          } t          j        |                                           S r]   )r   r   r   r_   sha256ra   rb   s    r   sha256_utf8z7HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8   A    a%% *))A~a((22444r   zSHA-512c                     t          | t                    r|                     d          } t          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    ))qJJ1JJ// 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~   s5   
 "'0"'0 %))%00&+//<<	#(,,X66	JJ"**J*
":":2 2 2
 !II5  3 3 3
 !II9$$5 5 5
 $II9$$5 5 5
 $I////4 C==}#> 	)((((D777777immimmD&111**a/***-.D*'399".//66w??	U\\'"""	TZ\\  )))	RZ]]a**,,SbS1##)s55U55V5566C 	b....//GGF]]f		#66??'??F??#??Hbh''GG 4(-%2 2 2% 2 25 2 22 2'.2 2 2 	  	+*****D 	10I0000D 	+*****D 	EDDD6DDDDDr   c                 0    |j         rd| j        _        dS dS )z)Reset num_401_calls counter on redirects.r   N)is_redirectrJ   rS   )r#   r$   kwargss      r   handle_redirectzHTTPDigestAuth.handle_redirect   s'    = 	1/0D,,,	1 	1r   c                    d|j         cxk    rdk     sn d| j        _        |S | j        j        )|j        j                            | j        j                   |j                            dd          }d|	                                v rA| j        j        dk     r0| j        xj        dz  c_        t          j        d	t          j        
          }t          |                    d|d                    | j        _        |j         |                                 |j                                        }t'          |j        |j        |j                   |                    |j                   |                     |j        |j                  |j        d<    |j        j        |fi |}|j                            |           ||_        |S d| j        _        |S )zo
        Takes the given response and tries digest-auth, if needed.

        :rtype: requests.Response
        i  i  r   Nz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    am))))c))))/0D,H!- IN 2 67771266v||~~%%$*<*JQ*N*N,,1,,*Zr}===C&7FRS8T8T&U&UD# IIGGIII9>>##D"4=!)QUCCC  ///,0,D,DTX- -DL) #"422622BJa   BJI+,(r   c                    |                                   | j        j        r(|                     |j        |j                  |j        d<   	 |j                                        | j        _	        n# t          $ r d | j        _	        Y nw xY w|                    d| j                   |                    d| j                   d| j        _        |S )Nr?   responser   )rT   rJ   rO   r   r   r   rA   r   tellrR   AttributeErrorregister_hookr   r   rS   r"   s     r   r%   zHTTPDigestAuth.__call__  s    ""$$$( 	S)-)A)A!(AE)R)RAIo&	*%&V[[]]D"" 	* 	* 	*
 &*D"""	* 	

DO444	
D$8999+,(s   
#A. .BB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   s        JJ/ / /4 4 4l  l  l \1 1 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      s     				 				             - - - - - - - - - - - - - - - - + + + + + + $ $ $ $ $ $B / ) ) )XB B B B B B B B    H   .    M   P! P! P! P! P!X P! P! P! P! P!r   