o
    'hG'                     @  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   X/var/www/html/olx_land/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 )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   )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 )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   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 )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
        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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.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   9  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    ~