Ë
    'täis.  ã                  óF  — 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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j:                  «      Zy)é    )ÚannotationsN)Ú	b64encode)Úparse_http_listé   )ÚProtocolError)ÚCookiesÚRequestÚResponse)Úto_bytesÚto_strÚunquote)Ú_Hash)ÚAuthÚ	BasicAuthÚ
DigestAuthÚ	NetRCAuthc                  ó@   — 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     úZ/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/httpx/_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_flowW   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      sD   „ ñ
ð "ÐØ"Ðóð0Øðà	2óð2Øðà	1ôr/   r   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚFunctionAuthz‘
    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__w   s	   € Øˆ�
r/   c              #  ó2   K  — | j                  |«      –— y ­wr3   r4   r   s     r   r   zFunctionAuth.auth_flowz   s   è ø€ Ø�j‰j˜Ó!Ó!ùs   ‚N)r6   z#typing.Callable[[Request], Request]r*   ÚNoner)   )r+   r,   r-   r.   r7   r   r   r/   r   r1   r1   q   s   „ ñó
ô"r/   r1   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 r3   )Ú_build_auth_headerÚ_auth_header©r   ÚusernameÚpasswords      r   r7   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@   rO   r*   r9   r)   ©r?   rO   r@   rO   r*   Ústr©r+   r,   r-   r.   r7   r   r<   r   r/   r   r   r   ~   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   ÚfilerU   s      r   r7   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@   rB   )rV   ÚauthenticatorsÚurlÚhostr<   rC   )r   r   Ú	auth_infos      r   r   zNetRCAuth.auth_flow�   sl   è ø€ Ø×$Ñ$×3Ñ3°G·K±K×4DÑ4DÓEˆ	ØÐ I¨a¢Là‹Mð 04×/FÑ/FØ" 1™°	¸!±ð 0Gó 0ˆG�O‰O˜OÑ,ð ‹Mùs   ‚A'A)c                óˆ   — dj                  t        |«      t        |«      f«      }t        |«      j                  «       }d|› �S rE   rG   rJ   s        r   r<   zNetRCAuth._build_auth_header©   rM   r/   r3   )rW   z
str | Noner*   r9   r)   rP   rR   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   r7   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)NrB   i‘  zwww-authenticatezdigest r   ©r   )rf   r<   rC   Ústatus_codeÚget_listÚlowerÚ
startswithÚ_parse_challengerg   Úcookiesr   Úset_cookie_header)r   r   r$   Úauth_headers       r   r   zDigestAuth.auth_flowÁ   s  è ø€ Ø×ÒØ/3×/FÑ/FØ˜×-Ñ-ó0ˆG�O‰O˜OÑ,ð !‘=ˆà×Ñ 3Ò&Ð*<ÀH×DTÑDTÑ*Tð à#×+Ñ+×4Ñ4Ð5GÖHˆKØ× Ñ Ó"×-Ñ-¨iÕ8Ùð Ið à#×4Ñ4°W¸hÈÓTˆÔØˆÔà+/×+BÑ+BØ�T×)Ñ)ó,
ˆ�‰˜Ñ(ð ×ÒÜ�H×$Ñ$Ó%×7Ñ7ÀÐ7ÔHØ‹ùs   ‚BDÂBDc                ó  — |j                  d«      \  }}}|j                  «       dk(  sJ ‚i }t        |«      D ]3  }|j                  «       j	                  dd«      \  }	}
t        |
«      ||	<   Œ5 	 |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 headerri   )Ú	partitionrl   r   ÚstripÚsplitr   ÚencodeÚgetÚ_DigestAuthChallengeÚKeyErrorr   )r   r   r$   rq   ÚschemeÚ_ÚfieldsÚheader_dictÚfieldÚkeyÚvaluerv   rw   rx   ry   rz   ÚexcÚmessages                     r   rn   zDigestAuth._parse_challengeà   s%  € ð (×1Ñ1°#Ó6Ñˆ��6ð �|‰|‹~ Ò)Ð)Ð)à&(ˆÜ$ VÖ,ˆEØŸ™›×,Ñ,¨S°!Ó4‰JˆC�Ü& u›~ˆK˜Òð -ð	CØ Ñ(×/Ñ/Ó1ˆEØ Ñ(×/Ñ/Ó1ˆEØ#Ÿ™¨°UÓ;ˆIØ7?À;Ñ7N�[ Ñ*×1Ñ1Ô3ÐTXˆFØ16¸+Ñ1E�+˜eÑ$×+Ñ+Ô-È4ˆCÜ'Ø 5°IÀfÐRUôð øô ò 	CØ@ˆGÜ °Ô9¸sÐBûð	Cús   Á/A9C) Ã)	DÃ2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 r3   )Ú	hexdigestr~   )ÚdataÚ	hash_funcs    €r   rt   z-DigestAuth._build_auth_header.<locals>.digest  s   ø€ Ù˜T“?×,Ñ,Ó.×5Ñ5Ó7Ð7r/   rF   s   %08xr   z-sessri   )r?   rv   rw   Úurir$   rx   ry   ó   authrz   ÚncÚcnoncezDigest )rŽ   Úbytesr*   r”   )rb   rx   ÚupperrH   rd   rv   re   r[   Úraw_pathÚmethodr~   rg   Ú_get_client_noncerw   rl   ÚendswithÚ_resolve_qoprz   ry   Ú_get_header_value)r   r   Ú	challengert   Ú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é   é   )	rQ   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_value7  s†   € Ø6ÐØ#ˆØ%ÐàˆÜ!*¨=×+>Ñ+>Ó+@Ö!AÑˆA‰~��uØ�1ŠuØ Ñ$�ð Ð 1Ñ1ñ  à(ð ð
 ˜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 authri   )Úrer}   ÚNotImplementedErrorr   )r   rz   r   ÚqopsrŠ   s        r   rš   zDigestAuth._resolve_qopI  sV   € Øˆ;ØÜ�x‰x˜ Ó$ˆØ�d‰?Øà�K�=Ò Ü%Ð&VÓWÐWà*¨3¨'Ð1AÐBˆÜ˜G¨WÔ5Ð5r/   NrN   r)   )r   r	   r$   r
   rq   rQ   r*   r€   )r   r	   rœ   r€   r*   rQ   )r®   Úintrw   r”   r*   r”   )rµ   zdict[str, bytes]r*   rQ   )rz   úbytes | Noner   r	   r*   rÁ   )r+   r,   r-   r¬   Úmd5r­   Úsha256Úsha512rb   Ú__annotations__r7   r   rn   r<   r˜   r›   rš   r   r/   r   r   r   ¯   s¬   … à�{‰{Ø—K‘KØ�|‰|Ø—L‘LØ—>‘>ØŸ™Ø—>‘>ØŸ™ñ	OÐÐ!Kó 	óóð>CØðCØ*2ðCØADðCà	óCð>.?Øð.?Ø+?ð.?à	ó.?ó`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   rQ   rx   rÁ   ry   rz   N)r+   r,   r-   rÅ   r   r/   r   r€   r€   W  s   … ØƒLØƒLØƒNØÓØ	Ôr/   r€   )Ú
__future__r   r¬   rª   r½   r¨   ÚtypingÚbase64r   Úurllib.requestr   Ú_exceptionsr   Ú_modelsr   r	   r
   Ú_utilsr   r   r   ÚTYPE_CHECKINGr   Ú__all__r   r1   r   r   r   Ú
NamedTupler€   r   r/   r   Ú<module>rÑ      s‘   ðÝ "ã Û 	Û 	Û Û Ý Ý *å &ß /Ñ /ß -Ñ -à	×ÒÝò ;€÷Xñ Xôv
"�4ô 
"ô �ô  ô& �ô  ô<e6�ô e6ôP˜6×,Ñ,õ r/   