a
    0hG'                     @  s   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rnd dlZG d	d
 d
ZG dd dZdS )    )annotationsN   )dump_header)parse_dict_header)quote_header_value   )CallbackDictc                   @  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] | None
str | NoneNone)	auth_typedatatokenreturnc                 C  s"   || _ |d u ri }|| _|| _d S N)type
parametersr   )selfr   r   r    r   J/var/www/auris/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__C   s    zAuthorization.__getattr__c                 C  s   | j |S r   r   r   r   r   r   __getitem__F   s    zAuthorization.__getitem__keydefaultr   c                 C  s   | j ||S r   r   r   r!   r"   r   r   r   r   I   s    zAuthorization.getboolr!   r   c                 C  s
   || j v S r   r   r   r!   r   r   r   __contains__L   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__O   s    


zAuthorization.__eq__te.Self | Nonevaluer   c              	   C  s   |sdS | d\}}}| }| }|dkrzzt|  d\}}}W n tjtfyh   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binasciiErrorUnicodeErrorrstripr   )clsr2   scheme_restr6   r7   r   r   r   from_headerY   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
        r4   r5   asciizBasic Nr3   )r   r<   	b64encoder6   r7   encoder>   r   titler   r   r   r2   r   r   r   	to_headerx   s    


zAuthorization.to_headerc                 C  s   |   S r   rN   r   r   r   r   __str__   s    zAuthorization.__str__c                 C  s   dt | j d|   dS N<r3   >r   __name__rN   rP   r   r   r   __repr__   s    zAuthorization.__repr__)NN)N)rV   
__module____qualname____doc__r   r   r   r   r(   r/   classmethodrG   rN   rQ   rW   r   r   r   r   r	      s     
r	   c                      s  e Zd ZdZd<d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
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%d&Zdd	d!d'd(Zdd)dd*d+Zd,d)d-d.d/Zd=dddd0d1d2Zedd3dd4d5Zdd
d6d7Zdd
d8d9Zdd
d:d;Z  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.
    Nr
   r   r   )r   valuesr   c                   s.   |   _t| fdd _| _d  _d S )Nc                   s      S r   _trigger_on_updaterE   rP   r   r   <lambda>       z*WWWAuthenticate.__init__.<locals>.<lambda>)r:   _typer   _parameters_token
_on_update)r   r   r]   r   r   rP   r   r      s    
zWWWAuthenticate.__init__r   rH   c                 C  s   | j d ur|  |  d S r   )rf   rP   r   r   r   r_      s    
z"WWWAuthenticate._trigger_on_updatec                 C  s   | j S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)rc   rP   r   r   r   r      s    zWWWAuthenticate.typer1   c                 C  s   || _ |   d S r   )rc   r_   rM   r   r   r   r      s    zdict[str, str | None]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 given scheme.
        )rd   rP   r   r   r   r      s    zWWWAuthenticate.parameterszdict[str, str]c                   s    t | fdd _   d S )Nc                   s      S r   r^   r`   rP   r   r   ra      rb   z,WWWAuthenticate.parameters.<locals>.<lambda>)r   rd   r_   rM   r   rP   r   r      s    c                 C  s   | j S rg   )re   rP   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)re   r_   rM   r   r   r   r      s    r%   c                 C  s   | j |S r   r   r'   r   r   r   r      s    zWWWAuthenticate.__getitem__)r!   r2   r   c                 C  s2   |d u r|| j v r&| j |= n
|| j |< |   d S r   r   r_   )r   r!   r2   r   r   r   __setitem__   s
    


zWWWAuthenticate.__setitem__c                 C  s   || j v r| j |= |   d S r   rh   r'   r   r   r   __delitem__   s    
zWWWAuthenticate.__delitem__r   c                 C  s   | | S r   r   r   r   r   r   r      s    zWWWAuthenticate.__getattr__)r   r2   r   c                   s$   |dv rt  || n|| |< d S )N>   rf   rd   re   rc   )super__setattr__)r   r   r2   	__class__r   r   rl      s    zWWWAuthenticate.__setattr__c                 C  s
   | |= d S r   r   r   r   r   r   __delattr__   s    zWWWAuthenticate.__delattr__r$   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   )r,   r\   r-   r   r   r   r.   r   r   r   r/     s    


zWWWAuthenticate.__eq__r    c                 C  s   | j ||S r   r   r#   r   r   r   r     s    zWWWAuthenticate.getr0   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
        Nr3   r8   )r9   r:   r;   rB   r   )rC   r2   rD   rE   rF   r   r   r   rG     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.Nr3   digest>   domainrealmqopnonceopaqueF)Zallow_tokenr8   zDigest z, )	r   r   rL   r   itemsr   appendjoinr   )r   rv   r!   r2   r   r   r   rN   %  s    

zWWWAuthenticate.to_headerc                 C  s   |   S r   rO   rP   r   r   r   rQ   9  s    zWWWAuthenticate.__str__c                 C  s   dt | j d|   dS rR   rU   rP   r   r   r   rW   <  s    zWWWAuthenticate.__repr__)NN)N)rV   rX   rY   rZ   r   r_   propertyr   setterr   r   r   ri   rj   r   rl   ro   r(   r/   r   r[   rG   rN   rQ   rW   __classcell__r   r   rm   r   r\      s>     		
r\   )
__future__r   r<   r?   collections.abcabcZcabctypingthttpr   r   r   
structuresr   TYPE_CHECKINGZtyping_extensionster	   r\   r   r   r   r   <module>   s   ~