
    'g                       d dl m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 dd	lmZ dd
lmZ ddlmZ ej$                  rd dlZ ej*                  d      Z ej*                  d      Z ej*                  d      Z	 	 	 	 d*dZ G d deee         Z G d deeef         Z G d deeef   eeef         Z G d deeef         Z G d dej@                  eef         Z! G d deeef         Z" G d deeef   eeef         Z# G d deeef   eeef         Z$ G d  d!eeef   eeef         Z% G d" d#eeef   e"eef         Z& G d$ d%eeef   eeef         Z' G d& d'ejP                  e)         Z*dd(l	m+Z+ d+d)Z,y),    )annotationsNdeepcopy   )
exceptions)_missing   )ImmutableDictMixin)ImmutableListMixin)ImmutableMultiDictMixin)UpdateDictMixinKVTc              #  B  K   t        | t              r| j                  d      E d{    yt        | t        j                        rH| j                         D ]4  \  }}t        |t
        t        t        f      r|D ]  }||f 
 /||f 6 y| E d{    y7 r7 w)zyIterates over the items of a mapping yielding keys and values
    without dropping any from more complex structures.
    TmultiN)
isinstance	MultiDictitemscabcMappinglisttupleset)mappingkeyvaluevs       Z/var/www/html/knws/venv/lib/python3.12/site-packages/werkzeug/datastructures/structures.pyiter_multi_itemsr!      s      '9%==t=,,,	GT\\	*!--/ 	!JC%$s!34 !Aq&L! 5j 	!  	- 	s"   &BBA,BBBBc                      e Zd ZdZddZy)ImmutableListzJAn immutable :class:`list`.

    .. versionadded:: 0.5

    :private:
    c                ^    t        |       j                   dt        j                  |        dS N())type__name__r   __repr__selfs    r    r*   zImmutableList.__repr__5   *    t*%%&ad(;'<A>>    Nreturnstr)r)   
__module____qualname____doc__r*    r.   r    r#   r#   -   s    ?r.   r#   c                      e Zd ZdZej
                  d	d       Zej
                  d
d       Zej
                  dd       Zej
                  dd       Zej
                  dd       Z	 	 d	 	 	 	 	 	 	 ddZy)TypeConversionDictzWorks like a regular dict but the :meth:`get` method can perform
    type conversions.  :class:`MultiDict` and :class:`CombinedMultiDict`
    are subclasses of this class and provide the same feature.

    .. versionadded:: 0.5
    c                     y Nr5   r,   r   s     r    getzTypeConversionDict.getA       '*r.   c                     y r9   r5   r,   r   defaults      r    r;   zTypeConversionDict.getC       ,/r.   c                     y r9   r5   r>   s      r    r;   zTypeConversionDict.getE       03r.   c                     y r9   r5   r,   r   r(   s      r    r;   zTypeConversionDict.getG       FIr.   c                     y r9   r5   r,   r   r?   r(   s       r    r;   zTypeConversionDict.getI       KNr.   Nc                x    	 | |   }||S 	  ||      S # t         $ r |cY S w xY w# t        t        f$ r |cY S w xY w)a  Return the default value if the requested data doesn't exist.
        If `type` is provided and is a callable it should convert the value,
        return it or raise a :exc:`ValueError` if that is not possible.  In
        this case the function will return the default as if the value was not
        found:

        >>> d = TypeConversionDict(foo='42', bar='blub')
        >>> d.get('foo', type=int)
        42
        >>> d.get('bar', -1, type=int)
        -1

        :param key: The key to be looked up.
        :param default: The default value to be returned if the key can't
                        be looked up.  If not further specified `None` is
                        returned.
        :param type: A callable that is used to cast the value in the
                     :class:`MultiDict`.  If a :exc:`ValueError` or a
                     :exc:`TypeError` is raised by this callable the default
                     value is returned.

        .. versionchanged:: 3.0.2
           Returns the default value on :exc:`TypeError`, too.
        )KeyError
ValueError	TypeError)r,   r   r?   r(   rvs        r    r;   zTypeConversionDict.getK   sZ    <	cB <I	8O  	N	 I& 	N	s    % ""99r   r   r0   V | Noner   r   r?   r   r0   r   r   r   r?   r   r0   V | Tr   r1   r(   cabc.Callable[[V], T]r0   zT | Noner   r1   r?   r   r(   rT   r0   r   NNr   r   r?   V | T | Noner(   cabc.Callable[[V], T] | Noner0   rX   )r)   r2   r3   r4   toverloadr;   r5   r.   r    r7   r7   9   s     ZZ* *ZZ/ /ZZ3 3ZZI IZZN N !%-1	)) ) +	)
 
)r.   r7   c                       e Zd ZdZddZddZy)ImmutableTypeConversionDictzpWorks like a :class:`TypeConversionDict` but does not support
    modifications.

    .. versionadded:: 0.5
    c                    t        |       S zReturn a shallow mutable copy of this object.  Keep in mind that
        the standard library's :func:`copy` function is a no-op for this class
        like for any other python immutable type (eg: :class:`tuple`).
        )r7   r+   s    r    copyz ImmutableTypeConversionDict.copy~   s    
 "$''r.   c                    | S r9   r5   r+   s    r    __copy__z$ImmutableTypeConversionDict.__copy__       r.   N)r0   zTypeConversionDict[K, V]r0   te.Selfr)   r2   r3   r4   r`   rb   r5   r.   r    r]   r]   w   s    (r.   r]   c                      e Zd ZdZ	 d'	 	 	 d( fdZd)dZd* fdZd+ fdZd, fdZd- fdZ	d- fdZ
ej                  d.d	       Zej                  d/d
       Z	 d'	 	 	 	 	 d0 fdZd1 fdZej                  d2d       Zej                  d3d       Zd'd4dZ	 d'	 	 	 	 	 d5 fdZd6d7 fdZd8 fdZd9 fdZd: fdZd;dZd'd<dZej                  d=d       Zej                  d>d       Zd?d@dZ	 	 	 	 dAdZ	 	 	 	 dBdZ	 	 	 	 dCdZej                  d,d       Zej                  d3d       Zej                  dDd       Zef	 	 	 	 	 dE fd ZdF fd!Zd. fd"ZdG fd#Zd;d$Z d<d%Z!dHd&Z" xZ#S )Ir   a^  A :class:`MultiDict` is a dictionary subclass customized to deal with
    multiple values for the same key which is for example used by the parsing
    functions in the wrappers.  This is necessary because some HTML form
    elements pass multiple values for the same key.

    :class:`MultiDict` implements all standard dictionary methods.
    Internally, it saves all values for a key as a list, but the standard dict
    access methods will only return the first value for a key. If you want to
    gain access to the other values, too, you have to use the `list` methods as
    explained below.

    Basic Usage:

    >>> d = MultiDict([('a', 'b'), ('a', 'c')])
    >>> d
    MultiDict([('a', 'b'), ('a', 'c')])
    >>> d['a']
    'b'
    >>> d.getlist('a')
    ['b', 'c']
    >>> 'a' in d
    True

    It behaves like a normal dict thus all dict functions will only return the
    first value when multiple values for one key are found.

    From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a
    subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will
    render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP
    exceptions.

    A :class:`MultiDict` can be constructed from an iterable of
    ``(key, value)`` tuples, a dict, a :class:`MultiDict` or from Werkzeug 0.2
    onwards some keyword parameters.

    :param mapping: the initial value for the :class:`MultiDict`.  Either a
                    regular dict, an iterable of ``(key, value)`` tuples
                    or `None`.

    .. versionchanged:: 3.1
        Implement ``|`` and ``|=`` operators.
    c                   |t         |           y t        |t              r%t         |   d |j	                         D               y t        |t
        j                        r[i }|j                         D ]6  \  }}t        |t        t        t        f      rt        |      }|s/|g}|||<   8 t         |   |       y i }|D ]&  \  }}|j                  |g       j                  |       ( t         |   |       y )Nc              3  0   K   | ]  \  }}||d d  f  y wr9   r5   ).0kvss      r    	<genexpr>z%MultiDict.__init__.<locals>.<genexpr>   s     EEAraAZEs   )super__init__r   r   listsr   r   r   r   r   r   
setdefaultappend)r,   r   tmpr   r   	__class__s        r    ro   zMultiDict.__init__   s     ?G+GEW]]_EE.C%mmo !
UedE3%78 KE  "GE C! GS!C% 6
UsB'..u56GS!r.   c                4    t        | j                               S r9   )dictrp   r+   s    r    __getstate__zMultiDict.__getstate__   s    DJJL!!r.   c                @    t         |           t         | 	  |       y r9   )rn   clearupdate)r,   r   rt   s     r    __setstate__zMultiDict.__setstate__   s    ur.   c                     t         |          S r9   )rn   __iter__r,   rt   s    r    r}   zMultiDict.__iter__   s    
 w!!r.   c                z    || v r"t         |   |      }t        |      dkD  r|d   S t        j                  |      )zReturn the first data value for this key;
        raises KeyError if not found.

        :param key: The key to be looked up.
        :raise KeyError: if the key does not exist.
        r   )rn   __getitem__lenr   BadRequestKeyError)r,   r   lstrt   s      r    r   zMultiDict.__getitem__   s@     $;'%c*C3x!|1v++C00r.   c                (    t         |   ||g       y)zLike :meth:`add` but removes an existing key first.

        :param key: the key for the value.
        :param value: the value to set.
        N)rn   __setitem__r,   r   r   rt   s      r    r   zMultiDict.__setitem__   s     	C%)r.   c                D    t         |   |g       j                  |       y)zAdds a new value for the key.

        .. versionadded:: 0.6

        :param key: the key for the value.
        :param value: the value to add.
        N)rn   rq   rr   r   s      r    addzMultiDict.add   s     	3#**51r.   c                     y r9   r5   r:   s     r    getlistzMultiDict.getlist      *-r.   c                     y r9   r5   rD   s      r    r   zMultiDict.getlist      GJr.   c                    	 t         |   |      }|t        |      S g }|D ]  }	 |j	                   ||              |S # t        $ r g cY S w xY w# t
        t        f$ r Y Aw xY w)af  Return the list of items for a given key. If that key is not in the
        `MultiDict`, the return value will be an empty list.  Just like `get`,
        `getlist` accepts a `type` parameter.  All items will be converted
        with the callable defined there.

        :param key: The key to be looked up.
        :param type: Callable to convert each value. If a ``ValueError`` or
            ``TypeError`` is raised, the value is omitted.
        :return: a :class:`list` of all the values for the key.

        .. versionchanged:: 3.1
            Catches ``TypeError`` in addition to ``ValueError``.
        )rn   r   rJ   r   rr   rK   rL   )r,   r   r(   rM   resultitemrt   s         r    r   zMultiDict.getlist  s     	'-c2B <8O 	Dd4j)	
   	I	 	* s"   A AAAA%$A%c                8    t         |   |t        |             y)a  Remove the old values for a key and add new ones.  Note that the list
        you pass the values in will be shallow-copied before it is inserted in
        the dictionary.

        >>> d = MultiDict()
        >>> d.setlist('foo', ['1', '2'])
        >>> d['foo']
        '1'
        >>> d.getlist('foo')
        ['1', '2']

        :param key: The key for which the values are set.
        :param new_list: An iterable with the new values for the key.  Old values
                         are removed first.
        N)rn   r   r   )r,   r   new_listrt   s      r    setlistzMultiDict.setlist$  s      	Ch0r.   c                     y r9   r5   r:   s     r    rq   zMultiDict.setdefault6  r   r.   c                     y r9   r5   r>   s      r    rq   zMultiDict.setdefault8      36r.   c                    || vr|| |<   | |   S )aG  Returns the value for the key if it is in the dict, otherwise it
        returns `default` and sets that value for `key`.

        :param key: The key to be looked up.
        :param default: The default value to be returned if the key is not
                        in the dict.  If not further specified it's `None`.
        r5   r>   s      r    rq   zMultiDict.setdefault:  s     d?DICyr.   c                d    || vrt         |   |t        |xs d             t         |   |      S )a  Like `setdefault` but sets multiple values.  The list returned
        is not a copy, but the list that is actually used internally.  This
        means that you can put new values into the dict by appending items
        to the list:

        >>> d = MultiDict({"foo": 1})
        >>> d.setlistdefault("foo").extend([2, 3])
        >>> d.getlist("foo")
        [1, 2, 3]

        :param key: The key to be looked up.
        :param default_list: An iterable of default values.  It is either copied
                             (in case it was a list) or converted into a list
                             before returned.
        :return: a :class:`list`
        r5   )rn   r   r   r   )r,   r   default_listrt   s      r    setlistdefaultzMultiDict.setlistdefaultG  s5    & d?GT,*<"%=>w"3''r.   c              #  l   K   t         |          D ]  \  }}|r|D ]  }||f 
 ||d   f   yw)a  Return an iterator of ``(key, value)`` pairs.

        :param multi: If set to `True` the iterator returned will have a pair
                      for each value of each key.  Otherwise it will only
                      contain pairs for the first value of each key.
        r   N)rn   r   )r,   r   r   valuesr   rt   s        r    r   zMultiDict.items_  sN      !7=? 	%KC# %Eu*$% 6!9n$	%s   14c              #  X   K   t         |          D ]  \  }}|t        |      f  yw)zuReturn a iterator of ``(key, values)`` pairs, where values is the list
        of all values associated with the key.N)rn   r   r   )r,   r   r   rt   s      r    rp   zMultiDict.listso  s1     
 !7=? 	$KCtF|##	$s   '*c              #  B   K   t         |          D ]	  }|d     yw)zAReturns an iterator of the first value on every key's value list.r   Nrn   r   )r,   r   rt   s     r    r   zMultiDict.valuesw  s(      gn& 	F)O	s   c                     t         |          S )a   Return an iterator of all values associated with a key.  Zipping
        :meth:`keys` and this is the same as calling :meth:`lists`:

        >>> d = MultiDict({"foo": [1, 2, 3]})
        >>> zip(d.keys(), d.listvalues()) == d.lists()
        True
        r   r~   s    r    
listvalueszMultiDict.listvalues~  s     w~r.   c                $    | j                  |       S )z%Return a shallow copy of this object.rt   r+   s    r    r`   zMultiDict.copy  s    ~~d##r.   c                X    | j                  t        | j                  d      |            S )z"Return a deep copy of this object.F)flat)rt   r   to_dictr,   memos     r    r   zMultiDict.deepcopy  s#    ~~ht|||'?FGGr.   c                     y r9   r5   r+   s    r    r   zMultiDict.to_dict  s    %(r.   c                     y r9   r5   r,   r   s     r    r   zMultiDict.to_dict  s    CFr.   c                j    |rt        | j                               S t        | j                               S )a  Return the contents as regular dict.  If `flat` is `True` the
        returned dict will only have the first item present, if `flat` is
        `False` all values will be returned as lists.

        :param flat: If set to `False` the dict returned will have lists
                     with all the values in it.  Otherwise it will only
                     contain the first value for each key.
        :return: a :class:`dict`
        )rv   r   rp   r   s     r    r   zMultiDict.to_dict  s)     

%%DJJL!!r.   c                N    t        |      D ]  \  }}| j                  ||        y)a  update() extends rather than replaces existing key lists:

        >>> a = MultiDict({'x': 1})
        >>> b = MultiDict({'x': 2, 'y': 3})
        >>> a.update(b)
        >>> a
        MultiDict([('y', 3), ('x', 1), ('x', 2)])

        If the value list for a key in ``other_dict`` is empty, no new values
        will be added to the dict and the key will not be created:

        >>> x = {'empty_list': []}
        >>> y = MultiDict()
        >>> y.update(x)
        >>> y
        MultiDict([])
        Nr!   r   r,   r   r   r   s       r    rz   zMultiDict.update  s*    2 +73 	!JCHHS% 	!r.   c                    t        |t        j                        st        S | j	                         }|j                  |       |S r9   )r   r   r   NotImplementedr`   rz   )r,   otherrM   s      r    __or__zMultiDict.__or__  s4     %.!!YY[
		%	r.   c                    t        |t        j                  t        j                  f      st        S | j                  |       | S r9   )r   r   r   Iterabler   rz   )r,   r   s     r    __ior__zMultiDict.__ior__  s2     %$,,!>?!!Er.   c                     y r9   r5   r:   s     r    popzMultiDict.pop       #r.   c                     y r9   r5   r>   s      r    r   zMultiDict.pop  r@   r.   c                     y r9   r5   r>   s      r    r   zMultiDict.pop  rB   r.   c                    	 t         |   |      }t        |      dk(  rt        j                  |      |d   S # t
        $ r# |t        ur|cY S t        j                  |      dw xY w)a  Pop the first item for a list on the dict.  Afterwards the
        key is removed from the dict, so additional values are discarded:

        >>> d = MultiDict({"foo": [1, 2, 3]})
        >>> d.pop("foo")
        1
        >>> "foo" in d
        False

        :param key: the key to pop.
        :param default: if provided the value to return if the key was
                        not in the dictionary.
        r   N)rn   r   r   r   r   rJ   r   )r,   r   r?   r   rt   s       r    r   zMultiDict.pop  sj    (	?'+c"C3x1} 33C88q6M 	?h&//4$>		?s   6: A&A&c                    	 t         |          }t        |d         dk(  rt        j                  |d         |d   |d   d   fS # t
        $ r(}t        j                  |j                  d         dd}~ww xY w)zPop an item from the dict.r	   r   N)rn   popitemr   r   r   rJ   args)r,   r   ert   s      r    r   zMultiDict.popitem  s~    	E7?$D47|q  33DG<<7DGAJ&& 	E//q	:D	Es   AA 	A8#A33A8c                $    t         |   |g       S )zPop the list for a key from the dict.  If the key is not in the dict
        an empty list is returned.

        .. versionchanged:: 0.5
           If the key does no longer exist a list is returned instead of
           raising an error.
        )rn   r   )r,   r   rt   s     r    poplistzMultiDict.poplist
  s     w{3##r.   c                    	 t         |          S # t        $ r(}t        j                  |j
                  d         dd}~ww xY w)z*Pop a ``(key, list)`` tuple from the dict.r   N)rn   r   rJ   r   r   r   )r,   r   rt   s     r    popitemlistzMultiDict.popitemlist  sC    	E7?$$ 	E//q	:D	Es    	A#=Ac                "    | j                         S r9   )r`   r+   s    r    rb   zMultiDict.__copy__  s    yy{r.   c                &    | j                  |      S )N)r   r   r   s     r    __deepcopy__zMultiDict.__deepcopy__  s    }}$}''r.   c                j    t        |       j                   dt        | j                  d            dS )Nr&   Tr   r'   )r(   r)   r   r   r+   s    r    r*   zMultiDict.__repr__!  s1    t*%%&aTZZdZ-C(D'GqIIr.   r9   r   zkMultiDict[K, V] | cabc.Mapping[K, V | list[V] | tuple[V, ...] | set[V]] | cabc.Iterable[tuple[K, V]] | Noner0   Noner0   t.Any)r   r   r0   r   r0   zcabc.Iterator[K]r   r   r0   r   r   r   r   r   r0   r   r   r   r0   list[V]r   r   r(   rT   r0   zlist[T]r   r   r(   rY   r0   zlist[V] | list[T]r   r   r   cabc.Iterable[V]r0   r   r   r   r0   r   rP   )r   r   r?   rO   r0   rO   )r   r   r   zcabc.Iterable[V] | Noner0   r   Fr   boolr0   cabc.Iterable[tuple[K, V]]r0    cabc.Iterable[tuple[K, list[V]]]r0   r   r0   zcabc.Iterable[list[V]]rd   )r   r   r0   re   r0   z
dict[K, V])r   zt.Literal[False]r0   zdict[K, list[V]])T)r   r   r0   zdict[K, V] | dict[K, list[V]]r   dMultiDict[K, V] | cabc.Mapping[K, V | list[V] | tuple[V, ...] | set[V]] | cabc.Iterable[tuple[K, V]]r0   r   )r   z5cabc.Mapping[K, V | list[V] | tuple[V, ...] | set[V]]r0   MultiDict[K, V])r   zRcabc.Mapping[K, V | list[V] | tuple[V, ...] | set[V]] | cabc.Iterable[tuple[K, V]]r0   re   rQ   r   r   r?   rR   r0   rR   r0   ztuple[K, V]r0   ztuple[K, list[V]]r/   )$r)   r2   r3   r4   ro   rw   r{   r}   r   r   r   rZ   r[   r   r   rq   r   r   rp   r   r   r`   r   r   rz   r   r   r   r   r   r   r   rb   r   r*   __classcell__r   s   @r    r   r      s   )d "" 
">""1*2 ZZ- -ZZJ J;?8	<1$ ZZ- -ZZ6 6 ?C(($;(	(0% $ $H ZZ( (ZZF F"!)! 
!8J	) 
 ZZ# #ZZ/ /ZZ3 3 "?? ? 
	?BE$E(Jr.   r   c                  $    e Zd ZdZdZddZddZy)_omd_bucketa  Wraps values in the :class:`OrderedMultiDict`.  This makes it
    possible to keep an order over multiple different keys.  It requires
    a lot of extra memory and slows down access a lot, but makes it
    possible to access elements in O(1) and iterate in O(n).
    )prevr   r   nextc                    |j                   | _        || _        || _        d | _        |j
                  | |_        |j                   | |j                   _        | |_         y r9   )_last_bucketr   r   r   r   _first_bucket)r,   omdr   r   s       r    ro   z_omd_bucket.__init__.  sZ    .1.>.>	
.2	$ $C'$(C!r.   c                   | j                   r| j                  | j                   _        | j                  r| j                   | j                  _         |j                  | u r| j                  |_        |j                  | u r| j                   |_        y y r9   )r   r   r   r   )r,   r   s     r    unlinkz_omd_bucket.unlink:  sg    99!YYDIIN99!YYDIIN$ $		Ct##yyC $r.   N)r   _OrderedMultiDict[K, V]r   r   r   r   r0   r   )r   r   r0   r   )r)   r2   r3   r4   	__slots__ro   r   r5   r.   r    r   r   %  s     1I
 )r.   r   c                      e Zd ZdZ	 d	 	 	 d  fdZd!dZdZd"dZd#dZd$dZ	d%dZ
d&d	Zd'd
Zd(dZd)dZd*dZd+d,dZd-dZd.dZd&dZej*                  d/d       Zej*                  d0d       Z	 d	 	 	 	 	 d1dZd2dZdd3dZ	 	 	 	 d4dZd/dZej*                  d%d       Zej*                  d5d       Zej*                  d6d       Zef	 	 	 	 	 d7dZd8dZd9dZ xZS ):_OrderedMultiDicta  Works like a regular :class:`MultiDict` but preserves the
    order of the fields.  To convert the ordered multi dict into a
    list you can use the :meth:`items` method and pass it ``multi=True``.

    In general an :class:`OrderedMultiDict` is an order of magnitude
    slower than a :class:`MultiDict`.

    .. admonition:: note

       Due to a limitation in Python you cannot convert an ordered
       multi dict into a regular dict by using ``dict(multidict)``.
       Instead you have to use the :meth:`to_dict` method, otherwise
       the internal bucket objects are exposed.

    .. deprecated:: 3.1
        Will be removed in Werkzeug 3.2. Use ``MultiDict`` instead.
    Nc                    dd l }|j                  dt        d       t        |           d | _        d | _        || j                  |       y y )Nr   ^'OrderedMultiDict' is deprecated and will be removed in Werkzeug 3.2. Use 'MultiDict' instead.r   
stacklevel)warningswarnDeprecationWarningrn   ro   r   r   rz   )r,   r   r   rt   s      r    ro   z_OrderedMultiDict.__init__X  sX     	-	 	 	
 	7;6:KK  r.   c                   t        |t              st        S t        |t              rit	        | j                  d            }t	        |j                  d            }	 |D ]  \  }}t        |      \  }}||k7  s||k7  s y 	 	 t        |       yt        |       t        |      k7  ry| j                         D ]  \  }}	|j                  |      |	k7  s y y# t        $ r Y yw xY w# t        $ r Y yw xY w)NTr   F)r   r   r   r   iterr   r   StopIterationr   rp   r   )
r,   r   iter1iter2k1v1k2v2r   r   s
             r    __eq__z_OrderedMultiDict.__eq__o  s    %+!!e./$/0E401E# %FB!%[FBRx28$%U t9E
"::< 	KC}}S!V+	  !  ! s0    C ?C C C& 	C#"C#&	C21C2c                P    t        |       t        | j                  d            ffS NTr   )r(   r   r   r,   protocols     r    __reduce_ex__z_OrderedMultiDict.__reduce_ex__  s$    DzD$!78:::r.   c                8    t        | j                  d            S r  )r   r   r+   s    r    rw   z_OrderedMultiDict.__getstate__  s    DJJTJ*++r.   c                \    | j                          |D ]  \  }}| j                  ||        y r9   )ry   r   )r,   r   r   r   s       r    r{   z_OrderedMultiDict.__setstate__  s,    

  	!JCHHS% 	!r.   c                z    || v r#t         j                  | |      d   j                  S t        j                  |      Nr   )rv   r   r   r   r   r:   s     r    r   z_OrderedMultiDict.__getitem__  s8    $;##D#.q1777++C00r.   c                J    | j                  |       | j                  ||       y r9   r   r   r,   r   r   s      r    r   z_OrderedMultiDict.__setitem__  s    Ser.   c                &    | j                  |       y r9   )r   r:   s     r    __delitem__z_OrderedMultiDict.__delitem__  s    r.   c                0    d | j                         D        S )Nc              3  &   K   | ]	  \  }}|  y wr9   r5   )rj   r   _s      r    rm   z)_OrderedMultiDict.keys.<locals>.<genexpr>  s     /Q/   r   r+   s    r    keysz_OrderedMultiDict.keys  s    /$**,//r.   c                4    t        | j                               S r9   )r   r  r+   s    r    r}   z_OrderedMultiDict.__iter__  s    DIIK  r.   c                0    d | j                         D        S )Nc              3  &   K   | ]	  \  }}|  y wr9   r5   )rj   r   r   s      r    rm   z+_OrderedMultiDict.values.<locals>.<genexpr>  s     5*#u5r  r  r+   s    r    r   z_OrderedMultiDict.values  s    5

55r.   c              #  @  K   | j                   }|r-|*|j                  |j                  f |j                  }|)y y t	               }|S|j                  |vr5|j                  |j                         |j                  |j                  f |j                  }|Ry y wr9   )r   r   r   r   r   r   )r,   r   ptrreturned_keyss       r    r   z_OrderedMultiDict.items  s       /ggsyy((hh /  EM/77-/!%%cgg.''399,,hh	 /s   9BABBc              #     K   t               }| j                  }|b|j                  |vrD|j                  | j                  |j                        f |j	                  |j                         |j
                  }|ay y wr9   )r   r   r   r   r   r   )r,   r  r  s      r    rp   z_OrderedMultiDict.lists  sg       owwm+ggt||CGG444!!#''*((C	 os   A9A><A>c              #  D   K   | j                         D ]	  \  }}|  y wr9   rp   )r,   _keyr   s      r    r   z_OrderedMultiDict.listvalues  s$      JJL 	LD&L	    c                f    t         j                  | |g       j                  t        | ||             y r9   )rv   rq   rr   r   r  s      r    r   z_OrderedMultiDict.add  s&    c2&--k$U.KLr.   c                     y r9   r5   r:   s     r    r   z_OrderedMultiDict.getlist  r   r.   c                     y r9   r5   rD   s      r    r   z_OrderedMultiDict.getlist  r   r.   c                   	 t         j                  | |      }||D cg c]  }|j                   c}S g }|D ]$  }	 |j	                   ||j                               & |S # t        $ r g cY S w xY wc c}w # t
        t        f$ r Y Pw xY wr9   )rv   r   rJ   r   rr   rK   rL   )r,   r   r(   rM   xr   r   s          r    r   z_OrderedMultiDict.getlist  s    
	!!$,B <%'(AGG(( 	Dd4::./	
   	I	 )
 	* s'   A! A2!A7!A/.A/7B	B	c                X    | j                  |       |D ]  }| j                  ||        y r9   r  )r,   r   r   r   s       r    r   z_OrderedMultiDict.setlist  s+    S 	!EHHS% 	!r.   c                    t        d      )Nz5setlistdefault is unsupported for ordered multi dicts)rL   )r,   r   r   s      r    r   z _OrderedMultiDict.setlistdefault  s    OPPr.   c                N    t        |      D ]  \  }}| j                  ||        y r9   r   r   s       r    rz   z_OrderedMultiDict.update  s*     +73 	!JCHHS% 	!r.   c                    t         j                  | |d      }|D ]  }|j                  |         |D cg c]  }|j                   c}S c c}w Nr5   )rv   r   r   r   )r,   r   bucketsbucketr)  s        r    r   z_OrderedMultiDict.poplist  sG    48HHT34K 	 FMM$	 !()A)))s   A
c                     y r9   r5   r:   s     r    r   z_OrderedMultiDict.pop  r   r.   c                     y r9   r5   r>   s      r    r   z_OrderedMultiDict.pop  r@   r.   c                     y r9   r5   r>   s      r    r   z_OrderedMultiDict.pop  rB   r.   c                    	 t         j                  | |      }|D ]  }|j                  |         |d   j                  S # t        $ r# |t        ur|cY S t	        j
                  |      d w xY wr  )rv   r   rJ   r   r   r   r   r   )r,   r   r?   r/  r0  s        r    r   z_OrderedMultiDict.pop  sw    	?hhtS)G  	 FMM$	  qz  	?h&//4$>		?s   ? A+A+c                    	 t         j                  |       \  }}|D ]  }|j                  |         ||d   j                  fS # t        $ r(}t        j                  |j
                  d         d d }~ww xY wr  rv   r   rJ   r   r   r   r   r   )r,   r   r/  r   r0  s        r    r   z_OrderedMultiDict.popitem  s}    	E<<-LC  	 FMM$	  GAJ$$$$  	E//q	:D	Es   A 	A4#A//A4c                   	 t         j                  |       \  }}|D ]  }|j                  |         ||D cg c]  }|j                   c}fS # t        $ r(}t        j                  |j
                  d         d d }~ww xY wc c}w r  r6  )r,   r   r/  r   r0  r)  s         r    r   z_OrderedMultiDict.popitemlist!  s    	E<<-LC  	 FMM$	  g.QWW...  	E//q	:D	E /s   A B	A?#A::A?r9   r   )r   objectr0   r   r	  t.SupportsIndexr0   r   r   )r   r   r0   r   r   r   r   r0   zcabc.Iterable[K]r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r0   
t.NoReturnr   rP   rQ   r   r   r   ) r)   r2   r3   r4   ro   r  __hash__r
  rw   r{   r   r   r  r  r}   r   r   rp   r   r   rZ   r[   r   r   r   rz   r   r   r   r   r   r   r   s   @r    r   r   E  sK   2 !! 
!.2 H;,!1
0!6M ZZ- -ZZJ J;?8	&!
Q	!)	! 
	!* ZZ# #ZZ/ /ZZ3 3 "     
	 (%/r.   r   c                  4    e Zd ZdZddZdd fdZeddd       Zd dZe	j                  d!d       Ze	j                  d"d       Ze	j                  d#d       Ze	j                  d$d	       Ze	j                  d%d
       Z	 	 d&	 	 	 	 	 	 	 d'dZe	j                  d(d       Ze	j                  d)d       Z	 d	 	 	 	 	 d*dZd+dZd,dZd-dZe	j                  d.d       Ze	j                  d/d       Z	 d0	 	 	 d1dZd2dZd3dZd4dZd5dZd6dZd7dZd8dZ xZS )9CombinedMultiDicta>  A read only :class:`MultiDict` that you can pass multiple :class:`MultiDict`
    instances as sequence and it will combine the return values of all wrapped
    dicts:

    >>> from werkzeug.datastructures import CombinedMultiDict, MultiDict
    >>> post = MultiDict([('foo', 'bar')])
    >>> get = MultiDict([('blub', 'blah')])
    >>> combined = CombinedMultiDict([get, post])
    >>> combined['foo']
    'bar'
    >>> combined['blub']
    'blah'

    This works for all read operations and will raise a `TypeError` for
    methods that usually change data which isn't possible.

    From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a
    subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will
    render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP
    exceptions.
    c                2    t        |       | j                  ffS r9   )r(   dictsr  s     r    r
  zCombinedMultiDict.__reduce_ex__G  s    DzDJJ=((r.   c                J    t         |           t        |xs d      | _        y r.  )rn   ro   r   rA  )r,   rA  rt   s     r    ro   zCombinedMultiDict.__init__J  s    ,0",=
r.   c                4    t        d| j                  d      )Nzcannot create z instances by fromkeys)rL   r)   )clsr  r   s      r    fromkeyszCombinedMultiDict.fromkeysN  s    .(88NOPPr.   c                d    | j                   D ]  }||v s||   c S  t        j                  |      r9   )rA  r   r   r,   r   ds      r    r   zCombinedMultiDict.__getitem__R  s8     	Aaxv	 ++C00r.   c                     y r9   r5   r:   s     r    r;   zCombinedMultiDict.getX  r<   r.   c                     y r9   r5   r>   s      r    r;   zCombinedMultiDict.getZ  r@   r.   c                     y r9   r5   r>   s      r    r;   zCombinedMultiDict.get\  rB   r.   c                     y r9   r5   rD   s      r    r;   zCombinedMultiDict.get^  rE   r.   c                     y r9   r5   rG   s       r    r;   zCombinedMultiDict.get`  rH   r.   c                    | j                   D ]  }||v s|	  |||         c S ||   c S  |S # t        t        f$ r Y 3w xY wr9   )rA  rK   rL   )r,   r   r?   r(   rH  s        r    r;   zCombinedMultiDict.getb  sb      	Aax#!#AcF|+ v	  '	2 ! !s   
/A Ac                     y r9   r5   r:   s     r    r   zCombinedMultiDict.getlistr  r   r.   c                     y r9   r5   rD   s      r    r   zCombinedMultiDict.getlistt  r   r.   c                n    g }| j                   D ]#  }|j                  |j                  ||             % |S r9   )rA  extendr   )r,   r   r(   rM   rH  s        r    r   zCombinedMultiDict.getlistv  s8      	,AIIaiiT*+	,	r.   c                :    t        d | j                  D              S )zThis function exists so __len__ can be implemented more efficiently,
        saving one list creation from an iterator.
        c              3  .   K   | ]  }|D ]  }|   y wr9   r5   )rj   rH  rk   s      r    rm   z/CombinedMultiDict._keys_impl.<locals>.<genexpr>  s     4!4Q1414s   )r   rA  r+   s    r    
_keys_implzCombinedMultiDict._keys_impl~  s     4djj444r.   c                "    | j                         S r9   )rU  r+   s    r    r  zCombinedMultiDict.keys  s      r.   c                4    t        | j                               S r9   )r   rU  r+   s    r    r}   zCombinedMultiDict.__iter__  s    DOO%&&r.   c                     y r9   r5   r+   s    r    r   zCombinedMultiDict.items  r   r.   c                     y r9   r5   )r,   r   s     r    r   zCombinedMultiDict.items  s    QTr.   c              #     K   t               }| j                  D ]@  }|j                  |      D ]*  \  }}|r||f ||vs|j                  |       ||f , B y wr9   )r   rA  r   r   )r,   r   foundrH  r   r   s         r    r   zCombinedMultiDict.items  sg       	%Aggen %
Uu*$%IIcNu*$%	%s   >AAc              #  D   K   | j                         D ]	  \  }}|  y wr9   r  )r,   r  r   s      r    r   zCombinedMultiDict.values  s$     

 	HAuK	r$  c                    i }| j                   D ];  }|j                         D ]&  \  }}|j                  |g       j                  |       ( = |j	                         S r9   )rA  rp   rq   rR  r   )r,   rM   rH  r   r   s        r    rp   zCombinedMultiDict.lists  sZ    ! 	6A wwy 6Vc2&--f56	6 xxzr.   c                0    d | j                         D        S )Nc              3  &   K   | ]	  }|d      yw)r	   Nr5   )rj   r)  s     r    rm   z/CombinedMultiDict.listvalues.<locals>.<genexpr>  s     +!+r  r"  r+   s    r    r   zCombinedMultiDict.listvalues  s    +djjl++r.   c                    t        |       S )a0  Return a shallow mutable copy of this object.

        This returns a :class:`MultiDict` representing the data at the
        time of copying. The copy will no longer reflect changes to the
        wrapped dicts.

        .. versionchanged:: 0.15
            Return a mutable :class:`MultiDict`.
        r   r+   s    r    r`   zCombinedMultiDict.copy  s     r.   c                4    t        | j                               S r9   )r   rU  r+   s    r    __len__zCombinedMultiDict.__len__  s    4??$%%r.   c                2    | j                   D ]  }||v s y y)NTF)rA  rG  s      r    __contains__zCombinedMultiDict.__contains__  s$     	Aax	 r.   c                L    t        |       j                   d| j                  dS r%   )r(   r)   rA  r+   s    r    r*   zCombinedMultiDict.__repr__  s$    t*%%&a

~Q77r.   r9  r9   )rA  z%cabc.Iterable[MultiDict[K, V]] | Noner0   r   )r  r   r   r   r0   r<  r   rN   rP   rQ   rS   rU   rV   rW   r   r   r   )r0   zset[K]r;  r   )r0   r   )r   zt.Literal[True]r0   r   r   )r   r   r0   z=cabc.Iterable[tuple[K, V]] | cabc.Iterable[tuple[K, list[V]]]r   r   r   r0   r   r0   int)r   r   r0   r   r/   )r)   r2   r3   r4   r
  ro   classmethodrE  r   rZ   r[   r;   r   rU  r  r}   r   r   rp   r   r`   rc  re  r*   r   r   s   @r    r?  r?  0  sr   ,)> Q Q1 ZZ* *ZZ/ /ZZ3 3ZZI IZZN N !%-1	  +	
 
  ZZ- -ZZJ J;?8	5!' ZZ6 6ZZT T!
%
%	F
%,
&8r.   r?  c                  (    e Zd ZdZddZddZddZy)	ImmutableDictz;An immutable :class:`dict`.

    .. versionadded:: 0.5
    c                ^    t        |       j                   dt        j                  |        dS r%   )r(   r)   rv   r*   r+   s    r    r*   zImmutableDict.__repr__  r-   r.   c                    t        |       S r_   )rv   r+   s    r    r`   zImmutableDict.copy  s    
 Dzr.   c                    | S r9   r5   r+   s    r    rb   zImmutableDict.__copy__  rc   r.   Nr/   r   rd   )r)   r2   r3   r4   r*   r`   rb   r5   r.   r    rl  rl    s    
?r.   rl  c                       e Zd ZdZddZddZy)ImmutableMultiDictz@An immutable :class:`MultiDict`.

    .. versionadded:: 0.5
    c                    t        |       S r_   ra  r+   s    r    r`   zImmutableMultiDict.copy  s    
 r.   c                    | S r9   r5   r+   s    r    rb   zImmutableMultiDict.__copy__  rc   r.   Nrg  rd   rf   r5   r.   r    rq  rq    s    
r.   rq  c                  F     e Zd ZdZ	 d	 	 	 d fdZddZd	dZd
dZ xZS )_ImmutableOrderedMultiDictzAn immutable :class:`OrderedMultiDict`.

    .. deprecated:: 3.1
        Will be removed in Werkzeug 3.2. Use ``ImmutableMultiDict`` instead.

    .. versionadded:: 0.6
    c                |    t         |           |+t        |      D ]  \  }}t        j	                  | ||        y y r9   )rn   ro   r!   r   r   )r,   r   rk   r   rt   s       r    ro   z#_ImmutableOrderedMultiDict.__init__  sE     	(1 21!%%dAq12 r.   c                8    t        | j                  d            S r  )	enumerater   r+   s    r    _iter_hashitemsz*_ImmutableOrderedMultiDict._iter_hashitems   s    $/00r.   c                    t        |       S r_   )r   r+   s    r    r`   z_ImmutableOrderedMultiDict.copy  s    
 !&&r.   c                    | S r9   r5   r+   s    r    rb   z#_ImmutableOrderedMultiDict.__copy__
  rc   r.   r9   r   )r0   zcabc.Iterable[t.Any])r0   r   rd   )	r)   r2   r3   r4   ro   ry  r`   rb   r   r   s   @r    ru  ru    s5     22 
21'r.   ru  c                  @     e Zd ZdZ	 	 d	 	 	 	 	 d fdZd fdZ xZS )CallbackDictzwA dict that calls a function passed every time something is changed.
    The function is passed the dict instance.
    c                b    |t         |           || _        y t         |   |       || _        y r9   )rn   ro   	on_update)r,   initialr  rt   s      r    ro   zCallbackDict.__init__  s4    
 ?G # GW%"r.   c                T    dt        |       j                   dt        |           dS )N< >)r(   r)   rn   r*   r~   s    r    r*   zCallbackDict.__repr__  s,    4:&&'q)9);(<A>>r.   rV   )r  z6cabc.Mapping[K, V] | cabc.Iterable[tuple[K, V]] | Noner  %cabc.Callable[[te.Self], None] | Noner0   r   r/   )r)   r2   r3   r4   ro   r*   r   r   s   @r    r}  r}    s=     KO;?
#G
# 9
# 
	
#? ?r.   r}  c                      e Zd ZdZ	 	 d	 	 	 	 	 ddZddZddZddZddZddZ	dd	Z
dd
ZdddZddZd dZd!dZd"dZd#dZd$dZd%dZd&dZddZddZy)'	HeaderSeta  Similar to the :class:`ETags` class this implements a set-like structure.
    Unlike :class:`ETags` this is case insensitive and used for vary, allow, and
    content-language headers.

    If not constructed using the :func:`parse_set_header` function the
    instantiation works like this:

    >>> hs = HeaderSet(['foo', 'bar', 'baz'])
    >>> hs
    HeaderSet(['foo', 'bar', 'baz'])
    Nc                    t        |xs d      | _        | j                  D ch c]  }|j                          c}| _        || _        y c c}w r.  )r   _headerslower_setr  )r,   headersr  r)  s       r    ro   zHeaderSet.__init__0  s<    
 W]+(,61QWWY6	" 7s   A
c                (    | j                  |f       y)zAdd a new header to the set.N)rz   r,   headers     r    r   zHeaderSet.add9  s    VIr.   c                F   |j                         }|| j                  vrt        |      | j                  j                  |       t	        | j
                        D ]'  \  }}|j                         |k(  s| j
                  |=  n | j                  | j                  |        yy)aC  Remove a header from the set.  This raises an :exc:`KeyError` if the
        header is not in the set.

        .. versionchanged:: 0.5
            In older versions a :exc:`IndexError` was raised instead of a
            :exc:`KeyError` if the object was missing.

        :param header: the header to be removed.
        N)r  r  rJ   removerx  r  r  )r,   r  r   idxs       r    r  zHeaderSet.remove=  s     llndii6""		!$--0 	HCyy{f$MM#&	 >>%NN4  &r.   c                   d}|D ]Y  }|j                         }|| j                  vs"| j                  j                  |       | j                  j	                  |       d}[ |r| j
                  | j                  |        yyy)zAdd all the headers from the iterable to the set.

        :param iterable: updates the set with the items from the iterable.
        FTN)r  r  r  rr   r   r  )r,   iterableinserted_anyr  r   s        r    rz   zHeaderSet.updateR  sw    
  	$F,,.C$))#$$V,		c"#	$ DNN6NN4  7<r.   c                F    	 | j                  |       y# t        $ r Y yw xY w)zdLike :meth:`remove` but ignores errors.

        :param header: the header to be discarded.
        N)r  rJ   r  s     r    discardzHeaderSet.discarda  s%    
	KK 		s    	  c                    |j                         }t        | j                        D ]  \  }}|j                         |k(  s|c S  y)zReturn the index of the header in the set or return -1 if not found.

        :param header: the header to be looked up.
        )r  rx  r  )r,   r  r  r   s       r    findzHeaderSet.findk  sC    
 "4==1 	ICzz|v%
	 r.   c                H    | j                  |      }|dk  rt        |      |S )zReturn the index of the header in the set or raise an
        :exc:`IndexError`.

        :param header: the header to be looked up.
        r   )r  
IndexError)r,   r  rM   s      r    indexzHeaderSet.indexv  s)     YYv6V$$	r.   c                    | j                   j                          | j                  j                          | j                  | j                  |        yy)zClear the set.N)r  ry   r  r  r+   s    r    ry   zHeaderSet.clear  s;    		>>%NN4  &r.   c                Z    |rt        | j                        S t        | j                        S )a  Return the set as real python set type.  When calling this, all
        the items are converted to lowercase and the ordering is lost.

        :param preserve_casing: if set to `True` the items in the set returned
                                will have the original case like in the
                                :class:`HeaderSet`, otherwise they will
                                be lowercase.
        )r   r  r  )r,   preserve_casings     r    as_setzHeaderSet.as_set  s$     t}}%%499~r.   c                h    dj                  t        t        j                  | j                              S )z2Convert the header set into an HTTP header string.z, )joinmaphttpquote_header_valuer  r+   s    r    	to_headerzHeaderSet.to_header  s"    yyT44dmmDEEr.   c                     | j                   |   S r9   )r  )r,   r  s     r    r   zHeaderSet.__getitem__  s    }}S!!r.   c                    | j                   j                  |      }| j                  j                  |j	                                | j
                  | j                  |        y y r9   )r  r   r  r  r  r  )r,   r  rM   s      r    r  zHeaderSet.__delitem__  sI    ]]s#		$>>%NN4  &r.   c                    | j                   |   }| j                  j                  |j                                || j                   |<   | j                  j	                  |j                                | j
                  | j                  |        y y r9   )r  r  r  r  r   r  )r,   r  r   olds       r    r   zHeaderSet.__setitem__  sg    mmC 		%"c		ekkm$>>%NN4  &r.   c                :    |j                         | j                  v S r9   )r  r  r  s     r    re  zHeaderSet.__contains__  s    ||~**r.   c                ,    t        | j                        S r9   )r   r  r+   s    r    rc  zHeaderSet.__len__  s    499~r.   c                ,    t        | j                        S r9   )r   r  r+   s    r    r}   zHeaderSet.__iter__  s    DMM""r.   c                ,    t        | j                        S r9   )r   r  r+   s    r    __bool__zHeaderSet.__bool__  s    DIIr.   c                "    | j                         S r9   )r  r+   s    r    __str__zHeaderSet.__str__  s    ~~r.   c                L    t        |       j                   d| j                  dS r%   )r(   r)   r  r+   s    r    r*   zHeaderSet.__repr__  s%    t*%%&a'8::r.   rV   )r  zcabc.Iterable[str] | Noner  r  r0   r   )r  r1   r0   r   )r,   re   r  r1   r0   r   )r,   re   r  zcabc.Iterable[str]r0   r   )r  r1   r0   ri  )r,   re   r0   r   r   )r  r   r0   zset[str]r/   )r  r:  r0   r1   )r,   re   r  r:  r0   r   )r,   re   r  r:  r   r1   r0   r   )r  r1   r0   r   rh  )r0   zcabc.Iterator[str])r0   r   )r)   r2   r3   r4   ro   r   r  rz   r  r  r  ry   r  r  r   r  r   re  rc  r}   r  r  r*   r5   r.   r    r  r  #  s    
 .2;?#*# 9# 
	#!*!		!F"!!+# ;r.   r  )r  c                    dd l }| dk(  r|j                  dt        d       t        S | dk(  r|j                  dt        d       t        S t        |       )Nr   OrderedMultiDictr   r   r   ImmutableOrderedMultiDictzp'ImmutableOrderedMultiDict' is deprecated and will be removed in Werkzeug 3.2. Use 'ImmutableMultiDict' instead.)r   r   r   r   ru  AttributeError)namer   s     r    __getattr__r    sj    !!-	 	 	
 ! **?	 	 	
 *)

r.   )r   r   r0   zcabc.Iterator[tuple[K, V]])r  r1   r0   r   )-
__future__r   collections.abcabcr   typingrZ   r`   r    r   	_internalr   mixinsr
   r   r   r   TYPE_CHECKINGtyping_extensionsteTypeVarr   r   r   r!   r   r#   rv   r7   r]   r   Genericr   r   r?  rl  rq  ru  r}  
MutableSetr1   r  r  r  r5   r.   r    <module>r     s   "       & & + #??"AIIcNAIIcNAIIcN	%  .	?&Q 	?;ad ;|"4QT":<NqRSt<T $YJ"1a4( YJx)!))AqD/ )@h/	!Q$ h/VN8/15yA N8b&q!t,d1a4j (0A6	!Q$ "%AqD!#4QT#:%P??1a4($q!t* ?*X;$ X;x r.   