
    =h-                     6   d dl 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 ddlmZmZmZ ej&                  rd dl m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j4                        Zy)    N)	b64encode)parse_http_list   )ProtocolError)RequestResponse)to_bytesto_strunquote)_Hashc                       e Zd ZdZdZdZdedej                  ee	df   fdZ
dedej                  ee	df   fdZdedej                  ee	f   fdZy)	Autha  
    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              #      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 selfr   s     [/var/www/html/phonemate/phone_mate_backend/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      %%LLN~~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_flowS   s      %%--/!!~~g&t*$}H**nn&&&))H-  " ' ! sF    BB AB(B)B.B ?BB	BBBB)__name__
__module____qualname____doc__r   r   r   typing	Generatorr   r   r!   AsyncGeneratorr$   r       r   r   r      s    
 "" V-=-=gxQU>U-V 0			'8T1	22			w0	1r,   r   c                   p    e Zd ZdZdej
                  egef   ddfdZdedej                  ee	df   f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.
    funcr   Nc                     || _         y N_func)r   r/   s     r   __init__zFunctionAuth.__init__s   s	    
r,   r   c              #   2   K   | j                  |       y wr1   r2   r   s     r   r   zFunctionAuth.auth_flowv   s     jj!!s   )r%   r&   r'   r(   r)   Callabler   r4   r*   r   r   r   r,   r   r.   r.   m   sP    
V__gY-?@ T " "V-=-=gxQU>U-V "r,   r.   c                       e Zd ZdZdej
                  eef   dej
                  eef   fdZde	dej                  e	edf   fdZdej
                  eef   dej
                  eef   defd	Zy)
	BasicAuthzy
    Allows the 'auth' argument to be passed as a (username, password) pair,
    and uses HTTP Basic authentication.
    usernamepasswordc                 2    | j                  ||      | _        y r1   )_build_auth_header_auth_headerr   r9   r:   s      r   r4   zBasicAuth.__init__   s     !33HhGr,   r   r   Nc              #   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   r9   r:   userpasstokens        r   r<   zBasicAuth._build_auth_header   A     99hx0(82DEF(#**,wr,   )r%   r&   r'   r(   r)   Unionstrbytesr4   r   r*   r   r   r<   r   r,   r   r8   r8   z   s    
HS%Z0H<BLLe<TH
 V-=-=gxQU>U-V  S%Z0 <BLLe<T 	 r,   r8   c                       e Zd ZdZddej
                  e   fdZdedej                  ee
df   fdZdej                  eef   d	ej                  eef   defd
Zy)	NetRCAuthzT
    Use a 'netrc' file to lookup basic auth credentials based on the url host.
    Nfilec                 8    t        j                   |      | _        y r1   )netrc_netrc_info)r   rQ   s     r   r4   zNetRCAuth.__init__   s     ;;t,r,   r   r   c              #      K   | j                   j                  |j                  j                        }||d   s| y | j	                  |d   |d         |j
                  d<   | y w)N   r   )r9   r:   r@   )rT   authenticatorsurlhostr<   rA   )r   r   	auth_infos      r   r   zNetRCAuth.auth_flow   sl     $$33GKK4D4DE	IaLM 04/F/F"1	! 0G 0GOOO, Ms   A'A)r9   r:   c                     dj                  t        |      t        |      f      }t        |      j                         }d| S rC   rE   rH   s        r   r<   zNetRCAuth._build_auth_header   rK   r,   r1   )r%   r&   r'   r(   r)   OptionalrM   r4   r   r*   r   r   rL   rN   r<   r   r,   r   rP   rP      sy    -V__S1 -
 
V-=-=gxQU>U-V 
 S%Z0 <BLLe<T 	 r,   rP   c            	       B   e Zd ZU ej                  ej                  ej
                  ej
                  ej                  ej                  ej                  ej                  dZe	j                  ee	j                  egdf   f   ed<   de	j                  eef   de	j                  eef   ddfdZd	ede	j$                  eedf   fd
Zd	edededdfdZd	edddefdZdededefdZde	j                  eef   defdZde	j4                  e   d	ede	j4                  e   fdZy)
DigestAuth)MD5zMD5-SESSSHAzSHA-SESSzSHA-256zSHA-256-SESSzSHA-512zSHA-512-SESSr   _ALGORITHM_TO_HASH_FUNCTIONr9   r:   r   Nc                 `    t        |      | _        t        |      | _        d | _        d| _        y )Nr   )r	   	_username	_password_last_challenge_nonce_countr>   s      r   r4   zDigestAuth.__init__   s,     "(+!(+FJr,   r   c              #     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<   | y w)Nr@   i  zwww-authenticatezdigest r   )	re   r<   rA   status_codeget_listlower
startswith_parse_challengerf   )r   r   r    auth_headers       r   r   zDigestAuth.auth_flow   s     /3/F/F--0GOOO, !=3&*<HDTDT*T #++445GHK  "--i8 I #44WhT+/+B+BT)),
( s   BC)AC)r    rm   _DigestAuthChallengec                    |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)rs   rt   ru   rv   rw   z(Malformed Digest WWW-Authenticate headerr   )	partitionrj   r   stripsplitr   encodegetrn   KeyErrorr   )r   r   r    rm   scheme_fieldsheader_dictfieldkeyvaluers   rt   ru   rv   rw   excmessages                     r   rl   z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'5IfRU   	C@G9sB	Cs   /A9C) )	D2DD	challengec           
      x   | j                   |j                  j                            dt        dt        f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}dj	                  |      }| j
                  |j                  |j                  | |dj	                  |
|f            |j                  j                         d	}|j&                  r|j&                  |d
<   |rd|d<   ||d<   |	|d<   d| j)                  |      z   S )Ndatar   c                 L     |       j                         j                         S r1   )	hexdigestr|   )r   	hash_funcs    r   rq   z-DigestAuth._build_auth_header.<locals>.digest  s    T?,,.5577r,   rD   s   %08xr   z-sessrx   )r9   rs   rt   urir    ru   rv      authrw   nccnoncezDigest )ra   ru   upperrN   rF   rc   rs   rd   rX   raw_pathmethodr|   rf   _get_client_noncert   rj   endswith_resolve_qoprw   rv   _get_header_value)r   r   r   rq   A1pathA2HA2nc_valuer   HA1rw   digest_data
key_digestformat_argsr   s                  @r   r<   z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C&#ABCC	w?;	5K$??Hfc3GKYY{+
 ____tyy#z):;<",,335
 $-$4$4K!!(K (K$*K!411+>>>r,   nonce_countrt   c                     t        |      j                         }||z  }|t        j                         j                         z  }|t	        j
                  d      z  }t        j                  |      j                         d d j                         S )N      )	rM   r|   timectimeosurandomhashlibsha1r   )r   r   rt   ss       r   r   zDigestAuth._get_client_nonce,  sp    ##%	U
	TZZ\  ""	RZZ]||A((*3B/6688r,   header_fieldsc                     d}d}d}d}t        |j                               D ]8  \  }\  }}|dkD  r|dz  }||vr|n|}	||	j                  |t        |            z  }: |S )N)ru   rw   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   zDigestAuth._get_header_value4  s    6#%!*=+>+>+@!AA~u1u$  11  ( 
 HOOE6%=AAL "B r,   rw   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 authrx   )rer{   NotImplementedErrorr   )r   rw   r   qopsr   s        r   r   zDigestAuth._resolve_qopF  sX     ;xx$d?K= %&VWW*3'1ABGW55r,   )r%   r&   r'   r   md5r   sha256sha512ra   r)   DictrM   r6   rN   __annotations__rL   r4   r   r*   r   r   rl   r<   intr   r   r\   r   r   r,   r   r^   r^      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		6r,   r^   c                   t    e Zd ZU eed<   eed<   eed<   ej                  e   ed<   ej                  e   ed<   y)rn   rs   rt   ru   rv   rw   N)r%   r&   r'   rN   r   rM   r)   r\   r   r,   r   rn   rn   V  s/    LLNOOE""		r,   rn   )r   rS   r   r   r   r)   base64r   urllib.requestr   _exceptionsr   _modelsr   r   _utilsr	   r
   r   TYPE_CHECKINGr   r   r.   r8   rP   r^   
NamedTuplern   r   r,   r   <module>r      s      	 	    * & & - -	X Xv
"4 
"   .   8f6 f6R 6,,  r,   