
    Ii.                     <   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	 S
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\R4                  5      rg)    N)	b64encode)parse_http_list   )ProtocolError)CookiesRequestResponse)to_bytesto_strunquote)_Hashc                       \ rS rSrSrSrSrS\S\R                  \\
S4   4S jrS\S\R                  \\
S4   4S jrS\S\R                  \\
4   4S	 jrS
rg)Auth   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.
FrequestreturnNc              #      #    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 selfr   s     1/venv/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_flow9   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_flowR   s      %%--/!!~~g&t*$}H**nn&&&))H-  " ' ! sF   %BBA
B2B3B8B 	BB
BBBBr   )__name__
__module____qualname____firstlineno____doc__r   r   r   typing	Generatorr	   r   r$   AsyncGeneratorr(   __static_attributes__r       r   r   r      s    
 "" V-=-=gxQU>U-V 0			'8T1	22			w0	1r3   r   c                   |    \ rS rSrSrS\R                  \/\4   SS4S jrS\S\R                  \\
S4   4S jrS	rg)
FunctionAuthl   z
Allows the 'auth' argument to be passed as a simple callable function,
that takes the request, and returns a new, modified request.
funcr   Nc                     Xl         g N_func)r   r7   s     r   __init__FunctionAuth.__init__r   s    
r3   r   c              #   2   #    U R                  U5      v   g 7fr9   r:   r   s     r   r   FunctionAuth.auth_flowu   s     jj!!s   r:   )r*   r+   r,   r-   r.   r/   Callabler   r<   r0   r	   r   r2   r   r3   r   r5   r5   l   sP    
V__gY-?@ T " "V-=-=gxQU>U-V "r3   r5   c                       \ rS rSrSrS\R                  \\4   S\R                  \\4   SS4S jr	S\
S\R                  \
\S4   4S	 jrS\R                  \\4   S\R                  \\4   S\4S
 jrSrg)	BasicAuthy   zm
Allows the 'auth' argument to be passed as a (username, password) pair,
and uses HTTP Basic authentication.
usernamepasswordr   Nc                 0    U R                  X5      U l        g r9   )_build_auth_header_auth_headerr   rD   rE   s      r   r<   BasicAuth.__init__   s     !33HGr3   r   c              #   F   #    U R                   UR                  S'   Uv   g 7f)NAuthorization)rH   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   rD   rE   userpasstokens        r   rG   BasicAuth._build_auth_header   A     99hx0(82DEF(#**,wr3   )rH   )r*   r+   r,   r-   r.   r/   Unionstrbytesr<   r   r0   r	   r   rG   r2   r   r3   r   rB   rB   y   s    
HS%Z0H<BLLe<TH	H
 V-=-=gxQU>U-V  S%Z0 <BLLe<T 	 r3   rB   c                       \ rS rSrSrSS\R                  \   SS4S jjrS\	S\R                  \	\S4   4S jrS	\R                  \\4   S
\R                  \\4   S\4S jrSrg)	NetRCAuth   zL
Use a 'netrc' file to lookup basic auth credentials based on the url host.
Nfiler   c                 8    SS K nUR                  U5      U l        g )Nr   )netrc_netrc_info)r   r`   rb   s      r   r<   NetRCAuth.__init__   s     	 ;;t,r3   r   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   )rD   rE   rL   )rc   authenticatorsurlhostrG   rM   )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,rD   rE   c                     SR                  [        U5      [        U5      45      n[        U5      R                  5       nSU 3$ rP   rR   rU   s        r   rG   NetRCAuth._build_auth_header   rY   r3   )rc   r9   )r*   r+   r,   r-   r.   r/   Optionalr[   r<   r   r0   r	   r   rZ   r\   rG   r2   r   r3   r   r^   r^      s    -V__S1 -T -
 
V-=-=gxQU>U-V 
 S%Z0 <BLLe<T 	 r3   r^   c            	       X   \ rS rSr% \R
                  \R
                  \R                  \R                  \R                  \R                  \R                  \R                  S.r	\
R                  \\
R                  \/S4   4   \S'   S\
R                   \\4   S\
R                   \\4   SS4S	 jrS
\S\
R&                  \\S4   4S jrS
\S\S\SS4S jrS
\SSS\4S jrS\S\S\4S jrS\
R                  \\4   S\4S jrS\
R6                  \   S
\S\
R6                  \   4S jrSrg)
DigestAuth   )MD5zMD5-SESSSHAzSHA-SESSzSHA-256zSHA-256-SESSzSHA-512zSHA-512-SESSr   _ALGORITHM_TO_HASH_FUNCTIONrD   rE   r   Nc                 `    [        U5      U l        [        U5      U l        S U l        SU l        g )Nr   )r
   	_username	_password_last_challenge_nonce_countrI   s      r   r<   DigestAuth.__init__   s,     "(+!(+FJr3   r   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)NrL   i  zwww-authenticatezdigest r   r   )rx   rG   rM   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(r#   r   _DigestAuthChallengec                    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getr   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	challengec           
        ^ U R                   UR                  R                  5          mS[        S[        4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UR                  XX/nSR	                  U5      nU R
                  UR                  UR                  UU" SR	                  X4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      -   $ )Ndatar   c                 L   > T" U 5      R                  5       R                  5       $ r9   )	hexdigestr   )r   	hash_funcs    r   r   -DigestAuth._build_auth_header.<locals>.digest  s    T?,,.5577r3   rQ   s   %08xr   z-sessr|   )rD   r   r   urir#   r   r      authr   nccnoncezDigest )rt   r   upperr\   rS   rv   r   rw   rh   raw_pathmethodr   ry   _get_client_noncer   r   endswith_resolve_qopr   r   _get_header_value)r   r   r   r   A1pathA2HA2nc_valuer   HA1r   digest_data
key_digestformat_argsr   s                  @r   rG   DigestAuth._build_auth_header  s    44Y5H5H5N5N5PQ		8 	85 	8 YY	HI{{##YY--/67RjT...''(9(99??KQRj$$&//88C&#ABCC	w?;5K$??HcGKYY{+
 ____tyy#):;<",,335
 $-$4$4K!!(K ($*!411+>>>r3   nonce_countr   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   r   r   ss       r   r   DigestAuth._get_client_nonce1  sn    ##%	
	TZZ\  ""	RZZ]||A((*3B/6688r3   header_fieldsc                     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   r   NON_QUOTED_FIELDSQUOTED_TEMPLATENON_QUOTED_TEMPLATEheader_valueir   r   templates
             r   r   DigestAuth._get_header_value9  s    6#%!*=+>+>+@!AA~1u$ 1  ( 
 OOE6%=AAL "B r3   r   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_qopK  sV     ;xx$d?K= %&VWW*3'1ABG55r3   )rx   ry   rw   rv   )r*   r+   r,   r-   r   md5r   sha256sha512rt   r/   Dictr[   r@   r\   __annotations__rZ   r<   r   r0   r	   r   r   rG   intr   r   rn   r   r2   r   r3   r   rp   rp      sv   {{KK||LL>>>>	XS&//5'7BR2S-S!T 	S%Z0<BLLe<T	 V-=-=gxQU>U-V >CC*2CADC	C>-?-?+A-?	-?^9S 9 95 9v{{3:/F 3 $6??5)64;6		6r3   rp   c                   |    \ rS rSr% \\S'   \\S'   \\S'   \R                  \   \S'   \R                  \   \S'   Sr	g)	r   i[  r   r   r   r   r   r   N)
r*   r+   r,   r-   r\   r   r[   r/   rn   r2   r   r3   r   r   r   [  s/    LLNOOE""		r3   r   )r   r   r   r   r/   base64r   urllib.requestr   _exceptionsr   _modelsr   r   r	   _utilsr
   r   r   TYPE_CHECKINGr   r   r5   rB   r^   rp   
NamedTupler   r   r3   r   <module>r      s     	 	    * & / / - -	X Xv
"4 
"   .   @h6 h6V 6,,  r3   