
    hs.                    P   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  SSKJr  SSKJrJrJr  SSKJrJrJr  \R*                  (       a  S S	KJr  / S
Qr " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\R:                  5      rg)    )annotationsN)	b64encode)parse_http_list   )ProtocolError)CookiesRequestResponse)to_bytesto_strunquote)_Hash)Auth	BasicAuth
DigestAuth	NetRCAuthc                  N    \ rS rSrSrSrSrS	S jr    S	S jr    S
S jr	Sr
g)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              #     #    Uv   g7f)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     =/var/www/html/env/lib/python3.13/site-packages/httpx/_auth.py	auth_flowAuth.auth_flow&   s     , s   c              #    #    U R                   (       a  UR                  5         U R                  U5      n[        U5      n Uv nU R                  (       a  UR                  5          UR                  U5      nM9  ! [         a     gf = f7f)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_flowAuth.sync_auth_flow>   sw      %%LLN~~g&t*$}H**))H-  ! s*   A$B
'A: 8B
:
BB
BB
c               B  #    U R                   (       a  UR                  5       I Sh  vN   U R                  U5      n[        U5      n U7v nU R                  (       a  UR                  5       I Sh  vN    UR                  U5      nMB   Nc N! [         a     gf = f7f)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_flowAuth.async_auth_flowW   s      %%--/!!~~g&t*$}H**nn&&&))H-  " ' ! sF   %BBA
B2B3B8B 	BB
BBBBr   Nr   r	   returnz)typing.Generator[Request, Response, None])r   r	   r.   z(typing.AsyncGenerator[Request, Response])__name__
__module____qualname____firstlineno____doc__r   r!   r   r'   r+   __static_attributes__r       r   r   r      sD    
 ""0	22	1r5   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	FunctionAuthq   z
Allows the 'auth' argument to be passed as a simple callable function,
that takes the request, and returns a new, modified request.
c                    Xl         g N_func)r   funcs     r   __init__FunctionAuth.__init__w   s    
r5   c              #  2   #    U R                  U5      v   g 7fr:   r;   r   s     r   r   FunctionAuth.auth_flowz   s     jj!!s   r;   N)r=   z#typing.Callable[[Request], Request]r.   Noner-   )r/   r0   r1   r2   r3   r>   r   r4   r   r5   r   r7   r7   q   s    
"r5   r7   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)r   ~   zm
Allows the 'auth' argument to be passed as a (username, password) pair,
and uses HTTP Basic authentication.
c                0    U R                  X5      U l        g r:   )_build_auth_header_auth_headerr   usernamepasswords      r   r>   BasicAuth.__init__   s     33HGr5   c              #  F   #    U R                   UR                  S'   Uv   g 7f)NAuthorization)rG   headersr   s     r   r   BasicAuth.auth_flow   s     +/+<+<(s   !c                    SR                  [        U5      [        U5      45      n[        U5      R                  5       nSU 3$ N   :zBasic joinr   r   decoder   rI   rJ   userpasstokens        r   rF   BasicAuth._build_auth_header   ?    99hx0(82DEF(#**,wr5   )rG   NrI   str | bytesrJ   r\   r.   rB   r-   rI   r\   rJ   r\   r.   str	r/   r0   r1   r2   r3   r>   r   rF   r4   r   r5   r   r   r   ~   s    
H r5   r   c                  :    \ rS rSrSrSS	S jjrS
S jrSS jrSrg)r      zL
Use a 'netrc' file to lookup basic auth credentials based on the url host.
Nc                8    SS K nUR                  U5      U l        g )Nr   )netrc_netrc_info)r   filerc   s      r   r>   NetRCAuth.__init__   s     	 ;;t,r5   c              #     #    U R                   R                  UR                  R                  5      nUb
  US   (       d  Uv   g U R	                  US   US   S9UR
                  S'   Uv   g 7f)N   r   )rI   rJ   rM   )rd   authenticatorsurlhostrF   rN   )r   r   	auth_infos      r   r   NetRCAuth.auth_flow   sk     $$33GKK4D4DE	IaLM 04/F/F"1	! 0G 0GOOO, Ms   A*A,c                    SR                  [        U5      [        U5      45      n[        U5      R                  5       nSU 3$ rQ   rS   rV   s        r   rF   NetRCAuth._build_auth_header   rZ   r5   )rd   r:   )re   z
str | Noner.   rB   r-   r]   r_   r   r5   r   r   r      s    -
 r5   r   c            	      8   \ rS rSr% \R
                  \R
                  \R                  \R                  \R                  \R                  \R                  \R                  S.r	S\
S'   SS jrSS jr        SS jr      SS jrSS	 jrSS
 jrSS jrSrg)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                `    [        U5      U l        [        U5      U l        S U l        SU l        g )Nr   )r   	_username	_password_last_challenge_nonce_countrH   s      r   r>   DigestAuth.__init__   s*    !(+!(+<@r5   c              #  T  #    U R                   (       a(  U R                  XR                   5      UR                  S'   Uv nUR                  S:w  d  SUR                  ;  a  g UR                  R	                  S5       H)  nUR                  5       R                  S5      (       d  M)    O   g U R                  XU5      U l         SU l        U R                  XR                   5      UR                  S'   UR                  (       a"  [        UR                  5      R                  US9  Uv   g 7f)NrM   i  zwww-authenticatezdigest r   r   )rx   rF   rN   status_codeget_listlower
startswith_parse_challengery   cookiesr   set_cookie_header)r   r   r&   auth_headers       r   r   DigestAuth.auth_flow   s    /3/F/F--0GOOO, !=3&*<HDTDT*T #++445GHK  "--i88 I #44WT+/+B+B)),
( H$$%777Hs   BD(%BD(c                   UR                  S5      u  pEnUR                  5       S:X  d   e0 n[        U5       H2  nUR                  5       R	                  SS5      u  p[        U
5      Xy'   M4      US   R                  5       nUS   R                  5       nUR                  SS5      nS	U;   a  US	   R                  5       OS
nSU;   a  US   R                  5       OS
n[        XXUS9$ ! [         a  nSn[        UUS9UeS
nAff = f)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	algorithmrr   opaqueNqop)r   r   r   r   r   z(Malformed Digest WWW-Authenticate headerr|   )	partitionr   r   stripsplitr   encodeget_DigestAuthChallengeKeyErrorr   )r   r   r&   r   scheme_fieldsheader_dictfieldkeyvaluer   r   r   r   r   excmessages                     r   r   DigestAuth._parse_challenge   s    (11#66 ||~)))&($V,E,,S!4JC&u~K -	C(//1E(//1E#U;I7?;7N[*113TXF16+1E+e$++-4C'IRU   	C@G9sB	Cs   /A8C( (
D2C??Dc           	     L  ^ U R                   UR                  R                  5          mSU4S jjnSR                  U R                  UR
                  U R                  45      nUR                  R                  nSR                  UR                  R                  5       U45      nU" U5      nSU R                  -  nU R                  U R                  UR                  5      n	U =R                  S-  sl        U" U5      n
UR                  R                  5       R                  S5      (       a#  U" SR                  XR                  U	45      5      n
U R!                  UR"                  US9nUc  XR                  U/nOXR                  XX/nU R                  UR
                  UR                  UU" SR                  U5      5      UR                  R                  5       S.nUR$                  (       a  UR$                  US'   U(       a  S	US
'   XS'   XS'   SU R'                  U5      -   $ )Nc                L   > T" U 5      R                  5       R                  5       $ r:   )	hexdigestr   )data	hash_funcs    r   r   -DigestAuth._build_auth_header.<locals>.digest  s    T?,,.5577r5   rR   s   %08xr   z-sessr|   )rI   r   r   urir&   r   r      authr   nccnoncezDigest )r   bytesr.   r   )rt   r   upperrT   rv   r   rw   rj   raw_pathmethodr   ry   _get_client_noncer   r   endswith_resolve_qopr   r   _get_header_value)r   r   	challenger   A1pathA2HA2nc_valuer   HA1r   digest_dataformat_argsr   s                 @r   rF   DigestAuth._build_auth_header   s    44Y5H5H5N5N5PQ		8 YY	HI{{##YY--/67RjT...''(9(99??KQRj$$&//88C&#ABCC	w?;5K 3LK ____tyy56",,335
 $-$4$4K!!(K ($*!411+>>>r5   c                $   [        U5      R                  5       nX2-  nU[        R                  " 5       R                  5       -  nU[        R
                  " S5      -  n[        R                  " U5      R                  5       S S R                  5       $ )N      )	r^   r   timectimeosurandomhashlibsha1r   )r   nonce_countr   ss       r   r   DigestAuth._get_client_nonce/  sn    ##%	
	TZZ\  ""	RZZ]||A((*3B/6688r5   c                    SnSnSnSn[        UR                  5       5       H9  u  nu  pxUS:  a  US-  nXr;  a  UOUn	XYR                  U[        U5      5      -  nM;     U$ )N)r   r   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   DigestAuth._get_header_value7  s    6#%!*=+>+>+@!AA~1u$ 1  ( 
 OOE6%=AAL "B r5   c                    Uc  g [         R                  " SU5      nSU;   a  gUS/:X  a  [        S5      eSU< S3n[        XBS9e)Ns   , ?r   s   auth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authr|   )rer   NotImplementedErrorr   )r   r   r   qopsr   s        r   r   DigestAuth._resolve_qopI  sT    ;xx$d?K= %&VWW*3'1ABG55r5   )rx   ry   rw   rv   Nr[   r-   )r   r	   r&   r
   r   r^   r.   r   )r   r	   r   r   r.   r^   )r   intr   r   r.   r   )r   zdict[str, bytes]r.   r^   )r   bytes | Noner   r	   r.   r   )r/   r0   r1   r2   r   md5r   sha256sha512rt   __annotations__r>   r   r   rF   r   r   r   r4   r   r5   r   r   r      s    {{KK||LL>>>>	O!K 	>CC*2CADC	C>.?.?+?.?	.?`9$6r5   r   c                  H    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S	'   S
rg)r   iW  r   r   r   r^   r   r   r   r   r   N)r/   r0   r1   r2   r   r4   r   r5   r   r   r   W  s    LLN	r5   r   )
__future__r   r   r   r   r   typingbase64r   urllib.requestr   _exceptionsr   _modelsr   r	   r
   _utilsr   r   r   TYPE_CHECKINGr   __all__r   r7   r   r   r   
NamedTupler   r   r5   r   <module>r      s    "  	 	    * & / / - -	 ;X Xv
"4 
"   &   <e6 e6P6,, r5   