o
    ßý°j�'  ã                   @  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r7d 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„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] | NoneÚtokenú
str | NoneÚreturnÚNonec                 C  s&   || _ 	 |d u r
i }|| _	 || _d S ©N)ÚtypeÚ
parametersr   )Úselfr
   r   r   © r   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/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__C   ó   zAuthorization.__getattr__c                 C  r   r   r   r   r   r   r   Ú__getitem__F   r   zAuthorization.__getitem__ÚkeyÚdefaultc                 C  ó   | j  ||¡S r   r   ©r   r!   r"   r   r   r   r   I   ó   zAuthorization.getÚboolc                 C  ó
   || j v S r   ©r   ©r   r!   r   r   r   Ú__contains__L   ó   
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   r,   r   r   r   Ú__eq__O   ó   

ÿ
ý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 )zÄParse 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   )Úclsr4   ÚschemeÚ_Úrestr9   r:   r   r   r   Úfrom_headerY   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
        r7   r8   ÚasciizBasic Nr6   )r   r?   Ú	b64encoder9   r:   ÚencoderA   r   Útitler   r   ©r   r4   r   r   r   Ú	to_headerx   s   
ÿþ

zAuthorization.to_headerc                 C  ó   |   ¡ S r   ©rP   ©r   r   r   r   Ú__str__ˆ   ó   zAuthorization.__str__c                 C  ó   dt | ƒj› d|  ¡ › d�S ©Nú<r6   ú>©r   Ú__name__rP   rS   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&   ©r,   r-   r   r&   ©r4   r   r   r5   ©r   r   )r[   Ú
__module__Ú__qualname__Ú__doc__r   r   r    r   r*   r2   ÚclassmethodrJ   rP   rT   r\   r   r   r   r   r	      s    ü






r	   c                      s  e Zd ZdZ		d<d=d	d
„Zd>dd„Zed?dd„ƒZejd@dd„ƒZedAdd„ƒZ	e	jdBdd„ƒZ	edCdd„ƒZ
e
jdDdd„ƒZ
dEdd„ZdFdd„ZdGd d!„ZdHd#d$„ZdI‡ fd%d&„ZdJd'd(„ZdKd*d+„ZdLd.d/„ZdMdNd1d2„ZedOd4d5„ƒZd?d6d7„Zd?d8d9„Zd?d:d;„Z‡  ZS )PÚ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   r   c                   s.   |  ¡ ˆ _t|‡ fdd„ƒˆ _|ˆ _d ˆ _d S )Nc                   ó   ˆ   ¡ S r   ©Ú_trigger_on_update©rH   rS   r   r   Ú<lambda>±   ó    z*WWWAuthenticate.__init__.<locals>.<lambda>)r=   Ú_typer   Ú_parametersÚ_tokenÚ
_on_update)r   r
   rj   r   r   rS   r   r   ©   s   
ÿ
zWWWAuthenticate.__init__r   r   c                 C  s   | j d ur|   | ¡ d S d S r   )rt   rS   r   r   r   rm   ¶   s   
ÿz"WWWAuthenticate._trigger_on_updatec                 C  ó   | j S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)rq   rS   r   r   r   r   º   s   zWWWAuthenticate.typer4   c                 C  s   || _ |  ¡  d S r   )rq   rm   rO   r   r   r   r   ¿   s   údict[str, str | None]c                 C  ru   ©zA dict of parameters for the header. Only one of this or :attr:`token` should
        have a value for a given scheme.
        )rr   rS   r   r   r   r   Ä   ó   zWWWAuthenticate.parametersúdict[str, str]c                   s    t |‡ fdd„ƒˆ _ˆ  ¡  d S )Nc                   rk   r   rl   rn   rS   r   r   ro   Í   rp   z,WWWAuthenticate.parameters.<locals>.<lambda>)r   rr   rm   rO   r   rS   r   r   Ë   s   c                 C  ru   rw   )rs   rS   r   r   r   r   Ð   rx   zWWWAuthenticate.tokenc                 C  s   || _ |  ¡  dS )z–A token for the header. Only one of this or :attr:`parameters` should have a
        value for a given scheme.

        .. versionadded:: 2.3
        N)rs   rm   rO   r   r   r   r   ×   s   r!   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   rm   )r   r!   r4   r   r   r   Ú__setitem__ä   s   
€
zWWWAuthenticate.__setitem__c                 C  s"   || j v r| j |= |  ¡  d S d S r   rz   r)   r   r   r   Ú__delitem__í   s   
þzWWWAuthenticate.__delitem__r   c                 C  s   | | S r   r   r   r   r   r   r   ò   rU   zWWWAuthenticate.__getattr__c                   s&   |dv rt ƒ  ||¡ d S || |< d S )N>   rq   rs   rt   rr   )ÚsuperÚ__setattr__)r   r   r4   ©Ú	__class__r   r   r~   õ   s   zWWWAuthenticate.__setattr__c                 C  s
   | |= d S r   r   r   r   r   r   Ú__delattr__û   r+   zWWWAuthenticate.__delattr__r&   c                 C  r'   r   r(   r)   r   r   r   r*   þ   r+   zWWWAuthenticate.__contains__r,   r-   c                 C  r.   r   )r/   ri   r0   r   r   r   r1   r   r   r   r2     r3   zWWWAuthenticate.__eq__r"   c                 C  r#   r   r   r$   r   r   r   r     r%   zWWWAuthenticate.getr5   c                 C  sR   |sdS |  d¡\}}}| ¡ }| ¡ }d| d¡v r#| |t|ƒdƒS | |d|ƒS )zÆParse 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
        Nr6   r;   )r<   r=   r>   rE   r   )rF   r4   rG   rH   rI   r   r   r   rJ     s   	zWWWAuthenticate.from_headerc                 C  s®   | j dur| j ¡ › d| j › �S | js| j ¡ S | jdkrJg }| j ¡ D ]\}}|dv r3t|dd�}nt|ƒ}| |› d|› �¡ q$dd	 |¡› �S | j ¡ › dt| jƒ› �S )
zCProduce a ``WWW-Authenticate`` header value representing this data.Nr6   Údigest>   ÚqopÚnonceÚrealmÚdomainÚopaqueF)Úallow_tokenr;   zDigest z, )	r   r   rN   r   Úitemsr   ÚappendÚjoinr   )r   r‰   r!   r4   r   r   r   rP   %  s   


zWWWAuthenticate.to_headerc                 C  rQ   r   rR   rS   r   r   r   rT   <  rU   zWWWAuthenticate.__str__c                 C  rV   rW   rZ   rS   r   r   r   r\   ?  r]   zWWWAuthenticate.__repr__r^   )r
   r   rj   r   r   r   )r   r   rd   )r4   r   r   r   )r   rv   )r4   ry   r   r   )r   r   )r4   r   r   r   )r!   r   r   r   )r!   r   r4   r   r   r   )r!   r   r   r   r_   )r   r   r4   r   r   r   )r   r   r   r   ra   rb   r   r`   rc   )r[   re   rf   rg   r   rm   Úpropertyr   Úsetterr   r   r    r{   r|   r   r~   r�   r*   r2   r   rh   rJ   rP   rT   r\   Ú__classcell__r   r   r   r   ri   �   s@    ü

	

	






ri   )Ú
__future__r   r?   rB   Úcollections.abcÚabcÚcabcÚtypingÚtÚhttpr   r   r   Ú
structuresr   ÚTYPE_CHECKINGÚtyping_extensionsÚter	   ri   r   r   r   r   Ú<module>   s    ~