a
    !f>                     @  s   d dl m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rd dlZG dd dZddd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 qd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dddd	Zddd
ddZddd
ddZd&ddddddZdddddZdddddZ	e
dddddZdddd Zddd!d"Zddd#d$ZdS )'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strdict[str, str] | None
str | NoneNone)	auth_typedatatokenreturnc                 C  s"   || _ |d u ri }|| _|| _d S N)type
parametersr   )selfr   r   r    r   ]/var/www/html/python-backend/venv/lib/python3.9/site-packages/werkzeug/datastructures/auth.py__init__-   s    zAuthorization.__init__namer   c                 C  s   | j |S r   r   getr   r   r   r   r   __getattr__E   s    zAuthorization.__getattr__c                 C  s   | j |S r   r   r!   r   r   r   __getitem__H   s    zAuthorization.__getitem__keydefaultr   c                 C  s   | j ||S r   r   r   r%   r&   r   r   r   r    K   s    zAuthorization.getboolr%   r   c                 C  s
   || j v S r   r   r   r%   r   r   r   __contains__N   s    zAuthorization.__contains__objectotherr   c                 C  s2   t |tstS |j| jko0|j| jko0|j| jkS r   )
isinstancer   NotImplementedr   r   r   r   r/   r   r   r   __eq__Q   s    


zAuthorization.__eq__te.Self | Nonevaluer   c                 C  s   |sdS | d\}}}| }| }|dkrtzt|  d\}}}W n tyb   Y dS 0 | |||dS d|dv r| |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UnicodeErrorrstripr   )clsr6   scheme_restr:   r;   r   r   r   from_header[   s    	zAuthorization.from_headerr   c                 C  sp   | j dkr6t| j d| j  d}d| S | jdurV| j   d| j S | j   dt	| j
 S )ziProduce an ``Authorization`` header value representing this data.

        .. versionadded:: 2.0
        r8   r9   utf8zBasic Nr7   )r   r@   	b64encoder:   r;   encoderB   r   titler   r   r   r6   r   r   r   	to_headerz   s    


zAuthorization.to_headerc                 C  s   |   S r   rP   r   r   r   r   __str__   s    zAuthorization.__str__c                 C  s   dt | j d|   dS N<r7   >r   __name__rP   rR   r   r   r   __repr__   s    zAuthorization.__repr__)NN)N)rX   
__module____qualname____doc__r   r"   r#   r    r,   r3   classmethodrI   rP   rS   rY   r   r   r   r   r      s     
r   r   r   property)r   docr   c                   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  nt||  < d S r   )popr   rO   r   r   r   
_set_value   s    z!auth_property.<locals>._set_valuec                   s
   |   S r   )r    )xrc   r   r   <lambda>       zauth_property.<locals>.<lambda>)r_   )warningswarnDeprecationWarningr^   )r   r_   rd   r   rc   r   auth_property   s    
rk   c                	      s  e Zd ZdZdMddddddZdd	d
dZedd	ddZejdddddZedd	ddZ	e	jdddddZ	edd	ddZ
e
jdddddZ
dNdddddZdOdddddddd d!d"Zddd#d$d%Zdddd&d'd(Zddd#d)d*Zddd+d,d-Zdddd. fd/d0Zddd+d1d2Zddd#d3d4Zd5dd6d7d8ZdPdddd9d:d;Zedd<dd=d>Zdd	d?d@Zdd	dAdBZdd	dCdDZedEd	dFdGZedHd	dIdJZejdKdddLdJZeeZ  ZS )Q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   )r   valuesr   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   r`   r8   c                   s      S r   _trigger_on_updaterG   rR   r   r   rf      rg   z*WWWAuthenticate.__init__.<locals>.<lambda>)	rh   ri   rj   r>   _typer   _parameters_token
_on_update)r   r   rm   r   r   rR   r   r      s    
zWWWAuthenticate.__init__r   rJ   c                 C  s   | j d ur|  |  d S r   )rt   rR   r   r   r   ro      s    
z"WWWAuthenticate._trigger_on_updater   c                 C  s   | j S )zDThe authorization scheme, like ``Basic``, ``Digest``, or ``Bearer``.)rq   rR   r   r   r   r      s    zWWWAuthenticate.typer5   c                 C  s   || _ |   d S r   )rq   ro   rO   r   r   r   r      s    zdict[str, str]c                 C  s   | j S z~A dict of parameters for the header. Only one of this or :attr:`token` should
        have a value for a give scheme.
        )rr   rR   r   r   r   r      s    zWWWAuthenticate.parametersc                   s    t | fdd _   d S )Nc                   s      S r   rn   rp   rR   r   r   rf      rg   z,WWWAuthenticate.parameters.<locals>.<lambda>)r   rr   ro   rO   r   rR   r   r      s    c                 C  s   | j S ru   )rs   rR   r   r   r   r      s    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)rs   ro   rO   r   r   r   r      s    authentication required)realmr   c                 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.r8   rw   N)	rh   ri   rq   dictclearr   updaters   ro   )r   rw   r   r   r   	set_basic  s    zWWWAuthenticate.set_basicauthFzt.Sequence[str]r(   )rw   nonceqopopaque	algorithmstaler   c                 C  sx   t d d| _t| j ||d||r0dndd}|durH||d< |durX||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)rw   r~   r   r   Nr   r   )
rh   ri   rq   rx   ry   r   joinrz   rs   ro   )r   rw   r~   r   r   r   r   r   r   r   r   
set_digest  s"    
zWWWAuthenticate.set_digestr)   c                 C  s   | j |S r   r   r+   r   r   r   r#   ?  s    zWWWAuthenticate.__getitem__)r%   r6   r   c                 C  s2   |d u r|| j v r&| j |= n
|| j |< |   d S r   r   ro   )r   r%   r6   r   r   r   __setitem__B  s
    


zWWWAuthenticate.__setitem__c                 C  s   || j v r| j |= |   d S r   r   r+   r   r   r   __delitem__K  s    
zWWWAuthenticate.__delitem__r   c                 C  s   | | S r   r   r!   r   r   r   r"   P  s    zWWWAuthenticate.__getattr__)r   r6   r   c                   s$   |dv rt  || n|| |< d S )N>   rq   rr   rs   rt   )super__setattr__)r   r   r6   	__class__r   r   r   S  s    zWWWAuthenticate.__setattr__c                 C  s
   | |= d S r   r   r!   r   r   r   __delattr__Y  s    zWWWAuthenticate.__delattr__c                 C  s
   || j v S r   r*   r+   r   r   r   r,   \  s    zWWWAuthenticate.__contains__r-   r.   c                 C  s2   t |tstS |j| jko0|j| jko0|j| jkS r   )r0   rl   r1   r   r   r   r2   r   r   r   r3   _  s    


zWWWAuthenticate.__eq__r$   c                 C  s   | j ||S r   r   r'   r   r   r   r    i  s    zWWWAuthenticate.getr4   c                 C  sR   |sdS | d\}}}| }| }d|dv rF| |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
        Nr7   r<   )r=   r>   r?   rD   r   )rE   r6   rF   rG   rH   r   r   r   rI   l  s    	zWWWAuthenticate.from_headerc                 C  s   | j dur | j  d| j  S | jdkrg }| j D ]:\}}|dv rVt|dd}nt|}|| d|  q8dd	| S | j  dt| j S )
zCProduce a ``WWW-Authenticate`` header value representing this data.Nr7   r   >   r   rw   r   domainr~   F)Zallow_tokenr<   zDigest r   )	r   r   rN   r   itemsr	   appendr   r   )r   r   r%   r6   r   r   r   rP     s    

zWWWAuthenticate.to_headerc                 C  s   |   S r   rQ   rR   r   r   r   rS     s    zWWWAuthenticate.__str__c                 C  s   dt | j d|   dS rT   rW   rR   r   r   r   rY     s    zWWWAuthenticate.__repr__zset[str]c                   s6   t jdtdd 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   r`   r   r   r5   c                   s(   | sd v r d= d S |    jd< d S )Nr   )rP   r   )r6   rR   r   r   	on_update  s
    z&WWWAuthenticate.qop.<locals>.on_updater   )rh   ri   rj   r   r   r    )r   r   r   rR   r   r     s    	zWWWAuthenticate.qopz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   r`   r   trueN)rh   ri   rj   r   r>   rR   r   r   r   r     s    
zWWWAuthenticate.stalezbool | str | Nonec                 C  sZ   |d u rd| j v r| j d= d S t|trLtjdtdd |r@dnd| j d< n
|| j d< d S )Nr   z\Setting the 'stale' property to a boolean is deprecated and will be removed in Werkzeug 3.0.r   r`   r   r   )r   r0   r(   rh   ri   rj   rO   r   r   r   r     s    

)NNN)rv   )r|   NNF)N) rX   rZ   r[   r\   r   ro   r^   r   setterr   r   r{   r   r#   r   r   r"   r   r   r,   r3   r    r]   rI   rP   rS   rY   r   r   staticmethodrk   __classcell__r   r   r   r   rl      sZ      	    %	
rl   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   r`   )rh   ri   rj   )argskwargsfr   r   wrapper  s    z(_deprecated_dict_method.<locals>.wrapperr   )r   r   r   r   r   _deprecated_dict_method  s    	r   )
__iter__ry   copyr   keysrb   popitem
setdefaultrz   rm   )N)
__future__r   r@   typingtrh   	functoolsr   httpr   r   r   r	   
structuresr   r   TYPE_CHECKINGZtyping_extensionster   rk   rl   r   r   getattrrx   r   setattrr   r   r   r   <module>   s,   ~  9