a
    ýÓEbß'  ã                   @   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
mZmZ ddlmZ ddlmZ ddlmZ d	Zd
Zdd„ ZG dd„ deƒ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é   )ÚurlparseÚstrÚ
basestring)Úextract_cookies_to_jar)Úto_native_string)Úparse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datac                 C   sš   t | tƒs&tjd | ¡td� t| ƒ} t |tƒsPtjd t|ƒ¡td� t|ƒ}t | tƒrd|  d¡} t |tƒrx| d¡}dt	t
d | |f¡ƒ ¡ ƒ }|S )zReturns a Basic Auth string.z·Non-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.)Úcategoryz·Non-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ÚpasswordZauthstr© r   úY/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pip/_vendor/requests/auth.pyÚ_basic_auth_str   s0    

ýû
ýû



ÿr   c                   @   s   e Zd ZdZdd„ ZdS )ÚAuthBasez4Base class that all auth implementations derive fromc                 C   s   t dƒ‚d S )NzAuth hooks must be callable.)ÚNotImplementedError©ÚselfÚrr   r   r   Ú__call__K   s    zAuthBase.__call__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r   r   r   r   r   H   s   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__R   s    zHTTPBasicAuth.__init__c                 C   s(   t | jt|dd ƒk| jt|dd ƒkgƒS ©Nr   r   ©Úallr   Úgetattrr   ©r   Úotherr   r   r   Ú__eq__V   s    þzHTTPBasicAuth.__eq__c                 C   s
   | |k S r'   r   r.   r   r   r   Ú__ne__\   s    zHTTPBasicAuth.__ne__c                 C   s   t | j| jƒ|jd< |S )NÚAuthorization©r   r   r   Úheadersr   r   r   r   r    _   s    zHTTPBasicAuth.__call__N)r"   r#   r$   r%   r)   r0   r1   r    r   r   r   r   r&   O   s
   r&   c                   @   s   e Zd ZdZdd„ ZdS )ÚHTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c                 C   s   t | j| jƒ|jd< |S )NzProxy-Authorizationr3   r   r   r   r   r    g   s    zHTTPProxyAuth.__call__Nr!   r   r   r   r   r5   d   s   r5   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)   o   s    zHTTPDigestAuth.__init__c                 C   s@   t | jdƒs<d| j_d| j_d| j_i | j_d | j_d | j_d S )NÚinitTÚ r   )Úhasattrr9   r:   Ú
last_nonceÚnonce_countÚchalÚposÚnum_401_calls)r   r   r   r   Úinit_per_thread_stateu   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 rTd}n| ¡ }|dksl|dkrzd	d
„ }	|	‰ n@|dkr�dd„ }
|
‰ n*|dkr¦dd„ }|‰ n|dkrºdd„ }|‰ ‡ fdd„}ˆ du rÒdS d}t|ƒ}|jpæd}|jrü|d|j 7 }d| j|| jf }d||f }ˆ |ƒ}ˆ |ƒ}|| j j	k�rJ| j  j
d7  _
nd| j _
d| j j
 }t| j j
ƒ d¡}|| d¡7 }|t ¡  d¡7 }|t d¡7 }t |¡ ¡ dd… }|dk�rÐˆ d|||f ƒ}|�sê||d||f ƒ}n<|dk�sd| d ¡v �r"d!|||d|f }|||ƒ}ndS || j _	d"| j||||f }|�rT|d#| 7 }|�rf|d$| 7 }|�rx|d%| 7 }|�rŽ|d&||f 7 }d'| S )(z
        :rtype: str
        ÚrealmÚnonceÚqopÚ	algorithmÚopaqueNÚMD5zMD5-SESSc                 S   s"   t | tƒr|  d¡} t | ¡ ¡ S ©Núutf-8)r   r   r   ÚhashlibÚmd5Ú	hexdigest©Úxr   r   r   Úmd5_utf8‘   s    

z4HTTPDigestAuth.build_digest_header.<locals>.md5_utf8ÚSHAc                 S   s"   t | tƒr|  d¡} t | ¡ ¡ S rI   )r   r   r   rK   Úsha1rM   rN   r   r   r   Úsha_utf8—   s    

z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8zSHA-256c                 S   s"   t | tƒr|  d¡} t | ¡ ¡ S rI   )r   r   r   rK   Úsha256rM   rN   r   r   r   Úsha256_utf8�   s    

z7HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8zSHA-512c                 S   s"   t | tƒr|  d¡} t | ¡ ¡ S rI   )r   r   r   rK   Úsha512rM   rN   r   r   r   Úsha512_utf8£   s    

z7HTTPDigestAuth.build_digest_header.<locals>.sha512_utf8c                    s   ˆ d| |f ƒS )Nú%s:%sr   )ÚsÚd©Z	hash_utf8r   r   Ú<lambda>©   ó    z4HTTPDigestAuth.build_digest_header.<locals>.<lambda>ú/ú?z%s:%s:%srX   r   z%08xrJ   é   é   Úauthú,z%s:%s:%s:%s:%sz>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z, opaque="%s"z, algorithm="%s"z, digest="%s"z , qop="auth", nc=%s, cnonce="%s"z	Digest %s)r9   r?   ÚgetÚupperr   ÚpathÚqueryr   r   r=   r>   r   r   ÚtimeÚctimeÚosÚurandomrK   rR   rM   Úsplit)r   ÚmethodÚurlrC   rD   rE   rF   rG   Z
_algorithmrP   rS   rU   rW   ÚKDÚentdigZp_parsedrf   ÚA1ÚA2ZHA1ZHA2ÚncvaluerY   ÚcnonceÚrespdigÚnoncebitÚbaser   r[   r   Úbuild_digest_header   s‚    


ÿÿz"HTTPDigestAuth.build_digest_headerc                 K   s   |j rd| j_dS )z)Reset num_401_calls counter on redirects.r   N)Úis_redirectr9   rA   )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rB|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-authenticater;   Údigesté   zdigest )Úflags)Úcountr2   )Ústatus_coder9   rA   r@   ÚrequestÚbodyÚseekr4   rd   ÚlowerÚreÚcompileÚ
IGNORECASEr	   Úsubr?   ÚcontentÚcloseÚcopyr   Ú_cookiesÚrawÚprepare_cookiesrx   rm   rn   Ú
connectionÚsendÚhistoryÚappend)r   r   rz   Zs_authÚpatZ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
yR   d | j_	Y n0 | d| j¡ | d| j¡ d| j_|S )Nr2   Úresponser   )rB   r9   r=   rx   rm   rn   r4   r‚   Útellr@   ÚAttributeErrorÚregister_hookr•   r{   rA   r   r   r   r   r      s    zHTTPDigestAuth.__call__c                 C   s(   t | jt|dd ƒk| jt|dd ƒkgƒS r*   r+   r.   r   r   r   r0   *  s    þzHTTPDigestAuth.__eq__c                 C   s
   | |k S r'   r   r.   r   r   r   r1   0  s    zHTTPDigestAuth.__ne__N)r"   r#   r$   r%   r)   rB   rx   r{   r•   r    r0   r1   r   r   r   r   r6   l   s   
f,r6   )r%   rj   r…   rh   rK   r7   r   Úbase64r   Úcompatr   r   r   Úcookiesr   Ú_internal_utilsr   Úutilsr	   ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTr   Úobjectr   r&   r5   r6   r   r   r   r   Ú<module>   s$   ,