o
    ‚ç×iº'  ã                   @   sÊ   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d„ ZG dd„ dƒZG dd„ deƒZG dd„ deƒZG d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                 C   sž   t | tƒstjd| ›d�td� t| ƒ} t |tƒs*tjdt|ƒ›d�td� t|ƒ}t | tƒr4|  d¡} t |tƒr>| d¡}dtt	d 
| |f¡ƒ ¡ ƒ }|S )zReturns a Basic Auth string.zpNon-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (zC) to a string or bytes object in the near future to avoid problems.)ÚcategoryzpNon-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (Úlatin1zBasic ó   :)Ú
isinstancer   ÚwarningsÚwarnÚDeprecationWarningr   ÚtypeÚencoder   r   ÚjoinÚstrip)ÚusernameÚpasswordÚauthstr© r   úQ/var/www/html/automatizacionGV/venv/lib/python3.10/site-packages/requests/auth.pyÚ_basic_auth_str   s0   

ÿû
ÿû



ÿr   c                   @   ó   e Zd ZdZdd„ ZdS )ÚAuthBasez4Base class that all auth implementations derive fromc                 C   s   t dƒ‚)NzAuth hooks must be callable.)ÚNotImplementedError©ÚselfÚrr   r   r   Ú__call__H   s   zAuthBase.__call__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r   r   r   r   r   E   ó    r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚHTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.c                 C   s   || _ || _d S ©N)r   r   ©r   r   r   r   r   r   Ú__init__O   s   
zHTTPBasicAuth.__init__c                 C   ó(   t | jt|dd ƒk| jt|dd ƒkgƒS ©Nr   r   ©Úallr   Úgetattrr   ©r   Úotherr   r   r   Ú__eq__S   ó
   þÿzHTTPBasicAuth.__eq__c                 C   ó
   | |k S r)   r   r1   r   r   r   Ú__ne__[   ó   
zHTTPBasicAuth.__ne__c                 C   ó   t | j| jƒ|jd< |S )NÚAuthorization©r   r   r   Úheadersr   r   r   r   r!   ^   ó   zHTTPBasicAuth.__call__N)r#   r$   r%   r&   r+   r3   r6   r!   r   r   r   r   r(   L   s    r(   c                   @   r   )ÚHTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c                 C   r8   )NzProxy-Authorizationr:   r   r   r   r   r!   f   r<   zHTTPProxyAuth.__call__Nr"   r   r   r   r   r=   c   r'   r=   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚHTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.c                 C   s   || _ || _t ¡ | _d S r)   )r   r   Ú	threadingÚlocalÚ_thread_localr*   r   r   r   r+   n   s   zHTTPDigestAuth.__init__c                 C   sD   t | jdƒs d| j_d| j_d| j_i | j_d | j_d | j_d S d S )NÚinitTÚ r   )ÚhasattrrA   rB   Ú
last_nonceÚnonce_countÚchalÚposÚnum_401_calls)r   r   r   r   Úinit_per_thread_statet   s   úz$HTTPDigestAuth.init_per_thread_statec                    sÐ  | j jd }| j jd }| j j d¡}| j j d¡}| j j d¡}d‰ |du r*d}n| ¡ }|dks6|dkr=d	d
„ }	|	‰ n |dkrHdd„ }
|
‰ n|dkrSdd„ }|‰ n
|dkr]dd„ }|‰ ‡ fdd„}ˆ du ridS d}t|ƒ}|jpsd}|jr|d|j› �7 }| j› d|› d| j› �}|› d|› �}ˆ |ƒ}ˆ |ƒ}|| j j	kr©| j  j
d7  _
nd| j _
| j j
d›}t| j j
ƒ d¡}|| d¡7 }|t ¡  d¡7 }|t d¡7 }t |¡ ¡ dd… }|dkrîˆ |› d|› d|› �ƒ}|sû|||› d|› �ƒ}n"|dk�sd| d¡v �r|› d|› d|› d |› �}|||ƒ}ndS || j _	d!| j› d"|› d#|› d$|› d%|› d&�}|�r?|d'|› d&�7 }|�rJ|d(|› d&�7 }|�rU|d)|› d&�7 }|�rc|d*|› d+|› d&�7 }d,|› �S )-z
        :rtype: str
        ÚrealmÚnonceÚqopÚ	algorithmÚopaqueNÚMD5zMD5-SESSc                 S   ó"   t | tƒr
|  d¡} t | ¡ ¡ S ©Núutf-8)r   r   r   ÚhashlibÚmd5Ú	hexdigest©Úxr   r   r   Úmd5_utf8‘   ó   

z4HTTPDigestAuth.build_digest_header.<locals>.md5_utf8ÚSHAc                 S   rQ   rR   )r   r   r   rT   Úsha1rV   rW   r   r   r   Úsha_utf8™   rZ   z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8zSHA-256c                 S   rQ   rR   )r   r   r   rT   Úsha256rV   rW   r   r   r   Úsha256_utf8¡   rZ   z7HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8zSHA-512c                 S   rQ   rR   )r   r   r   rT   Úsha512rV   rW   r   r   r   Úsha512_utf8©   rZ   z7HTTPDigestAuth.build_digest_header.<locals>.sha512_utf8c                    s   ˆ | › d|› �ƒS )Nú:r   )ÚsÚd©Ú	hash_utf8r   r   Ú<lambda>°   s    z4HTTPDigestAuth.build_digest_header.<locals>.<lambda>ú/ú?rb   r   Ú08xrS   é   é   Ú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 )rA   rG   ÚgetÚupperr   ÚpathÚqueryr   r   rE   rF   r   r   ÚtimeÚctimeÚosÚurandomrT   r\   rV   Úsplit)r   ÚmethodÚurlrK   rL   rM   rN   rO   Ú
_algorithmrY   r]   r_   ra   ÚKDÚentdigÚp_parsedrr   ÚA1ÚA2ÚHA1ÚHA2Úncvaluerc   ÚcnonceÚrespdigÚnoncebitÚbaser   re   r   Úbuild_digest_header~   s„   
ÿÿÿ
z"HTTPDigestAuth.build_digest_headerc                 K   s   |j r	d| j_dS dS )z)Reset num_401_calls counter on redirects.r   N)Úis_redirectrA   rI   )r   r    Úkwargsr   r   r   Úhandle_redirectì   s   ÿzHTTPDigestAuth.handle_redirectc                 K   s"  d|j   krdk sn d| j_|S | jjdur!|jj | jj¡ |j dd¡}d| 	¡ v r‹| jjdk r‹| j jd7  _t
jd	t
jd
�}t|jd|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-authenticaterC   Údigesté   zdigest )Úflags)Úcountr9   )Ústatus_coderA   rI   rH   ÚrequestÚbodyÚseekr;   rp   ÚlowerÚreÚcompileÚ
IGNORECASEr	   ÚsubrG   ÚcontentÚcloseÚcopyr   Ú_cookiesÚrawÚprepare_cookiesrˆ   ry   rz   Ú
connectionÚsendÚhistoryÚappend)r   r    rŠ   Ús_authÚpatÚprepÚ_rr   r   r   Ú
handle_401ñ   s0   	

ÿzHTTPDigestAuth.handle_401c                 C   s|   |   ¡  | jjr|  |j|j¡|jd< z	|j ¡ | j_	W n t
y)   d | j_	Y nw | d| j¡ | d| j¡ d| j_|S )Nr9   Úresponser   )rJ   rA   rE   rˆ   ry   rz   r;   r’   ÚtellrH   ÚAttributeErrorÚregister_hookr§   r‹   rI   r   r   r   r   r!     s   ûzHTTPDigestAuth.__call__c                 C   r,   r-   r.   r1   r   r   r   r3   1  r4   zHTTPDigestAuth.__eq__c                 C   r5   r)   r   r1   r   r   r   r6   9  r7   zHTTPDigestAuth.__ne__N)r#   r$   r%   r&   r+   rJ   rˆ   r‹   r§   r!   r3   r6   r   r   r   r   r>   k   s    
n,r>   )r&   rT   rv   r•   r?   rt   r   Úbase64r   Ú_internal_utilsr   Úcompatr   r   r   Úcookiesr   Úutilsr	   ÚCONTENT_TYPE_FORM_URLENCODEDÚCONTENT_TYPE_MULTI_PARTr   r   r(   r=   r>   r   r   r   r   Ú<module>   s&    ,