o �J�hs.�@s�ddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZddlmZmZmZejrIdd lmZgd �ZGd d �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�IC:\pinokio\api\whisper-webui.git\app\env\lib\site-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�rrZflow�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�Zdd d �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�Z_func)rr,rrr�__init__ws zFunctionAuth.__init__rrrccs�|�|�VdSr/r0rrrrrzs�zFunctionAuth.auth_flowN)r,r-rr.r&)r'r(r)r*r1rrrrrr+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|�||�|_dSr/)�_build_auth_header� _auth_header�rr2r4rrrr1�szBasicAuth.__init__rrrccs�|j|jd<|VdS)N� Authorization)r6�headersrrrrr�s�  zBasicAuth.auth_flow�strcC�,d�t|�t|�f�}t|���}d|��S�N�:zBasic ��joinr r�decode�rr2r4Zuserpass�tokenrrrr5��  zBasicAuth._build_auth_headerN�r2r3r4r3rr.r&�r2r3r4r3rr:�r'r(r)r*r1rr5rrrrr~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)rrGrIrrrr1�szNetRCAuth.__init__rrrccsR�|j�|jj�}|dus|ds|VdS|j|d|dd�|jd<|VdS)N�r)r2r4r8)rJZauthenticators�url�hostr5r9)rrZ auth_inforrrr�s�   � zNetRCAuth.auth_flowr2r3r4r:cCr;r<r>rArrrr5�rCzNetRCAuth._build_auth_headerr/)rGrHrr.r&rErFrrrrr�s    rc @s�eZdZUejejejejejejejejd�Zde d<d)d d �Z d*dd�Z d+dd�Z d,dd�Z d-dd�Zd.d"d#�Zd/d&d'�Zd(S)0r)�MD5zMD5-SESSZSHAzSHA-SESSzSHA-256z SHA-256-SESSzSHA-512z SHA-512-SESSz*dict[str, typing.Callable[[bytes], _Hash]]�_ALGORITHM_TO_HASH_FUNCTIONr2r3r4rr.cCs$t|�|_t|�|_d|_d|_dS)Nr)r � _username� _password�_last_challenge� _nonce_countr7rrrr1�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)Nr8i�zwww-authenticatezdigest r�r) rRr5r9� status_codeZget_list�lower� startswith�_parse_challengerS�cookiesrZset_cookie_header)rrr!� auth_headerrrrr�s*� �� � zDigestAuth.auth_flowr!r rZr:�_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� algorithmrN�opaqueN�qop)r_r`rarbrcz(Malformed Digest WWW-Authenticate headerrT) � partitionrVr�strip�splitr �encode�getr[�KeyErrorr)rrr!rZ�scheme�_�fieldsZ header_dict�field�key�valuer_r`rarbrc�exc�messagerrrrX�s(     ���zDigestAuth._parse_challenge� challengecsH|j|j���d�fdd� }d�|j|j|jf�}|jj}d�|j � �|f�}||�}d|j }|� |j |j �} |j d7_ ||�} |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�|�����Sr/)� hexdigestrg)rs�Z hash_funcrrr]sz-DigestAuth._build_auth_header.<locals>.digestr=s%08xrz-sessrT)r2r_r`Zurir!rarb�authrc�nc�cnoncezDigest )rsrtrrt)rOra�upperr?rPr_rQrL�raw_path�methodrgrS�_get_client_noncer`rV�endswith� _resolve_qoprcrb�_get_header_value)rrrrr]ZA1�pathZA2ZHA2Znc_valueryZHA1rcZ digest_dataZ format_argsrrvrr5�s<  � zDigestAuth._build_auth_header� nonce_count�intr`rtcCsLt|���}||7}|t����7}|t�d�7}t�|���dd���S)N��) r:rg�time�ctime�os�urandom�hashlib�sha1ru)rr�r`�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)rarcrxz{}="{}"z{}={}�rz, )� enumerate�items�formatr ) rr�ZNON_QUOTED_FIELDSZQUOTED_TEMPLATEZNON_QUOTED_TEMPLATEZ header_value�irmro�templaterrrr�7s��zDigestAuth._get_header_valuerc� bytes | NonecCsN|durdSt�d|�}d|vrdS|dgkrtd��d|�d�}t||d��)Ns, ?rwsauth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authrT)�rerf�NotImplementedErrorr)rrcrZqopsrqrrrrIs    zDigestAuth._resolve_qopNrDr&)rrr!r rZr:rr[)rrrrr[rr:)r�r�r`rtrrt)r�r�rr:)rcr�rrrr�)r'r(r)r��md5r��sha256�sha512rO�__annotations__r1rrXr5r}r�rrrrrr�s" �    0 rc@s6eZdZUded<ded<ded<ded<ded<d S) r[rtr_r`r:rar�rbrcN)r'r(r)r�rrrrr[Ws  r[)� __future__rr�r�r�r��typing�base64rZurllib.requestr� _exceptionsr�_modelsrrr �_utilsr r r � TYPE_CHECKINGr �__all__rr+rrr� NamedTupler[rrrr�<module>s*     [ )
Memory