
    zi.                     D   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	 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dS )    N)	b64encode)parse_http_list   )ProtocolError)Cookies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dS )	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   |V  dS )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     V/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/httpx/_auth.py	auth_flowzAuth.auth_flow!   s      ,     c              #     K   | j         r|                                 |                     |          }t          |          }	 |V }| j        r|                                 	 |                    |          }n# t          $ r Y dS w xY wH)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.
        TN)requires_request_bodyreadr   nextrequires_response_bodysendStopIterationr   r   flowresponses       r   sync_auth_flowzAuth.sync_auth_flow9   s       % 	LLNNN~~g&&t**	$}}H*  ))H--    	s   #A9 9
BBc                0  K   | j         r|                                 d{V  |                     |          }t          |          }	 |W V }| j        r|                                 d{V  	 |                    |          }n# t          $ r Y dS w xY wO)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_flowR   s       % 	"--//!!!!!!!~~g&&t**	$}}}H* 'nn&&&&&&&&&))H--    	s   0B 
BB)__name__
__module____qualname____doc__r   r   r   typing	Generatorr	   r   r#   AsyncGeneratorr&   r   r   r   r   r      s        
 
 "" V-=gxQU>U-V    0		'8T1	2   2		w0	1     r   r   c                   j    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
dS )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                     || _         d S N_func)r   r0   s     r   __init__zFunctionAuth.__init__r   s    


r   r   c              #   8   K   |                      |          V  d S r2   r3   r   s     r   r   zFunctionAuth.auth_flowu   s$      jj!!!!!!!r   )r'   r(   r)   r*   r+   Callabler   r5   r,   r	   r   r   r   r   r/   r/   l   s         
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         dd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dS )
	BasicAuthzy
    Allows the 'auth' argument to be passed as a (username, password) pair,
    and uses HTTP Basic authentication.
    usernamepasswordr   Nc                 <    |                      ||          | _        d S r2   )_build_auth_header_auth_headerr   r:   r;   s      r   r5   zBasicAuth.__init__   s"     !33HhGGr   r   c              #   0   K   | j         |j        d<   |V  d S )NAuthorization)r>   headersr   s     r   r   zBasicAuth.auth_flow   s"      +/+<(r   c                     d                     t          |          t          |          f          }t          |                                          }d| S N   :zBasic joinr
   r   decoder   r:   r;   userpasstokens        r   r=   zBasicAuth._build_auth_header   Q     99hx00(82D2DEFF(##**,,r   )r'   r(   r)   r*   r+   Unionstrbytesr5   r   r,   r	   r   r=   r   r   r   r9   r9   y   s         
HS%Z0H<BLe<TH	H H H H
 V-=gxQU>U-V     S%Z0 <BLe<T 	           r   r9   c                       e Zd ZdZddej        e         dd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dS )	NetRCAuthzT
    Use a 'netrc' file to lookup basic auth credentials based on the url host.
    Nfiler   c                 B    dd l }|                     |          | _        d S )Nr   )netrc_netrc_info)r   rR   rT   s      r   r5   zNetRCAuth.__init__   s'     	 ;;t,,r   r   c              #      K   | j                             |j        j                  }||d         s|V  d S |                     |d         |d                   |j        d<   |V  d S )N   r   )r:   r;   rA   )rU   authenticatorsurlhostr=   rB   )r   r   	auth_infos      r   r   zNetRCAuth.auth_flow   s}      $33GK4DEE	IaLMMMMM 04/F/F"1	! 0G 0 0GOO, MMMMMr   r:   r;   c                     d                     t          |          t          |          f          }t          |                                          }d| S rD   rF   rI   s        r   r=   zNetRCAuth._build_auth_header   rL   r   r2   )r'   r(   r)   r*   r+   OptionalrN   r5   r   r,   r	   r   rM   rO   r=   r   r   r   rQ   rQ      s         - -V_S1 -T - - - -
 
V-=gxQU>U-V 
 
 
 
 S%Z0 <BLe<T 	           r   rQ   c            	          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	j        e         d	ede	j        e         fdZdS )
DigestAuth)MD5zMD5-SESSSHAzSHA-SESSzSHA-256zSHA-256-SESSzSHA-512zSHA-512-SESSr   _ALGORITHM_TO_HASH_FUNCTIONr:   r;   r   Nc                 r    t          |          | _        t          |          | _        d | _        d| _        d S )Nr   )r
   	_username	_password_last_challenge_nonce_countr?   s      r   r5   zDigestAuth.__init__   s8     "(++!(++FJr   r   c              #     K   | j         r#|                     || j                   |j        d<   |V }|j        dk    s	d|j        vrd S |j                            d          D ]+}|                                                    d          r n,d S |                     |||          | _         d| _        |                     || j                   |j        d<   |j	        r(t          |j	                                      |           |V  d S )NrA   i  zwww-authenticatezdigest r   r   )rf   r=   rB   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 0GOO, !==3&&*<HDT*T*T F#+445GHH 	 	K  ""--i88 
 F#44WhTT+/+B+BT),
 ,
(  	IH$%%777HHHr   r"   rq   _DigestAuthChallengec                    |                     d          \  }}}|                                dk    sJ i }t          |          D ]?}|                                                    dd          \  }	}
t          |
          ||	<   @	 |d                                         }|d                                         }|                    dd          }d	|v r|d	                                         nd
}d|v r|d                                         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)rw   rx   ry   rz   r{   z(Malformed Digest WWW-Authenticate headerri   )	partitionrl   r   stripsplitr   encodegetrr   KeyErrorr   )r   r   r"   rq   scheme_fieldsheader_dictfieldkeyvaluerw   rx   ry   rz   r{   excmessages                     r   rn   zDigestAuth._parse_challenge   s{    (11#666 ||~~))))-/$V,, 	. 	.E,,S!44JC&u~~K	C(//11E(//11E#U;;I7?;7N7N[*11333TXF16+1E1E+e$++---4C'5IfRU     	C 	C 	C@G999sB	Cs   BD$ $
E.EE	challengec           
         | j         |j                                                 dt          dt          ffd}d                    | j        |j        | j        f          }|j        j	        }d                    |j
                                        |f          } ||          }d| j        z  }|                     | j        |j                  }	| xj        dz  c_         ||          }
|j                                                            d          r& |d                    |
|j        |	f                    }
|                     |j        |          }||
|j        |g}n|j        ||	||g}d                    |          }| j        |j        |j        | |d                    |
|f                    |j                                        d	}|j        r
|j        |d
<   |rd|d<   ||d<   |	|d<   d|                     |          z   S )Ndatar   c                 b     |                                                                            S r2   )	hexdigestr   )r   	hash_funcs    r   ru   z-DigestAuth._build_auth_header.<locals>.digest  s)    9T??,,..55777r   rE   s   %08xr   z-sessri   )r:   rw   rx   urir"   ry   rz      authr{   nccnoncezDigest )rb   ry   upperrO   rG   rd   rw   re   rY   raw_pathmethodr   rg   _get_client_noncerx   rl   endswith_resolve_qopr{   rz   _get_header_value)r   r   r   ru   A1pathA2HA2nc_valuer   HA1r{   digest_data
key_digestformat_argsr   s                  @r   r=   zDigestAuth._build_auth_header  s5    4Y5H5N5N5P5PQ		8 	85 	8 	8 	8 	8 	8 	8 YY	HII{#YY--//677fRjjT..''(99?KKQfRjj$$&&//88 	D&C&#ABBCCC	w??;	5KK$?Hfc3GKYY{++
 __tyy#z):;;<<",3355
 
  	5$-$4K! 	+!(K (K$*K!411+>>>>r   nonce_countrx   c                 L   t          |                                          }||z  }|t          j                                                    z  }|t	          j        d          z  }t          j        |                                          d d                                         S )N      )	rN   r   timectimeosurandomhashlibsha1r   )r   r   rx   ss       r   r   zDigestAuth._get_client_nonce1  s    ##%%	U
	TZ\\  """	RZ]]|A((**3B3/66888r   header_fieldsc                     d}d}d}d}t          |                                          D ]A\  }\  }}|dk    r|dz  }||vr|n|}	||	                    |t          |                    z  }B|S )N)ry   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   zDigestAuth._get_header_value9  s    6#%!*=+>+>+@+@!A!A 	B 	BA~u1uu$  111  ( 
 HOOE6%==AAALLr   r{   c                     |d S t          j        d|          }d|v rdS |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   r{   r   qopsr   s        r   r   zDigestAuth._resolve_qopK  sl     ;4x$$d??7K=  %&VWWWB3BBBGW5555r   )r'   r(   r)   r   md5r   sha256sha512rb   r+   DictrN   r7   rO   __annotations__rM   r5   r   r,   r	   r   rn   r=   intr   r   r]   r   r   r   r   r_   r_      s        {K|L>>	X 	XS&/5'7BR2S-S!T 	 	 	S%Z0<BLe<T	    V-=gxQU>U-V    >CC*2CADC	C C C C>-?-?+A-?	-? -? -? -?^9S 9 95 9 9 9 9v{3:/F 3    $6?5)64;6		6 6 6 6 6 6r   r_   c                   n    e Zd ZU eed<   eed<   eed<   ej        e         ed<   ej        e         ed<   dS )rr   rw   rx   ry   rz   r{   N)r'   r(   r)   rO   r   rN   r+   r]   r   r   r   rr   rr   [  sS         LLLLLLNNNOE""""		r   rr   )r   r   r   r   r+   base64r   urllib.requestr   _exceptionsr   _modelsr   r   r	   _utilsr
   r   r   TYPE_CHECKINGr   r   r/   r9   rQ   r_   
NamedTuplerr   r   r   r   <module>r      s    				 				         * * * * * * & & & & & & / / / / / / / / / / - - - - - - - - - -	 X X X X X X X Xv
" 
" 
" 
" 
"4 
" 
" 
"               .               @h6 h6 h6 h6 h6 h6 h6 h6V         6,          r   