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   úW/var/www/html/chatgpt/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¡}|dkr@ztj|dd� ¡   d¡\}}}W n tjtfy7   Y dS w | |||dœƒS d	| 	d	¡v rO| |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ú ú 	ÚbasicT)Úvalidateú:)ÚusernameÚpasswordú=)Ú	partitionÚlowerÚstripÚbase64Ú	b64decodeÚdecodeÚbinasciiÚErrorÚUnicodeErrorÚrstripr   )Úclsr4   ÚschemeÚ_Úrestr;   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
        r8   r:   ÚasciizBasic Nr6   )r   rA   Ú	b64encoder;   r<   ÚencoderC   r   Útitler   r   ©r   r4   r   r   r   Ú	to_headerz   s   
ÿþ

zAuthorization.to_headerc                 C  ó   |   ¡ S r   ©rR   ©r   r   r   r   Ú__str__Š   ó   zAuthorization.__str__c                 C  ó   dt | ƒj› d|  ¡ › d�S ©Nú<r6   ú>©r   Ú__name__rR   rU   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   ÚclassmethodrL   rR   rV   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©rJ   rU   r   r   Ú<lambda>³   ó    z*WWWAuthenticate.__init__.<locals>.<lambda>)r?   Ú_typer   Ú_parametersÚ_tokenÚ
_on_update)r   r
   rl   r   r   rU   r   r   «   s   
ÿ
zWWWAuthenticate.__init__r   r   c                 C  s   | j d ur|   | ¡ d S d S r   )rv   rU   r   r   r   ro   ¸   s   
ÿz"WWWAuthenticate._trigger_on_updatec                 C  ó   | j S )zDThe authorization scheme, like ``basic``, ``digest``, or ``bearer``.)rs   rU   r   r   r   r   ¼   s   zWWWAuthenticate.typer4   c                 C  s   || _ |  ¡  d S r   )rs   ro   rQ   r   r   r   r   Á   s   údict[str, str | None]c                 C  rw   ©zA dict of parameters for the header. Only one of this or :attr:`token` should
        have a value for a given scheme.
        )rt   rU   r   r   r   r   Æ   ó   zWWWAuthenticate.parametersúdict[str, str]c                   s    t |‡ fdd„ƒˆ _ˆ  ¡  d S )Nc                   rm   r   rn   rp   rU   r   r   rq   Ï   rr   z,WWWAuthenticate.parameters.<locals>.<lambda>)r   rt   ro   rQ   r   rU   r   r   Í   s   c                 C  rw   ry   )ru   rU   r   r   r   r   Ò   rz   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)ru   ro   rQ   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   ro   )r   r!   r4   r   r   r   Ú__setitem__æ   s   
€
zWWWAuthenticate.__setitem__c                 C  s"   || j v r| j |= |  ¡  d S d S r   r|   r)   r   r   r   Ú__delitem__ï   s   
þzWWWAuthenticate.__delitem__r   c                 C  s   | | S r   r   r   r   r   r   r   ô   rW   zWWWAuthenticate.__getattr__c                   s&   |dv rt ƒ  ||¡ d S || |< d S )N>   rt   rv   rs   ru   )Ú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/   rk   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  sT   |sdS |  d¡\}}}| ¡ }| 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   r7   r=   )r>   r?   r@   rG   r   )rH   r4   rI   rJ   rK   r   r   r   rL     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>   ÚopaqueÚdomainÚqopÚrealmÚnonceF)Zallow_tokenr=   zDigest z, )	r   r   rP   r   Úitemsr   ÚappendÚjoinr   )r   rŠ   r!   r4   r   r   r   rR   '  s   


zWWWAuthenticate.to_headerc                 C  rS   r   rT   rU   r   r   r   rV   >  rW   zWWWAuthenticate.__str__c                 C  rX   rY   r\   rU   r   r   r   r^   A  r_   zWWWAuthenticate.__repr__r`   )r
   r   rl   r   r   r   )r   r   rf   )r4   r   r   r   )r   rx   )r4   r{   r   r   )r   r   )r4   r   r   r   )r!   r   r   r   )r!   r   r4   r   r   r   )r!   r   r   r   ra   )r   r   r4   r   r   r   )r   r   r   r   rc   rd   r   rb   re   )r]   rg   rh   ri   r   ro   Úpropertyr   Úsetterr   r   r    r}   r~   r   r€   rƒ   r*   r2   r   rj   rL   rR   rV   r^   Ú__classcell__r   r   r�   r   rk   ‘   s@    ü

	

	






rk   )Ú
__future__r   rA   rD   Úcollections.abcÚabcZcabcÚtypingÚtÚhttpr   r   r   Ú
structuresr   ÚTYPE_CHECKINGZtyping_extensionsÚter	   rk   r   r   r   r   Ú<module>   s     