
    +h>                    0   d dl m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 ddl	mZ d	d
lmZ d	dlmZ ej"                  rd dlZ G d d      ZdddZ G d d      Zd ZdD ]%  Z e eee            Z eeee        eeee       ' y)    )annotationsNwraps   )dump_header)parse_dict_header)parse_set_header)quote_header_value   )CallbackDict)	HeaderSetc                      e Zd ZdZ	 	 d	 	 	 	 	 	 	 ddZddZddZdddZddZddZ	e
dd	       Zdd
ZddZddZy)Authorizationa  Represents the parts of an ``Authorization`` request header.

    :attr:`.Request.authorization` returns an instance if the header is set.

    An instance can be used with the test :class:`.Client` request methods' ``auth``
    parameter to send the header in test requests.

    Depending on the auth scheme, either :attr:`parameters` or :attr:`token` will be
    set. The ``Basic`` scheme's token is decoded into the ``username`` and ``password``
    parameters.

    For convenience, ``auth["key"]`` and ``auth.key`` both access the key in the
    :attr:`parameters` dict, along with ``auth.get("key")`` and ``"key" in auth``.

    .. versionchanged:: 2.3
        The ``token`` parameter and attribute was added to support auth schemes that use
        a token instead of parameters, such as ``Bearer``.

    .. versionchanged:: 2.3
        The object is no longer a ``dict``.

    .. versionchanged:: 0.5
        The object is an immutable dict.
    Nc                :    || _         	 |i }|| _        	 || _        y N)type
parameterstoken)self	auth_typedatar   s       O/var/www/html/venv/lib/python3.12/site-packages/werkzeug/datastructures/auth.py__init__zAuthorization.__init__.   s2     	R<D	 
	    c                8    | j                   j                  |      S r   r   getr   names     r   __getattr__zAuthorization.__getattr__F       ""4((r   c                8    | j                   j                  |      S r   r   r   s     r   __getitem__zAuthorization.__getitem__I   r!   r   c                :    | j                   j                  ||      S r   r   r   keydefaults      r   r   zAuthorization.getL       ""300r   c                    || j                   v S r   r   r   r&   s     r   __contains__zAuthorization.__contains__O       doo%%r   c                    t        |t              st        S |j                  | j                  k(  xr4 |j                  | j                  k(  xr |j
                  | j
                  k(  S r   )
isinstancer   NotImplementedr   r   r   r   others     r   __eq__zAuthorization.__eq__R   sU    %/!! JJ$))# 4tzz)4  DOO3	
r   c                   |sy|j                  d      \  }}}|j                         }|j                         }|dk(  rC	 t        j                  |      j                         j                  d      \  }}} | |||d      S d|j                  d      v r | |t        |      d      S  | |d|      S # t        j                  t        f$ r Y yw xY w)zParse an ``Authorization`` header value and return an instance, or ``None``
        if the value is empty.

        :param value: The header value to parse.

        .. versionadded:: 2.3
        N basic:)usernamepassword=)	partitionlowerstripbase64	b64decodedecodebinasciiErrorUnicodeErrorrstripr   )clsvaluescheme_restr8   r9   s          r   from_headerzAuthorization.from_header\   s     //#.4zz|W(.(8(8(>(E(E(G(Q(QRU(V%!X vH(KLL$++c""v06== 64&& NNL1 s   6B1 1CCc                   | j                   dk(  rPt        j                  | j                   d| j                   j                               j                  d      }d| S | j                  )| j                   j                          d| j                   S | j                   j                          dt        | j                         S )ziProduce an ``Authorization`` header value representing this data.

        .. versionadded:: 2.0
        r6   r7   utf8zBasic r5   )r   r>   	b64encoder8   r9   encoder@   r   titler   r   r   rF   s     r   	to_headerzAuthorization.to_header{   s    
 99$$==/4==/299;fVn  E7##::!iioo'($**66))//#$Ak$//&B%CDDr   c                "    | j                         S r   rQ   r   s    r   __str__zAuthorization.__str__       ~~r   c                V    dt        |       j                   d| j                          dS N<r5   >r   __name__rQ   rT   s    r   __repr__zAuthorization.__repr__   *    4:&&'q)9(:!<<r   )NN)r   strr   dict[str, str] | Noner   
str | NonereturnNoner   r_   rb   ra   r   r&   r_   r'   ra   rb   ra   r&   r_   rb   boolr2   objectrb   rg   rF   ra   rb   zte.Self | Nonerb   r_   )r\   
__module____qualname____doc__r   r    r#   r   r,   r3   classmethodrJ   rQ   rU   r]    r   r   r   r      sw    8 '+ 	 $ 	
 
0))1&
 ' '<E  =r   r   c                h     t        j                  dt        d        fd}t         fd||      S )a*  A static helper function for Authentication subclasses to add
    extra authentication system properties onto a class::

        class FooAuthenticate(WWWAuthenticate):
            special_realm = auth_property('special_realm')

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0.
    zB'auth_property' is deprecated and will be removed in Werkzeug 3.0.r   
stacklevelc                L    || j                  d        y t        |      | <   y r   )popr_   )r   rF   r   s     r   
_set_valuez!auth_property.<locals>._set_value   s#    =HHT4 UDJr   c                &    | j                        S r   )r   )xr   s    r   <lambda>zauth_property.<locals>.<lambda>   s    aeeDk r   )doc)warningswarnDeprecationWarningproperty)r   rz   rv   s   `  r   auth_propertyr      s1     MML$ ):3??r   c                      e Zd ZdZ	 	 	 d	 	 	 	 	 ddZddZedd       Zej                  d d       Zed!d       Z	e	j                  d"d       Z	ed#d       Z
e
j                  d$d	       Z
d%d&d
Z	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZd)dZd*dZd+dZd,dZd- fdZd.dZd/dZd0dZd1d2dZed3d       ZddZddZddZed4d       Zed5d       Zej                  d6d       Z ee      Z xZS )7WWWAuthenticatea  Represents the parts of a ``WWW-Authenticate`` response header.

    Set :attr:`.Response.www_authenticate` to an instance of list of instances to set
    values for this header in the response. Modifying this instance will modify the
    header value.

    Depending on the auth scheme, either :attr:`parameters` or :attr:`token` should be
    set. The ``Basic`` scheme will encode ``username`` and ``password`` parameters to a
    token.

    For convenience, ``auth["key"]`` and ``auth.key`` both act on the :attr:`parameters`
    dict, and can be used to get, set, or delete parameters. ``auth.get("key")`` and
    ``"key" in auth`` are also provided.

    .. versionchanged:: 2.3
        The ``token`` parameter and attribute was added to support auth schemes that use
        a token instead of parameters, such as ``Bearer``.

    .. versionchanged:: 2.3
        The object is no longer a ``dict``.

    .. versionchanged:: 2.3
        The ``on_update`` parameter was removed.
    c                     |t        j                  dt        d       d}|j                          _        t        | fd       _        | _        d  _        y )NzvAn auth type must be given as the first parameter. Assuming 'basic' is deprecated and will be removed in Werkzeug 3.0.r   rr   r6   c                $    j                         S r   _trigger_on_updaterH   r   s    r   ry   z*WWWAuthenticate.__init__.<locals>.<lambda>   s    d557 r   )	r{   r|   r}   r<   _typer   _parameters_token
_on_update)r   r   valuesr   s   `   r   r   zWWWAuthenticate.__init__   s[     MMC"	  I__&
+77,
 FJr   c                @    | j                   | j                  |        y y r   )r   rT   s    r   r   z"WWWAuthenticate._trigger_on_update   s    ??&OOD! 'r   c                    | j                   S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)r   rT   s    r   r   zWWWAuthenticate.type   s     zzr   c                2    || _         | j                          y r   )r   r   rP   s     r   r   zWWWAuthenticate.type   s    
!r   c                    | j                   S zA dict of parameters for the header. Only one of this or :attr:`token` should
        have a value for a given scheme.
        )r   rT   s    r   r   zWWWAuthenticate.parameters   s    
 r   c                N     t        | fd       _         j                          y )Nc                $    j                         S r   r   r   s    r   ry   z,WWWAuthenticate.parameters.<locals>.<lambda>   s    T446 r   )r   r   r   rP   s   ` r   r   zWWWAuthenticate.parameters   s$    '6
 	!r   c                    | j                   S r   )r   rT   s    r   r   zWWWAuthenticate.token   s    
 {{r   c                2    || _         | j                          y)zA token for the header. Only one of this or :attr:`parameters` should have a
        value for a given scheme.

        .. versionadded:: 2.3
        N)r   r   rP   s     r   r   zWWWAuthenticate.token   s     !r   c                    t        j                  d       d| _        t        j	                  | j
                         t        j                  | j
                  d|i       d| _        | j                          y)zClear any existing data and set a ``Basic`` challenge.

        .. deprecated:: 2.3
            Will be removed in Werkzeug 3.0. Create and assign an instance instead.
        zpThe 'set_basic' method is deprecated and will be removed in Werkzeug 3.0. Create and assign an instance instead.r6   realmN)	r{   r|   r   dictclearr   updater   r   )r   r   s     r   	set_basiczWWWAuthenticate.set_basic  s^     	6	
 


4??#OOe	
 !r   c                8   t        j                  d       d| _        t        j	                  | j
                         ||dj                  |      |rdndd}|||d<   |||d	<   t        j                  | j
                  |       d| _        | j                          y)
zClear any existing data and set a ``Digest`` challenge.

        .. deprecated:: 2.3
            Will be removed in Werkzeug 3.0. Create and assign an instance instead.
        zqThe 'set_digest' method is deprecated and will be removed in Werkzeug 3.0. Create and assign an instance instead.digest, TRUEFALSE)r   nonceqopstaleNopaque	algorithm)
r{   r|   r   r   r   r   joinr   r   r   )r   r   r   r   r   r   r   r   s           r   
set_digestzWWWAuthenticate.set_digest  s     	6	
 


4??#99S>$V'	

 #)Jx  &/J{#DOOZ0!r   c                8    | j                   j                  |      S r   r   r+   s     r   r#   zWWWAuthenticate.__getitem__@  s    ""3''r   c                ~    ||| j                   v r| j                   |= n|| j                   |<   | j                          y r   r   r   )r   r&   rF   s      r   __setitem__zWWWAuthenticate.__setitem__C  s9    =doo%OOC(#(DOOC !r   c                \    || j                   v r| j                   |= | j                          y y r   r   r+   s     r   __delitem__zWWWAuthenticate.__delitem__L  s+    $//!$##% "r   c                    | |   S r   rp   r   s     r   r    zWWWAuthenticate.__getattr__Q  s    Dzr   c                :    |dv rt         |   ||       y || |<   y )N>   r   r   r   r   )super__setattr__)r   r   rF   	__class__s      r   r   zWWWAuthenticate.__setattr__T  s$    CCGe,DJr   c                
    | |= y r   rp   r   s     r   __delattr__zWWWAuthenticate.__delattr__Z  s	    Jr   c                    || j                   v S r   r*   r+   s     r   r,   zWWWAuthenticate.__contains__]  r-   r   c                    t        |t              st        S |j                  | j                  k(  xr4 |j                  | j                  k(  xr |j
                  | j
                  k(  S r   )r/   r   r0   r   r   r   r1   s     r   r3   zWWWAuthenticate.__eq__`  sU    %1!! JJ$))# 4tzz)4  DOO3	
r   c                :    | j                   j                  ||      S r   r   r%   s      r   r   zWWWAuthenticate.getj  r(   r   c                    |sy|j                  d      \  }}}|j                         }|j                         }d|j                  d      v r | |t	        |      d      S  | |d|      S )zParse a ``WWW-Authenticate`` header value and return an instance, or ``None``
        if the value is empty.

        :param value: The header value to parse.

        .. versionadded:: 2.3
        Nr5   r:   )r;   r<   r=   rD   r   )rE   rF   rG   rH   rI   s        r   rJ   zWWWAuthenticate.from_headerm  sk     //#.4zz|$++c""v06== 64&&r   c                   | j                   )| j                  j                          d| j                    S | j                  dk(  rkg }| j                  j	                         D ]8  \  }}|dv rt        |d      }nt        |      }|j                  | d|        : ddj                  |       S | j                  j                          dt        | j                         S )	zCProduce a ``WWW-Authenticate`` header value representing this data.r5   r   >   r   r   r   domainr   F)allow_tokenr:   zDigest r   )	r   r   rO   r   itemsr
   appendr   r   )r   r   r&   rF   s       r   rQ   zWWWAuthenticate.to_header  s    ::!iioo'($**6699 E"oo335 /
UGG.u%HE.u5EuAeW-./ TYYu-.//))//#$Ak$//&B%CDDr   c                "    | j                         S r   rS   rT   s    r   rU   zWWWAuthenticate.__str__  rV   r   c                V    dt        |       j                   d| j                          dS rX   r[   rT   s    r   r]   zWWWAuthenticate.__repr__  r^   r   c                     t        j                  dt        d       d fd}t         j                  j                  d      |      S )zThe ``qop`` parameter as a set.

        .. deprecated:: 2.3
            Will be removed in Werkzeug 3.0. It will become the same as other
            parameters, returning a string.
        zThe 'qop' property is deprecated and will be removed in Werkzeug 3.0. It will become the same as other parameters, returning a string.r   rr   c                T    | sdv rd= y | j                         j                  d<   y )Nr   )rQ   r   )rF   r   s    r   	on_updatez&WWWAuthenticate.qop.<locals>.on_update  s,    D=U%*__%6DOOE"r   r   )rF   r   rb   rc   )r{   r|   r}   r	   r   r   )r   r   s   ` r   r   zWWWAuthenticate.qop  s@     	P		
	7   3 3E :IFFr   c                    t        j                  dt        d       d| j                  v r | j                  d   j	                         dk(  S y)zThe ``stale`` parameter as a boolean.

        .. deprecated:: 2.3
            Will be removed in Werkzeug 3.0. It will become the same as other
            parameters, returning a string.
        zThe 'stale' property is deprecated and will be removed in Werkzeug 3.0. It will become the same as other parameters, returning a string.r   rr   r   trueN)r{   r|   r}   r   r<   rT   s    r   r   zWWWAuthenticate.stale  sJ     	P		
 doo%??7+113v==r   c                    |d| j                   v r| j                   d= y t        |t              r0t        j                  dt
        d       |rdnd| j                   d<   y || j                   d<   y )Nr   z\Setting the 'stale' property to a boolean is deprecated and will be removed in Werkzeug 3.0.r   rr   r   r   )r   r/   rg   r{   r|   r}   rP   s     r   r   zWWWAuthenticate.stale  se    =$//)OOG,eT"MM,"	 27vGDOOG$',DOOG$r   )NNN)r   ra   r   r`   r   ra   )rb   rc   rk   )rF   r_   rb   rc   )rb   dict[str, str])rF   r   rb   rc   )rb   ra   )rF   ra   rb   rc   )zauthentication required)r   r_   rb   rc   ))authNNF)r   r_   r   r_   r   zt.Sequence[str]r   ra   r   ra   r   rg   rb   rc   )r&   r_   rb   ra   )r&   r_   rF   ra   rb   rc   )r&   r_   rb   rc   rd   )r   r_   rF   ra   rb   rc   )r   r_   rb   rc   rf   rh   r   re   rj   )rb   zset[str])rb   zbool | None)rF   zbool | str | Nonerb   rc   ) r\   rl   rm   rn   r   r   r~   r   setterr   r   r   r   r#   r   r   r    r   r   r,   r3   r   ro   rJ   rQ   rU   r]   r   r   staticmethodr   __classcell__)r   s   @r   r   r      s   6 !%(, 	KK &K 	K,"   
[[" "     " "   \\" "".  )! $#"#" #" 	#"
 #" #" #" 
#"J("&
&
1 ' ',E( = G G2  & \\- -$ !/Mr   r   c                .     t                fd       }|S )Nc                 L    t        j                  dt        d        | i |S )NzTreating 'Authorization' and 'WWWAuthenticate' as a dict is deprecated and will be removed in Werkzeug 3.0. Use the 'parameters' attribute instead.r   rr   )r{   r|   r}   )argskwargsfs     r   wrapperz(_deprecated_dict_method.<locals>.wrapper  s-    X		
 $!&!!r   r   )r   r   s   ` r   _deprecated_dict_methodr     s     
1X" " Nr   )
__iter__r   copyr   keysru   popitem
setdefaultr   r   r   )r   r_   rz   ra   rb   r~   )
__future__r   r>   rA   typingtr{   	functoolsr   httpr   r   r	   r
   
structuresr   r   TYPE_CHECKINGtyping_extensionster   r   r   r   r   getattrr   r   setattrrp   r   r   <module>r      s    "       $ # % $ !??"{= {=|@2t0 t0n	 &D 	 d 34AM4#OT1%&r   