Ë
    Eü´j€-  ã                  óB  — d dl m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 ddlmZmZmZ ddlmZmZ ej(                  rd d	lmZ g d
¢Z G d„ d«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ dej8                  «      Zy)é    )ÚannotationsN)Ú	b64encode)Úparse_http_listé   )ÚProtocolError)ÚCookiesÚRequestÚResponse)Úto_bytesÚto_str)Ú_Hash)ÚAuthÚ	BasicAuthÚ
DigestAuthÚFunctionAuthÚ	NetRCAuthc                  ó0   — e Zd ZdZdZdZdd„Zdd„Zdd„Zy)	r   aô  
    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.
    Fc              #  ó   K  — |–— y­w)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© ©ÚselfÚrequests     úJ/root/workspace/ytshorts/venv/lib/python3.12/site-packages/httpx2/_auth.pyÚ	auth_flowzAuth.auth_flow&   s   è ø€ ð, ‹ùs   ‚c              #  ó   K  — | j                   r|j                  «        | j                  |«      }t        |«      }	 |–—}| j                  r|j                  «        	 |j                  |«      }Œ3# t        $ r Y yw xY w­w)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.
        N)Úrequires_request_bodyÚreadr   ÚnextÚrequires_response_bodyÚsendÚStopIteration©r   r   ÚflowÚresponses       r   Úsync_auth_flowzAuth.sync_auth_flow>   sx   è ø€ ð ×%Ò%Ø�L‰LŒNà�~‰~˜gÓ&ˆÜ�t“*ˆàØ$‘}ˆHØ×*Ò*Ø—‘”ðØŸ)™) HÓ-�ð øô !ò Ùðüs*   ‚AA>ÁA/ Á.A>Á/	A;Á8A>Á:A;Á;A>c               ó*  K  — | j                   r|j                  «       ƒ d{  –—†  | j                  |«      }t        |«      }	 |­–—}| j                  r|j                  «       ƒ d{  –—†  	 |j                  |«      }Œ<7 Œ]7 Œ# t        $ r Y yw xY w­w)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   Úareadr   r   r   r    r!   r"   s       r   Úasync_auth_flowzAuth.async_auth_flowU   s�   è ø€ ð ×%Ò%Ø—-‘-“/×!Ð!à�~‰~˜gÓ&ˆÜ�t“*ˆàØ$’}ˆHØ×*Ò*Ø—n‘nÓ&×&Ð&ðØŸ)™) HÓ-�ð ð "øð 'ùô !ò ÙðüsF   ‚ B¢B £ABÁ(BÁ)BÁ.B Á?BÂBÂ	BÂBÂBÂBN©r   r	   Úreturnz)typing.Generator[Request, Response, None])r   r	   r*   z(typing.AsyncGenerator[Request, Response])	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r%   r(   r   ó    r   r   r      s$   „ ñ
ð "ÐØ"Ðóó0ô.r/   r   c                  ó    — e Zd ZdZdd„Zdd„Zy)r   z‘
    Allows the 'auth' argument to be passed as a simple callable function,
    that takes the request, and returns a new, modified request.
    c                ó   — || _         y ©N©Ú_func)r   Úfuncs     r   Ú__init__zFunctionAuth.__init__s   s	   € Øˆ�
r/   c              #  ó2   K  — | j                  |«      –— y ­wr2   r3   r   s     r   r   zFunctionAuth.auth_flowv   s   è ø€ Ø�j‰j˜Ó!Ó!ùs   ‚N)r5   z#typing.Callable[[Request], Request]r*   ÚNoner)   )r+   r,   r-   r.   r6   r   r   r/   r   r   r   m   s   „ ñó
ô"r/   r   c                  ó(   — e Zd ZdZdd„Zdd„Zdd„Zy)	r   zy
    Allows the 'auth' argument to be passed as a (username, password) pair,
    and uses HTTP Basic authentication.
    c                ó2   — | j                  ||«      | _        y r2   )Ú_build_auth_headerÚ_auth_header©r   ÚusernameÚpasswords      r   r6   zBasicAuth.__init__€   s   € Ø ×3Ñ3°H¸hÓGˆÕr/   c              #  óF   K  — | j                   |j                  d<   |–— y ­w)NÚAuthorization)r<   Úheadersr   s     r   r   zBasicAuth.auth_flowƒ   s   è ø€ Ø+/×+<Ñ+<ˆ�‰˜Ñ(Ø‹ùs   ‚!c                óˆ   — dj                  t        |«      t        |«      f«      }t        |«      j                  «       }d|› �S ©Nó   :zBasic ©Újoinr   r   Údecode©r   r>   r?   ÚuserpassÚtokens        r   r;   zBasicAuth._build_auth_header‡   ó?   € Ø—9‘9œh xÓ0´(¸8Ó2DÐEÓFˆÜ˜(Ó#×*Ñ*Ó,ˆØ˜�wÐÐr/   N©r>   ústr | bytesr?   rN   r*   r8   r)   ©r>   rN   r?   rN   r*   Ústr©r+   r,   r-   r.   r6   r   r;   r   r/   r   r   r   z   s   „ ñó
Hóô r/   r   c                  ó*   — e Zd ZdZddd„Zdd„Zd	d„Zy)
r   zT
    Use a 'netrc' file to lookup basic auth credentials based on the url host.
    Nc                ó8   — dd l }|j                  |«      | _        y )Nr   )ÚnetrcÚ_netrc_info)r   ÚfilerT   s      r   r6   zNetRCAuth.__init__’   s   € ó 	à Ÿ;™; tÓ,ˆÕr/   c              #  óÖ   K  — | j                   j                  |j                  j                  «      }|�|d   s|–— y | j	                  |d   |d   ¬«      |j
                  d<   |–— y ­w)Né   r   )r>   r?   rA   )rU   ÚauthenticatorsÚurlÚhostr;   rB   )r   r   Ú	auth_infos      r   r   zNetRCAuth.auth_flow™   sj   è ø€ Ø×$Ñ$×3Ñ3°G·K±K×4DÑ4DÓEˆ	ØÐ I¨a¢Là‹Mð 04×/FÑ/FÐPYÐZ[ÑP\ÐgpÐqrÑgsÐ/FÓ/tˆG�O‰O˜OÑ,Ø‹Mùs   ‚A'A)c                óˆ   — dj                  t        |«      t        |«      f«      }t        |«      j                  «       }d|› �S rD   rF   rI   s        r   r;   zNetRCAuth._build_auth_header£   rL   r/   r2   )rV   z
str | Noner*   r8   r)   rO   rQ   r   r/   r   r   r   �   s   „ ñô-óô r/   r   c            	      ó  — e Zd ZU ej                  ej                  ej
                  ej
                  ej                  ej                  ej                  ej                  dœZde	d<   dd„Z
dd„Zdd„Zdd„Zdd„Zdd	„Zdd
„Zy)r   )ÚMD5zMD5-SESSÚSHAzSHA-SESSzSHA-256zSHA-256-SESSzSHA-512zSHA-512-SESSz*dict[str, typing.Callable[[bytes], _Hash]]Ú_ALGORITHM_TO_HASH_FUNCTIONc                ó`   — t        |«      | _        t        |«      | _        d | _        d| _        y )Nr   )r   Ú	_usernameÚ	_passwordÚ_last_challengeÚ_nonce_countr=   s      r   r6   zDigestAuth.__init__µ   s*   € Ü! (Ó+ˆŒÜ! (Ó+ˆŒØ<@ˆÔØˆÕr/   c              #  ó8  K  — | j                   r)| j                  || j                   «      |j                  d<   |–—}|j                  dk7  sd|j                  vry |j                  j	                  d«      D ]#  }|j                  «       j                  d«      sŒ# n y | j                  |||«      | _         d| _        | j                  || j                   «      |j                  d<   |j                  r%t        |j                  «      j                  |¬«       |–— y ­w)NrA   i‘  zwww-authenticatezdigest r   ©r   )re   r;   rB   Ústatus_codeÚget_listÚlowerÚ
startswithÚ_parse_challengerf   Úcookiesr   Úset_cookie_header)r   r   r$   Úauth_headers       r   r   zDigestAuth.auth_flow»   s  è ø€ Ø×ÒØ/3×/FÑ/FÀwÐPT×PdÑPdÓ/eˆG�O‰O˜OÑ,à ‘=ˆà×Ñ 3Ò&Ð*<ÀH×DTÑDTÑ*Tð à#×+Ñ+×4Ñ4Ð5GÓHò 	ˆKØ× Ñ Ó"×-Ñ-¨iÕ8Ùð	ð à#×4Ñ4°W¸hÈÓTˆÔØˆÔà+/×+BÑ+BÀ7ÈD×L`ÑL`Ó+aˆ�‰˜Ñ(Ø×ÒÜ�H×$Ñ$Ó%×7Ñ7ÀÐ7ÔHØ‹ùs   ‚BDÂBDc                ó   — |j                  d«      \  }}}|j                  «       dk(  sJ ‚i }t        |«      D ]9  }|j                  «       j	                  dd«      \  }	}
|
j                  d«      ||	<   Œ; 	 |d   j                  «       }|d   j                  «       }|j                  dd	«      }d
|v r|d
   j                  «       nd}d|v r|d   j                  «       nd}t        |||||¬«      S # t        $ r}d}t        ||¬«      |‚d}~ww xY w)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Ú	algorithmr_   ÚopaqueNÚqop)rv   rw   rx   ry   rz   z(Malformed Digest WWW-Authenticate headerrh   )
Ú	partitionrk   r   ÚstripÚsplitÚencodeÚgetÚ_DigestAuthChallengeÚKeyErrorr   )r   r   r$   rp   ÚschemeÚ_ÚfieldsÚheader_dictÚfieldÚkeyÚvaluerv   rw   rx   ry   rz   ÚexcÚmessages                     r   rm   zDigestAuth._parse_challengeÖ   s)  € ð (×1Ñ1°#Ó6Ñˆ��6ð �|‰|‹~ Ò)Ð)Ð)à&(ˆÜ$ VÓ,ò 	0ˆEØŸ™›×,Ñ,¨S°!Ó4‰JˆC�Ø$Ÿ{™{¨3Ó/ˆK˜Òð	0ð		CØ Ñ(×/Ñ/Ó1ˆEØ Ñ(×/Ñ/Ó1ˆEØ#Ÿ™¨°UÓ;ˆIØ7?À;Ñ7N�[ Ñ*×1Ñ1Ô3ÐTXˆFØ16¸+Ñ1E�+˜eÑ$×+Ñ+Ô-È4ˆCÜ'¨e¸5ÈIÐ^dÐjmÔnÐnøÜò 	CØ@ˆGÜ °Ô9¸sÐBûð	Cús   Á5A9C/ Ã/	DÃ8DÄDc           	     ó<  ‡— | j                   |j                  j                  «          Šdˆfd„}dj                  | j                  |j
                  | j                  f«      }|j                  j                  }dj                  |j                  j                  «       |f«      } ||«      }d| j                  z  }| j                  | j                  |j                  «      }	| xj                  dz  c_         ||«      }
|j                  j                  «       j                  d«      r$ |dj                  |
|j                  |	f«      «      }
| j!                  |j"                  |¬«      }|€|
|j                  |g}n|
|j                  ||	||g}| j                  |j
                  |j                  | |dj                  |«      «      |j                  j                  «       dœ}|j$                  r|j$                  |d<   |rd	|d
<   ||d<   |	|d<   d| j'                  |«      z   S )Nc                óL   •—  ‰| «      j                  «       j                  «       S r2   )Ú	hexdigestr~   )ÚdataÚ	hash_funcs    €r   rs   z-DigestAuth._build_auth_header.<locals>.digestô   s   ø€ Ù˜T“?×,Ñ,Ó.×5Ñ5Ó7Ð7r/   rE   s   %08xr   z-sessrh   )r>   rv   rw   Úurir$   rx   ry   ó   authrz   ÚncÚcnoncezDigest )rŽ   Úbytesr*   r”   )ra   rx   ÚupperrG   rc   rv   rd   rZ   Úraw_pathÚmethodr~   rf   Ú_get_client_noncerw   rk   ÚendswithÚ_resolve_qoprz   ry   Ú_get_header_value)r   r   Ú	challengers   ÚA1ÚpathÚA2ÚHA2Únc_valuer“   ÚHA1rz   Údigest_dataÚformat_argsr�   s                 @r   r;   zDigestAuth._build_auth_headerñ   sß  ø€ Ø×4Ñ4°Y×5HÑ5H×5NÑ5NÓ5PÑQˆ	õ	8ð �Y‰Y˜Ÿ™¨	¯©¸¿¹ÐHÓIˆà�{‰{×#Ñ#ˆØ�Y‰Y˜Ÿ™×-Ñ-Ó/°Ð6Ó7ˆá�R‹jˆà˜T×.Ñ.Ñ.ˆØ×'Ñ'¨×(9Ñ(9¸9¿?¹?ÓKˆØ×Ò˜QÑÕá�R‹jˆØ×Ñ×$Ñ$Ó&×/Ñ/°Ô8Ù˜Ÿ™ C¨¯©¸&Ð#AÓBÓCˆCà×Ñ 	§¡°wÐÓ?ˆØˆ;à 	§¡°Ð5‰Kð  	§¡°¸6À3ÈÐLˆKð Ÿ™Ø—_‘_Ø—_‘_ØÙ˜tŸy™y¨Ó5Ó6Ø"×,Ñ,×3Ñ3Ó5ñ
ˆð ×ÒØ$-×$4Ñ$4ˆK˜Ñ!ÙØ!(ˆK˜ÑØ (ˆK˜ÑØ$*ˆK˜Ñ!à˜4×1Ñ1°+Ó>Ñ>Ð>r/   c                ó   — t        |«      j                  «       }||z  }|t        j                  «       j                  «       z  }|t	        j
                  d«      z  }t        j                  |«      j                  «       d d j                  «       S )Né   é   )	rP   r~   ÚtimeÚctimeÚosÚurandomÚhashlibÚsha1r�   )r   Únonce_countrw   Úss       r   r˜   zDigestAuth._get_client_nonce  sp   € Ü�Ó×#Ñ#Ó%ˆØ	ˆU‰
ˆØ	ŒT�Z‰Z‹\× Ñ Ó"Ñ"ˆØ	ŒR�Z‰Z˜‹]Ñˆä�|‰|˜A‹×(Ñ(Ó*¨3¨BÐ/×6Ñ6Ó8Ð8r/   c                ó¾   — d}d}d}d}t        |j                  «       «      D ]8  \  }\  }}|dkD  r|dz  }||vr|n|}	||	j                  |t        |«      «      z  }Œ: |S )N)rx   rz   r’   z{}="{}"z{}={}Ú r   z, )Ú	enumerateÚitemsÚformatr   )
r   Úheader_fieldsÚNON_QUOTED_FIELDSÚQUOTED_TEMPLATEÚNON_QUOTED_TEMPLATEÚheader_valueÚir†   rˆ   Útemplates
             r   r›   zDigestAuth._get_header_value'  s‚   € Ø6ÐØ#ˆØ%ÐàˆÜ!*¨=×+>Ñ+>Ó+@Ó!Aò 	BÑˆA‰~��uØ�1ŠuØ Ñ$�Ø*/Ð7HÑ*H‘ÐNaˆHØ˜HŸO™O¨E´6¸%³=ÓAÑA‰Lð		Bð Ðr/   c                ó†   — |€y t        j                  d|«      }d|v ry|dgk(  rt        d«      ‚d|›d�}t        ||¬«      ‚)Ns   , ?r‘   s   auth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authrh   )Úrer}   ÚNotImplementedErrorr   )r   rz   r   ÚqopsrŠ   s        r   rš   zDigestAuth._resolve_qop5  sV   € Øˆ;ØÜ�x‰x˜ Ó$ˆØ�d‰?Øà�K�=Ò Ü%Ð&VÓWÐWà*¨3¨'Ð1AÐBˆÜ˜G¨WÔ5Ð5r/   NrM   r)   )r   r	   r$   r
   rp   rP   r*   r€   )r   r	   rœ   r€   r*   rP   )r®   Úintrw   r”   r*   r”   )rµ   zdict[str, bytes]r*   rP   )rz   úbytes | Noner   r	   r*   rÁ   )r+   r,   r-   r¬   Úmd5r­   Úsha256Úsha512ra   Ú__annotations__r6   r   rm   r;   r˜   r›   rš   r   r/   r   r   r   ©   sp   … à�{‰{Ø—K‘KØ�|‰|Ø—L‘LØ—>‘>ØŸ™Ø—>‘>ØŸ™ñ	OÐÐ!Kó 	óóó6Có6,?ó\9óô6r/   r   c                  ó@   — e Zd ZU ded<   ded<   ded<   ded<   ded<   y	)
r€   r”   rv   rw   rP   rx   rÁ   ry   rz   N)r+   r,   r-   rÅ   r   r/   r   r€   r€   C  s   … ØƒLØƒLØƒNØÓØ	Ôr/   r€   )Ú
__future__r   r¬   rª   r½   r¨   ÚtypingÚbase64r   Úurllib.requestr   Ú_exceptionsr   Ú_modelsr   r	   r
   Ú_utilsr   r   ÚTYPE_CHECKINGr   Ú__all__r   r   r   r   r   Ú
NamedTupler€   r   r/   r   ú<module>rÑ      s�   ðÝ "ã Û 	Û 	Û Û Ý Ý *å &ß /Ñ /ß $à	×ÒÝò K€÷Tñ Tôn
"�4ô 
"ô �ô  ô& �ô  ô8W6�ô W6ôt˜6×,Ñ,õ r/   