
    Wh(                     
   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  G d d	          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)RequestResponse)to_bytesto_strunquotec                       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     Q/var/www/html/movieo_spanner_bot/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_flow6   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_flowO   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   r.   s     r   __init__zFunctionAuth.__init__o   s    


r   r   c              #   8   K   |                      |          V  d S r0   r1   r   s     r   r   zFunctionAuth.auth_flowr   s$      jj!!!!!!!r   )r%   r&   r'   r(   r)   Callabler   r3   r*   r   r   r   r   r   r-   r-   i   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         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passwordc                 <    |                      ||          | _        d S r0   )_build_auth_header_auth_headerr   r8   r9   s      r   r3   zBasicAuth.__init__|   s"     !33HhGGr   r   r   Nc              #   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   r8   r9   userpasstokens        r   r;   zBasicAuth._build_auth_header   sQ     99hx00(82D2DEFF(##**,,r   )r%   r&   r'   r(   r)   Unionstrbytesr3   r   r*   r   r   r;   r   r   r   r7   r7   v   s         
HS%Z0H<BLe<TH H H H
 V-=gxQU>U-V     S%Z0 <BLe<T 	           r   r7   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        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-SESS_ALGORITHM_TO_HASH_FUNCTIONr8   r9   r   Nc                 V    t          |          | _        t          |          | _        d S r0   )r	   	_username	_passwordr=   s      r   r3   zDigestAuth.__init__   s&     "(++!(++r   r   c              #   @  K   |V }|j         dk    s	d|j        vrd S |j                            d          D ]+}|                                                    d          r n,d S |                     |||          }|                     ||          |j        d<   |V  d S )Ni  zwww-authenticatezdigest r?   )status_coder@   get_listlower
startswith_parse_challenger;   )r   r   r    auth_header	challenges        r   r   zDigestAuth.auth_flow   s       ==3&&*<HDT*T*T F#+445GHH 	 	K  ""--i88 
 F))'8[II	+/+B+B7I+V+V(r   r    rX   _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	algorithmrL   opaqueNqop)r_   r`   ra   rb   rc   z(Malformed Digest WWW-Authenticate headerr   )	partitionrU   r   stripsplitr   encodegetrZ   KeyErrorr   )r   r   r    rX   scheme_fieldsheader_dictfieldkeyvaluer_   r`   ra   rb   rc   excmessages                     r   rW   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rY   c           
         | j         |j                 dt          dt          ffd}d                    | j        |j        | j        f          }|j        j        }d                    |j	        
                                |f          } ||          }d}d|z  }	|                     ||j                  }
 ||          }|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 r0   )	hexdigestrh   )ru   	hash_funcs    r   r]   z-DigestAuth._build_auth_header.<locals>.digest   s)    9T??,,..55777r   rB   r   s   %08xz-sessrd   )r8   r_   r`   urir    ra   rb      authrc   nccnoncezDigest )rN   ra   rI   rC   rP   r_   rQ   urlraw_pathmethodrh   _get_client_noncer`   rU   endswith_resolve_qoprc   rb   _get_header_value)r   r   rY   r]   A1pathA2HA2nonce_countnc_valuer|   HA1rc   digest_data
key_digestformat_argsrx   s                   @r   r;   zDigestAuth._build_auth_header   s    4Y5HI		8 	85 	8 	8 	8 	8 	8 	8 YY	HII{#YY--//677fRjj[(''Y_EE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   r   r`   c                 L   t          |                                          }||z  }|t          j                                                    z  }|t	          j        d          z  }t          j        |                                          d d                                         S )N      )	rH   rh   timectimeosurandomhashlibsha1rw   )r   r   r`   ss       r   r   zDigestAuth._get_client_nonce  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)ra   rc   r{   z{}="{}"z{}={} r   z, )	enumerateitemsformatr
   )
r   r   NON_QUOTED_FIELDSQUOTED_TEMPLATENON_QUOTED_TEMPLATEheader_valueiro   rq   templates
             r   r   zDigestAuth._get_header_value	  s    6#%!*=+>+>+@+@!A!A 	B 	BA~u1uu$  111  ( 
 HOOE6%==AAALLr   rc   c                     |d S t          j        d|          }d|v rdS |dgk    rt          d          d|d}t          ||          )Ns   , ?rz   s   auth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authrd   )rerg   NotImplementedErrorr   )r   rc   r   qopsrs   s        r   r   zDigestAuth._resolve_qop  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sha512rN   r)   DictrH   r5   __annotations__rG   rI   r3   r   r*   r   r   rW   r;   intr   r   Optionalr   r   r   r   rK   rK      s        {K|L>>	F 	FS&/-A!B 	 	 	,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   rK   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 )rZ   r_   r`   ra   rb   rc   N)r%   r&   r'   rI   r   rH   r)   r   r   r   r   rZ   rZ   +  sS         LLLLLLNNNOE""""		r   rZ   )r   r   r   r   r)   base64r   urllib.requestr   _exceptionsr   _modelsr   r   _utilsr	   r
   r   r   r-   r7   rK   
NamedTuplerZ   r   r   r   <module>r      s    				 				         * * * * * * & & & & & & & & & & & & & & - - - - - - - - - -X X X X X X X Xv
" 
" 
" 
" 
"4 
" 
" 
"               .[6 [6 [6 [6 [6 [6 [6 [6|         6,          r   