
    ,hs.                    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     M/var/www/html/Resume-Scraper/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_flowW   s      %%--/!!~~g&t*$}H**nn&&&))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     jj!!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3Hh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   ?    99hx0(82D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3GKK4D4DE	IaLM 04/F/F"1	! 0G 0GOOO, Ms   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GOOO, !=3&*<HDTDT*T #++445GH 	K  "--i8	 #44Wh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!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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4Y5H5H5N5N5PQ		8 YY	HI{{##YY--/67RjT...''(9(99??KQRj$$&//8C&#ABCC	w?;	5K 	63LK ____tyy56",,335
 $-$4$4K!!(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
	TZZ\  ""	RZZ]||A((*3B/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 	BA~u1u$  11  ( 
 HOOE6%=AAL	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    ;xx$d?K= %&VWW*3'1ABGW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    {{KK||LL>>>>	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6P6,, r/   