
    'gG'                        d dl mZ d dlZd dlZd dlm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 ej                  rd dlZ G d	 d
      Z G d d      Zy)    )annotationsN   )dump_header)parse_dict_header)quote_header_value   )CallbackDictc                      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       T/var/www/html/knws/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__C       ""4((r   c                8    | j                   j                  |      S r   r   r   s     r   __getitem__zAuthorization.__getitem__F   r   r   c                :    | j                   j                  ||      S r   r   r   keydefaults      r   r   zAuthorization.getI       ""300r   c                    || j                   v S r   r   r   r"   s     r   __contains__zAuthorization.__contains__L       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__O   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_restr4   r5   s          r   from_headerzAuthorization.from_headerY   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
        r2   r3   asciizBasic r1   )r   r:   	b64encoder4   r5   encoder<   r   titler   r   r   rB   s     r   	to_headerzAuthorization.to_headerx   s    
 99$$==/4==/299;fWo  E7##::!iioo'($**66))//#$Ak$//&B%CDDr   c                "    | j                         S r   rM   r   s    r   __str__zAuthorization.__str__       ~~r   c                V    dt        |       j                   d| j                          dS N<r1   >r   __name__rM   rP   s    r   __repr__zAuthorization.__repr__   *    4:&&'q)9(:!<<r   NN)r   strr   dict[str, str | None] | Noner   
str | NonereturnNoner   r\   r_   r^   r   r"   r\   r#   r^   r_   r^   r"   r\   r_   boolr.   objectr_   rd   rB   r^   r_   zte.Self | Noner_   r\   )rX   
__module____qualname____doc__r   r   r   r   r(   r/   classmethodrF   rM   rQ   rY    r   r   r   r      sw    8 .2 	 + 	
 
0))1&
 ' '<E  =r   r   c                  X    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
Zd!dZd"dZd#dZd$ fdZd%dZd&dZd'dZd(d)dZed*d       ZddZddZddZ xZS )+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                          _        t        | fd       _        | _        d  _        y )Nc                $    j                         S r   _trigger_on_updaterD   r   s    r   <lambda>z*WWWAuthenticate.__init__.<locals>.<lambda>   s    d557 r   )r8   _typer	   _parameters_token
_on_update)r   r   valuesr   s   `   r   r   zWWWAuthenticate.__init__   s6     __&
2>73
 IMr   c                @    | j                   | j                  |        y y r   )ry   rP   s    r   rs   z"WWWAuthenticate._trigger_on_update   s    ??&OOD! 'r   c                    | j                   S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)rv   rP   s    r   r   zWWWAuthenticate.type   s     zzr   c                2    || _         | j                          y r   )rv   rs   rL   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.
        )rw   rP   s    r   r   zWWWAuthenticate.parameters   s    
 r   c                N     t        | fd       _         j                          y )Nc                $    j                         S r   rr   rt   s    r   ru   z,WWWAuthenticate.parameters.<locals>.<lambda>   s    9P9P9R r   )r	   rw   rs   rL   s   ` r   r   zWWWAuthenticate.parameters   s    '/RS!r   c                    | j                   S r   )rx   rP   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)rx   rs   rL   s     r   r   zWWWAuthenticate.token   s     !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   rs   )r   r"   rB   s      r   __setitem__zWWWAuthenticate.__setitem__   s9    =doo%OOC(#(DOOC !r   c                \    || j                   v r| j                   |= | j                          y y r   r   r'   s     r   __delitem__zWWWAuthenticate.__delitem__   s+    $//!$##% "r   c                    | |   S r   rm   r   s     r   r   zWWWAuthenticate.__getattr__   s    Dzr   c                :    |dv rt         |   ||       y || |<   y )N>   rv   rx   ry   rw   )super__setattr__)r   r   rB   	__class__s      r   r   zWWWAuthenticate.__setattr__   s$    CCGe,DJr   c                
    | |= y r   rm   r   s     r   __delattr__zWWWAuthenticate.__delattr__   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+   ro   r,   r   r   r   r-   s     r   r/   zWWWAuthenticate.__eq__  sU    %1!! JJ$))# 4tzz)4  DOO3	
r   c                :    | j                   j                  ||      S r   r   r!   s      r   r   zWWWAuthenticate.get  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
        Nr1   r6   )r7   r8   r9   r@   r   )rA   rB   rC   rD   rE   s        r   rF   zWWWAuthenticate.from_header  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.r1   digest>   qopnoncerealmdomainopaqueF)allow_tokenr6   zDigest z, )	r   r   rK   r   itemsr   appendjoinr   )r   r   r"   rB   s       r   rM   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   rO   rP   s    r   rQ   zWWWAuthenticate.__str__9  rR   r   c                V    dt        |       j                   d| j                          dS rT   rW   rP   s    r   rY   zWWWAuthenticate.__repr__<  rZ   r   r[   )r   r\   rz   r]   r   r^   )r_   r`   rh   )rB   r\   r_   r`   )r_   zdict[str, str | None])rB   zdict[str, str]r_   r`   )r_   r^   )rB   r^   r_   r`   )r"   r\   r_   r^   )r"   r\   rB   r^   r_   r`   )r"   r\   r_   r`   ra   )r   r\   rB   r^   r_   r`   )r   r\   r_   r`   rc   re   r   rb   rg   )rX   ri   rj   rk   r   rs   propertyr   setterr   r   r   r   r   r   r   r   r(   r/   r   rl   rF   rM   rQ   rY   __classcell__)r   s   @r   ro   ro      s   8 04 	NN -N 	N"   
[[" "     " "   \\" "("&
&
1 ' ',E( =r   ro   )
__future__r   r:   r=   collections.abcabccabctypingthttpr   r   r   
structuresr	   TYPE_CHECKINGtyping_extensionster   ro   rm   r   r   <module>r      sC    "      $ % $??"{= {=|n= n=r   