o
    'h'                     @   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| td t| } t |ts(tjdt|td t|}t | tr2| d} t |tr<|d}dt	t
d| |f  }|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authstr r   I/var/www/html/olx_land/venv/lib/python3.10/site-packages/requests/auth.py_basic_auth_str   s,   







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   r2   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,   r4   r7   r"   r   r   r   r   r)   L   s    r)   c                   @   r   )HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c                 C   r9   )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   )hasattrrB   rC   
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   rR   rS   )r   r   r   rU   sha1rW   rX   r   r   r   sha_utf8   r[   z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8zSHA-256c                 S   rR   rS   )r   r   r   rU   sha256rW   rX   r   r   r   sha256_utf8   r[   z7HTTPDigestAuth.build_digest_header.<locals>.sha256_utf8zSHA-512c                 S   rR   rS   )r   r   r   rU   sha512rW   rX   r   r   r   sha512_utf8   r[   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>/?rc   r   08xrT         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 )rB   rH   getupperr   pathqueryr   r   rF   rG   r   r   timectimeosurandomrU   r]   rW   split)r    methodurlrL   rM   rN   rO   rP   
_algorithmrZ   r^   r`   rb   KDentdigp_parsedrs   A1A2HA1HA2ncvaluerd   cnoncerespdignoncebitbaser   rf   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_redirectrB   rJ   )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-authenticaterD   digest   zdigest )flags)countr:   )status_coderB   rJ   rI   requestbodyseekr<   rq   lowerrecompile
IGNORECASEr	   subrH   contentclosecopyr   _cookiesrawprepare_cookiesr   rz   r{   
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 )Nr:   responser   )rK   rB   rF   r   rz   r{   r<   r   tellrI   AttributeErrorregister_hookr   r   rJ   r   r   r   r   r"     s   zHTTPDigestAuth.__call__c                 C   r-   r.   r/   r2   r   r   r   r4   1  r5   zHTTPDigestAuth.__eq__c                 C   r6   r*   r   r2   r   r   r   r7   9  r8   zHTTPDigestAuth.__ne__N)r$   r%   r&   r'   r,   rK   r   r   r   r"   r4   r7   r   r   r   r   r?   k   s    
n,r?   )r'   rU   rw   r   r@   ru   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&    ,