U ��.e�'�@s�dZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd d �ZGd d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)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-urlencodedzmultipart/form-datacCs�t|t�s&tjd�|�td�t|�}t|t�sLtjd�|�td�t|�}t|t�r`|�d�}t|t�rt|�d�}dtt d� ||f��� ��}|S)zReturns 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.�latin1zBasic �:) � isinstancer�warnings�warn�format�DeprecationWarningr�encoderr�join�strip)�username�passwordZauthstr�r�=/usr/lib/python3.8/site-packages/pip/_vendor/requests/auth.py�_basic_auth_strs0 �� ��    �rc@seZdZdZdd�ZdS)�AuthBasez4Base class that all auth implementations derive fromcCs td��dS)NzAuth hooks must be callable.)�NotImplementedError��self�rrrr�__call__KszAuthBase.__call__N��__name__� __module__� __qualname__�__doc__rrrrrrHsrc@s0eZdZdZdd�Zdd�Zdd�Zdd �Zd S) � HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS�N)rr�rrrrrr�__init__RszHTTPBasicAuth.__init__cCs(t|jt|dd�k|jt|dd�kg�S�Nrr��allr�getattrr�r�otherrrr�__eq__Vs�zHTTPBasicAuth.__eq__cCs ||k Sr&rr-rrr�__ne__\szHTTPBasicAuth.__ne__cCst|j|j�|jd<|S)N� Authorization�rrr�headersrrrrr_szHTTPBasicAuth.__call__N)r!r"r#r$r(r/r0rrrrrr%Os r%c@seZdZdZdd�ZdS)� HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|j�|jd<|S)NzProxy-Authorizationr2rrrrrgszHTTPProxyAuth.__call__Nr rrrrr4dsr4c@sPeZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dS)�HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_t��|_dSr&)rr� threadingZlocal� _thread_localr'rrrr(oszHTTPDigestAuth.__init__cCs@t|jd�s.md5_utf8ZSHAcSs"t|t�r|�d�}t�|���SrF)r rrrH�sha1rIrJrrr�sha_utf8�s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|t�r|�d�}t�|���SrF)r rrrHZsha256rIrJrrr� sha256_utf8�s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|t�r|�d�}t�|���SrF)r rrrHZsha512rIrJrrr� sha512_utf8�s  z7HTTPDigestAuth.build_digest_header..sha512_utf8cs�d||f�S)N�%s:%sr)�s�d�Z hash_utf8rr���z4HTTPDigestAuth.build_digest_header..�/�?z%s:%s:%srQrz%08xrG��Zauth�,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)r7r=�get�upperr�pathZqueryrrr;r<rr�time�ctime�os�urandomrHrMrI�split)r�method�urlrArBrCrDrEZ _algorithmrLrNrOrPZKDZentdigZp_parsedr^ZA1ZA2ZHA1ZHA2ZncvaluerRZcnonceZrespdigZnoncebit�baserrTr�build_digest_headers�       � �   z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN)Z is_redirectr7r?)rr�kwargsrrr�handle_redirect�szHTTPDigestAuth.handle_redirectcKs"d|jkrdks$nd|j_|S|jjdk rB|jj�|jj�|j�dd�}d|� �k�r|jjdk�r|jjd7_t j d t j d �}t |jd|dd ��|j_|j|��|j��}t|j|j|j�|�|j�|�|j|j�|jd <|jj|f|�}|j�|�||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response i�i�rNzwww-authenticater9Zdigest�zdigest )�flags)�countr1)Z status_coder7r?r>Zrequest�body�seekr3r\�lower�re�compile� IGNORECASEr �subr=Zcontent�close�copyrZ_cookies�rawZprepare_cookiesrgrdreZ connection�send�history�append)rrrhZs_authZpatZprepZ_rrrr� handle_401�s2    �  zHTTPDigestAuth.handle_401cCs~|��|jjr&|�|j|j�|jd<z|j��|j_ Wnt k rTd|j_ YnX|� d|j �|� d|j �d|j_|S)Nr1Zresponser)r@r7r;rgrdrer3rm�tellr>�AttributeErrorZ register_hookrzrir?rrrrrszHTTPDigestAuth.__call__cCs(t|jt|dd�k|jt|dd�kg�Sr)r*r-rrrr/*s�zHTTPDigestAuth.__eq__cCs ||k Sr&rr-rrrr00szHTTPDigestAuth.__ne__N) r!r"r#r$r(r@rgrirzrr/r0rrrrr5ls f,r5)r$rarpr_rHr6r�base64r�compatrrrZcookiesrZ_internal_utilsrZutilsr ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTr�objectrr%r4r5rrrr�s$    ,