HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/root/usr/local/lib/python3.10/dist-packages/httpx/__pycache__/_auth.cpython-310.pyc
o

���gs.�@s�ddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZddlmZmZmZejrIdd	lmZgd
�ZGdd�d�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dej�ZdS)�)�annotationsN)�	b64encode)�parse_http_list�)�
ProtocolError)�Cookies�Request�Response)�to_bytes�to_str�unquote)�_Hash)�Auth�	BasicAuth�
DigestAuth�	NetRCAuthc@s6eZdZdZdZdZddd�Zdd	d
�Zddd
�ZdS)ra�
    Base class for all authentication schemes.

    To implement a custom authentication scheme, subclass `Auth` and override
    the `.auth_flow()` method.

    If the authentication scheme does I/O such as disk access or network calls, or uses
    synchronization primitives such as locks, you should override `.sync_auth_flow()`
    and/or `.async_auth_flow()` instead of `.auth_flow()` to provide specialized
    implementations that will be used by `Client` and `AsyncClient` respectively.
    F�requestr�return�)typing.Generator[Request, Response, None]ccs�|VdS)a
        Execute the authentication flow.

        To dispatch a request, `yield` it:

        ```
        yield request
        ```

        The client will `.send()` the response back into the flow generator. You can
        access it like so:

        ```
        response = yield request
        ```

        A `return` (or reaching the end of the generator) will result in the
        client returning the last response obtained from the server.

        You can dispatch as many requests as is necessary.
        N���selfrrr�6/usr/local/lib/python3.10/dist-packages/httpx/_auth.py�	auth_flow&s�
zAuth.auth_flowccs^�|jr|��|�|�}t|�}	|V}|jr|��z|�|�}Wn
ty-YdSwq)z�
        Execute the authentication flow synchronously.

        By default, this defers to `.auth_flow()`. You should override this method
        when the authentication scheme does I/O and/or uses concurrency primitives.
        TN)�requires_request_body�readr�next�requires_response_body�send�
StopIteration�rr�flow�responserrr�sync_auth_flow>s�	
��zAuth.sync_auth_flow�(typing.AsyncGenerator[Request, Response]cCsj�|jr|��IdH|�|�}t|�}	|V}|jr"|��IdHz|�|�}Wn
ty3YdSwq)z�
        Execute the authentication flow asynchronously.

        By default, this defers to `.auth_flow()`. You should override this method
        when the authentication scheme does I/O and/or uses concurrency primitives.
        N)r�areadrrrrrr rrr�async_auth_flowWs�	
��zAuth.async_auth_flowN�rrrr)rrrr$)	�__name__�
__module__�__qualname__�__doc__rrrr#r&rrrrrs

rc@s$eZdZdZddd�Zddd�Zd
S)�FunctionAuthz�
    Allows the 'auth' argument to be passed as a simple callable function,
    that takes the request, and returns a new, modified request.
    �func�#typing.Callable[[Request], Request]r�NonecCs
||_dS�N��_func)rr-rrr�__init__ws
zFunctionAuth.__init__rrrccs�|�|�VdSr0r1rrrrrzs�zFunctionAuth.auth_flowN)r-r.rr/r')r(r)r*r+r3rrrrrr,qs
r,c@s.eZdZdZddd�Zddd
�Zddd�ZdS)rzy
    Allows the 'auth' argument to be passed as a (username, password) pair,
    and uses HTTP Basic authentication.
    �username�str | bytes�passwordrr/cCs|�||�|_dSr0)�_build_auth_header�_auth_header�rr4r6rrrr3�szBasicAuth.__init__rrrccs�|j|jd<|VdS)N�
Authorization)r8�headersrrrrr�s�
zBasicAuth.auth_flow�strcC�,d�t|�t|�f�}t|���}d|��S�N�:zBasic ��joinr
r�decode�rr4r6�userpass�tokenrrrr7��
zBasicAuth._build_auth_headerN�r4r5r6r5rr/r'�r4r5r6r5rr<�r(r)r*r+r3rr7rrrrr~s


rc@s0eZdZdZdddd�Zddd
�Zddd�ZdS)rzT
    Use a 'netrc' file to lookup basic auth credentials based on the url host.
    N�file�
str | Nonerr/cCsddl}|�|�|_dS)Nr)�netrc�_netrc_info)rrJrLrrrr3�szNetRCAuth.__init__rrrccsR�|j�|jj�}|dus|ds|VdS|j|d|dd�|jd<|VdS)N�r)r4r6r:)rM�authenticators�url�hostr7r;)rr�	auth_inforrrr�s�
�
zNetRCAuth.auth_flowr4r5r6r<cCr=r>r@rCrrrr7�rFzNetRCAuth._build_auth_headerr0)rJrKrr/r'rHrIrrrrr�s

rc	@s�eZdZUejejejejejejejejd�Zde	d<d)d	d
�Z
d*dd�Zd+dd�Zd,dd�Z
d-dd�Zd.d"d#�Zd/d&d'�Zd(S)0r)�MD5zMD5-SESS�SHAzSHA-SESSzSHA-256zSHA-256-SESSzSHA-512zSHA-512-SESSz*dict[str, typing.Callable[[bytes], _Hash]]�_ALGORITHM_TO_HASH_FUNCTIONr4r5r6rr/cCs$t|�|_t|�|_d|_d|_dS)Nr)r
�	_username�	_password�_last_challenge�_nonce_countr9rrrr3�s


zDigestAuth.__init__rrrccs��|jr|�||j�|jd<|V}|jdksd|jvrdS|j�d�D]}|���d�r.nq#dS|�|||�|_d|_|�||j�|jd<|j	rRt
|j	�j|d�|VdS)Nr:i�zwww-authenticatezdigest r�r)rXr7r;�status_code�get_list�lower�
startswith�_parse_challengerY�cookiesr�set_cookie_header)rrr"�auth_headerrrrr�s*�
��
�
zDigestAuth.auth_flowr"r	rbr<�_DigestAuthChallengec
Cs�|�d�\}}}|��dksJ�i}t|�D]}|���dd�\}	}
t|
�||	<qz4|d��}|d��}|�dd�}
d	|vrF|d	��nd
}d|vrR|d��nd
}t|||
||d�WSt	yr}z	d
}t
||d�|�d
}~ww)z�
        Returns a challenge from a Digest WWW-Authenticate header.
        These take the form of:
        `Digest realm="realm@host.com",qop="auth,auth-int",nonce="abc",opaque="xyz"`
        � �digest�=r�realm�nonce�	algorithmrS�opaqueN�qop)rgrhrirjrkz(Malformed Digest WWW-Authenticate headerrZ)�	partitionr]r�strip�splitr�encode�getrc�KeyErrorr)rrr"rb�scheme�_�fields�header_dict�field�key�valuergrhrirjrk�exc�messagerrrr_�s(
���zDigestAuth._parse_challenge�	challengecsH|j|j���d�fdd�}d�|j|j|jf�}|jj}d�|j	�
�|f�}||�}d|j}|�|j|j
�}	|jd7_||�}
|j���d	�rW|d�|
|j
|	f��}
|j|j|d
�}|durj|
|j
|g}n	|
|j
||	||g}|j|j|j
||d�|��|j�
�d�}
|jr�|j|
d<|r�d
|
d<||
d<|	|
d<d|�|
�S)N�data�bytesrcs�|�����Sr0)�	hexdigestro)r|��	hash_funcrrresz-DigestAuth._build_auth_header.<locals>.digestr?s%08xrz-sessrZ)r4rgrh�urir"rirj�authrk�nc�cnoncezDigest )r|r}rr})rUri�upperrArVrgrWrP�raw_path�methodrorY�_get_client_noncerhr]�endswith�_resolve_qoprkrj�_get_header_value)rrr{re�A1�path�A2�HA2�nc_valuer��HA1rk�digest_data�format_argsrrrr7�s<
�
zDigestAuth._build_auth_header�nonce_count�intrhr}cCsLt|���}||7}|t����7}|t�d�7}t�|���dd���S)N��)	r<ro�time�ctime�os�urandom�hashlib�sha1r~)rr�rh�srrrr�/s
zDigestAuth._get_client_nonce�
header_fields�dict[str, bytes]c
Csbd}d}d}d}t|���D] \}\}}|dkr|d7}||vr"|n|}	||	�|t|��7}q|S)N)rirkr�z{}="{}"z{}={}�rz, )�	enumerate�items�formatr)
rr��NON_QUOTED_FIELDS�QUOTED_TEMPLATE�NON_QUOTED_TEMPLATE�header_value�irvrx�templaterrrr�7s��zDigestAuth._get_header_valuerk�bytes | NonecCsN|durdSt�d|�}d|vrdS|dgkrtd��d|�d�}t||d��)Ns, ?r�sauth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authrZ)�rern�NotImplementedErrorr)rrkr�qopsrzrrrr�Is
zDigestAuth._resolve_qopNrGr')rrr"r	rbr<rrc)rrr{rcrr<)r�r�rhr}rr})r�r�rr<)rkr�rrrr�)r(r)r*r��md5r��sha256�sha512rU�__annotations__r3rr_r7r�r�r�rrrrr�s"
�




0
rc@s6eZdZUded<ded<ded<ded<ded<d	S)
rcr}rgrhr<rir�rjrkN)r(r)r*r�rrrrrcWs
rc)�
__future__rr�r�r�r��typing�base64r�urllib.requestr�_exceptionsr�_modelsrrr	�_utilsr
rr�
TYPE_CHECKINGr
�__all__rr,rrr�
NamedTuplercrrrr�<module>s*[
)