o
    g>                     @  s   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rGd dlZG dd dZddddZG dd dZdd ZdD ]ZeeeeZeeee eeee qadS )    )annotationsNwraps   )dump_header)parse_dict_header)parse_set_header)quote_header_value   )CallbackDict)	HeaderSetc                   @  s   e Zd ZdZ		d'd(ddZd)ddZd)ddZd*d+ddZd,ddZd-ddZ	e
d.dd Zd/d!d"Zd/d#d$Zd/d%d&ZdS )0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.
    N	auth_typestrdatadict[str, str] | Nonetoken
str | NonereturnNonec                 C  s&   || _ 	 |d u r
i }|| _	 || _d S N)type
parametersr   )selfr   r   r    r   i/var/www/html/portale_awareness/portale-venv/lib/python3.10/site-packages/werkzeug/datastructures/auth.py__init__.   s   zAuthorization.__init__namec                 C     | j |S r   r   getr   r   r   r   r   __getattr__F      zAuthorization.__getattr__c                 C  r   r   r   r!   r   r   r   __getitem__I   r#   zAuthorization.__getitem__keydefaultc                 C     | j ||S r   r   r   r%   r&   r   r   r   r    L      zAuthorization.getboolc                 C  
   || j v S r   r   r   r%   r   r   r   __contains__O      
zAuthorization.__contains__otherobjectc                 C  2   t |tstS |j| jko|j| jko|j| jkS r   )
isinstancer   NotImplementedr   r   r   r   r0   r   r   r   __eq__R      


zAuthorization.__eq__valuete.Self | Nonec              	   C  s   |sdS | d\}}}| }| }|dkr=zt|  d\}}}W n tjtfy4   Y dS w | |||dS d|	dv rL| |t
|dS | |d|S )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   )clsr8   scheme_restr=   r>   r   r   r   from_header\   s   	zAuthorization.from_headerc                 C  sp   | j dkrt| j d| j  d}d| S | jdur+| j   d| j S | j   dt	| j
 S )ziProduce an ``Authorization`` header value representing this data.

        .. versionadded:: 2.0
        r;   r<   utf8zBasic Nr:   )r   rC   	b64encoder=   r>   encoderE   r   titler   r   r   r8   r   r   r   	to_header{   s   


zAuthorization.to_headerc                 C     |   S r   rT   r   r   r   r   __str__      zAuthorization.__str__c                 C     dt | j d|   dS N<r:   >r   __name__rT   rW   r   r   r   __repr__      zAuthorization.__repr__)NN)r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r   r&   r   r   r   r%   r   r   r*   r0   r1   r   r*   r8   r   r   r9   r   r   )r_   
__module____qualname____doc__r   r"   r$   r    r.   r6   classmethodrN   rT   rX   r`   r   r   r   r   r      s    






r   r   r   docr   r   propertyc                   s2   t jdtdd  fdd}t fdd||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                   s(   |d u r|   d  d S t||  < d S r   )popr   rS   r   r   r   
_set_value   s   z!auth_property.<locals>._set_valuec                   s
   |   S r   )r    )xrq   r   r   <lambda>   s   
 zauth_property.<locals>.<lambda>)rl   )warningswarnDeprecationWarningrm   )r   rl   rr   r   rq   r   auth_property   s   
rx   c                      sj  e Zd ZdZ			dQdRdd	ZdSddZedTddZejdUddZedVddZ	e	jdWddZ	edXddZ
e
jdYddZ
dZd[ddZ				d\d]d'd(Zd^d*d+Zd_d,d-Zd`d.d/Zdad1d2Zdb fd3d4Zdcd5d6Zddd7d8Zded;d<Zdfdgd>d?ZedhdAdBZdTdCdDZdTdEdFZdTdGdHZedidJdKZedjdMdNZejdkdPdNZeeZ  ZS )l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.
    Nr   r   valuesr   r   c                   sJ   |d u rt jdtdd d}|  _t| fdd _| _d  _d S )NzvAn auth type must be given as the first parameter. Assuming 'basic' is deprecated and will be removed in Werkzeug 3.0.r   rn   r;   c                         S r   _trigger_on_updaterL   rW   r   r   rt          z*WWWAuthenticate.__init__.<locals>.<lambda>)	ru   rv   rw   rA   _typer   _parameters_token
_on_update)r   r   rz   r   r   rW   r   r      s   

zWWWAuthenticate.__init__r   r   c                 C  s   | j d ur|  |  d S d S r   )r   rW   r   r   r   r}      s   
z"WWWAuthenticate._trigger_on_updater   c                 C     | j S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)r   rW   r   r   r   r      s   zWWWAuthenticate.typer8   c                 C  s   || _ |   d S r   )r   r}   rS   r   r   r   r      s   dict[str, str]c                 C  r   zA dict of parameters for the header. Only one of this or :attr:`token` should
        have a value for a given scheme.
        )r   rW   r   r   r   r         zWWWAuthenticate.parametersc                   s    t | fdd _   d S )Nc                   r{   r   r|   r~   rW   r   r   rt      r   z,WWWAuthenticate.parameters.<locals>.<lambda>)r   r   r}   rS   r   rW   r   r      s   c                 C  r   r   )r   rW   r   r   r   r      r   zWWWAuthenticate.tokenc                 C  s   || _ |   dS )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}   rS   r   r   r   r      s   authentication requiredrealmc                 C  s@   t d d| _t| j t| jd|i d| _|   dS )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.r;   r   N)	ru   rv   r   dictclearr   updater   r}   )r   r   r   r   r   	set_basic  s   zWWWAuthenticate.set_basicauthFnonceqopt.Sequence[str]opaque	algorithmstaler*   c                 C  sx   t d d| _t| j ||d||rdndd}|dur$||d< |dur,||d	< t| j| d| _| 	  dS )
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   r   r   r   Nr   r   )
ru   rv   r   r   r   r   joinr   r   r}   )r   r   r   r   r   r   r   r   r   r   r   
set_digest  s"   
zWWWAuthenticate.set_digestr%   c                 C  r   r   r   r-   r   r   r   r$   @  r#   zWWWAuthenticate.__getitem__c                 C  s2   |d u r|| j v r| j |= n|| j |< |   d S r   r   r}   )r   r%   r8   r   r   r   __setitem__C  s   

zWWWAuthenticate.__setitem__c                 C  s"   || j v r| j |= |   d S d S r   r   r-   r   r   r   __delitem__L  s   
zWWWAuthenticate.__delitem__r   c                 C  s   | | S r   r   r!   r   r   r   r"   Q  rY   zWWWAuthenticate.__getattr__c                   s&   |dv rt  || d S || |< d S )N>   r   r   r   r   )super__setattr__)r   r   r8   	__class__r   r   r   T  s   zWWWAuthenticate.__setattr__c                 C  s
   | |= d S r   r   r!   r   r   r   __delattr__Z  r/   zWWWAuthenticate.__delattr__c                 C  r+   r   r,   r-   r   r   r   r.   ]  r/   zWWWAuthenticate.__contains__r0   r1   c                 C  r2   r   )r3   ry   r4   r   r   r   r5   r   r   r   r6   `  r7   zWWWAuthenticate.__eq__r&   c                 C  r'   r   r   r(   r   r   r   r    j  r)   zWWWAuthenticate.getr9   c                 C  sR   |sdS | d\}}}| }| }d|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
        Nr:   r?   )r@   rA   rB   rI   r   )rJ   r8   rK   rL   rM   r   r   r   rN   m  s   	zWWWAuthenticate.from_headerc                 C  s   | j dur| j  d| j  S | jdkrBg }| j D ]\}}|dv r+t|dd}nt|}|| d|  qdd	| S | j  dt| j S )
zCProduce a ``WWW-Authenticate`` header value representing this data.Nr:   r   >   r   r   r   domainr   F)allow_tokenr?   zDigest r   )	r   r   rR   r   itemsr	   appendr   r   )r   r   r%   r8   r   r   r   rT     s   

zWWWAuthenticate.to_headerc                 C  rU   r   rV   rW   r   r   r   rX     rY   zWWWAuthenticate.__str__c                 C  rZ   r[   r^   rW   r   r   r   r`     ra   zWWWAuthenticate.__repr__set[str]c                   s0   t jdtdd d fdd	}t 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   rn   r8   r   r   r   c                   s(   | sd v r	 d= d S |    jd< d S )Nr   )rT   r   )r8   rW   r   r   	on_update  s
   z&WWWAuthenticate.qop.<locals>.on_updater   N)r8   r   r   r   )ru   rv   rw   r   r   r    )r   r   r   rW   r   r     s   	zWWWAuthenticate.qopbool | Nonec                 C  s0   t jdtdd d| jv r| jd  dkS dS )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   rn   r   trueN)ru   rv   rw   r   rA   rW   r   r   r   r     s   
zWWWAuthenticate.stalebool | str | Nonec                 C  s\   |d u rd| j v r| j d= d S t|tr'tjdtdd |r dnd| j d< d S || j d< d S )Nr   z\Setting the 'stale' property to a boolean is deprecated and will be removed in Werkzeug 3.0.r   rn   r   r   )r   r3   r*   ru   rv   rw   rS   r   r   r   r     s   

)NNN)r   r   rz   r   r   r   )r   r   rg   )r8   r   r   r   )r   r   )r8   r   r   r   )r   r   )r8   r   r   r   )r   )r   r   r   r   )r   NNF)r   r   r   r   r   r   r   r   r   r   r   r*   r   r   )r%   r   r   r   )r%   r   r8   r   r   r   )r%   r   r   r   rb   )r   r   r8   r   r   r   )r   r   r   r   rd   re   r   rc   rf   )r   r   )r   r   )r8   r   r   r   ) r_   rh   ri   rj   r   r}   rm   r   setterr   r   r   r   r$   r   r   r"   r   r   r.   r6   r    rk   rN   rT   rX   r`   r   r   staticmethodrx   __classcell__r   r   r   r   ry      s\    
	
%

	







ry   c                   s   t   fdd}|S )Nc                    s   t jdtd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   rn   )ru   rv   rw   )argskwargsfr   r   wrapper  s   z(_deprecated_dict_method.<locals>.wrapperr   )r   r   r   r   r   _deprecated_dict_method  s   	r   )
__iter__r   copyr   keysrp   popitem
setdefaultr   rz   r   )r   r   rl   r   r   rm   )
__future__r   rC   rF   typingtru   	functoolsr   httpr   r   r   r	   
structuresr   r   TYPE_CHECKINGtyping_extensionster   rx   ry   r   r   getattrr   r   setattrr   r   r   r   <module>   s2    ~  9