o
    uvXjÒ'  ã                   @   sŠ   d dl Z d dlmZ d dlmZ G dd„ dƒZG dd„ deƒZG dd	„ d	eƒZ	G d
d„ de
ƒZG dd„ deƒZdd„ ZG dd„ deƒZdS )é    N)ÚOrderedDict)ÚMappingc                   @   sR   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S )Ú
OrderedSetze
    A set which keeps the ordering of the inserted items.
    Currently backs onto OrderedDict.
    Nc                 C   s   t  |pd¡| _d S )N© )r   ÚfromkeysÚdict)ÚselfÚiterabler   r   úX/var/www/html/myproject/venv/lib/python3.10/site-packages/django/utils/datastructures.pyÚ__init__   ó   zOrderedSet.__init__c                 C   s   d | j |< d S ©N©r   ©r   Úitemr   r   r
   Úadd   s   zOrderedSet.addc                 C   s   | j |= d S r   r   r   r   r   r
   Úremove   s   zOrderedSet.removec                 C   s&   z|   |¡ W d S  ty   Y d S w r   )r   ÚKeyErrorr   r   r   r
   Údiscard   s
   ÿzOrderedSet.discardc                 C   ó
   t | jƒS r   )Úiterr   ©r   r   r   r
   Ú__iter__   ó   
zOrderedSet.__iter__c                 C   s
   || j v S r   r   r   r   r   r
   Ú__contains__   r   zOrderedSet.__contains__c                 C   r   r   )Úboolr   r   r   r   r
   Ú__bool__!   r   zOrderedSet.__bool__c                 C   r   r   )Úlenr   r   r   r   r
   Ú__len__$   r   zOrderedSet.__len__r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r
   r      s    
r   c                   @   s   e Zd ZdS )ÚMultiValueDictKeyErrorN)r   r    r!   r   r   r   r
   r#   (   s    r#   c                       sä   e Zd ZdZd/‡ fdd„	Z‡ fdd„Z‡ fdd„Z‡ fd	d
„Zdd„ Zdd„ Z	dd„ Z
dd„ Zd0dd„Zd1‡ fdd„	Zd0dd„Z‡ fdd„Zd0dd„Zd0dd „Zd!d"„ Zd#d$„ Z‡ fd%d&„Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Z‡  ZS )2ÚMultiValueDicta¤  
    A subclass of dictionary customized to handle multiple values for the
    same key.

    >>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
    >>> d['name']
    'Simon'
    >>> d.getlist('name')
    ['Adrian', 'Simon']
    >>> d.getlist('doesnotexist')
    []
    >>> d.getlist('doesnotexist', ['Adrian', 'Simon'])
    ['Adrian', 'Simon']
    >>> d.get('lastname', 'nonexistent')
    'nonexistent'
    >>> d.setlist('lastname', ['Holovaty', 'Willison'])

    This class exists to solve the irritating problem raised by cgi.parse_qs,
    which returns a list for every key, even though most Web forms submit
    single name-value pairs.
    r   c                    s   t ƒ  |¡ d S r   )Úsuperr   )r   Úkey_to_list_mapping©Ú	__class__r   r
   r   B   s   zMultiValueDict.__init__c                    s   d| j jtƒ  ¡ f S )Nz<%s: %s>)r(   r   r%   Ú__repr__r   r'   r   r
   r)   E   s   zMultiValueDict.__repr__c                    sJ   zt ƒ  |¡}W n ty   t|ƒ‚w z|d W S  ty$   g  Y S w )z|
        Return the last data value for this key, or [] if it's an empty list;
        raise KeyError if not found.
        éÿÿÿÿ)r%   Ú__getitem__r   r#   Ú
IndexError©r   ÚkeyÚlist_r'   r   r
   r+   H   s   ÿ
ÿzMultiValueDict.__getitem__c                    s   t ƒ  ||g¡ d S r   ©r%   Ú__setitem__©r   r.   Úvaluer'   r   r
   r1   V   r   zMultiValueDict.__setitem__c                 C   s   |   dd„ |  ¡ D ƒ¡S )Nc                 S   s    g | ]\}}||d d … f‘qS r   r   ©Ú.0ÚkÚvr   r   r
   Ú
<listcomp>Z   s    ÿÿz+MultiValueDict.__copy__.<locals>.<listcomp>)r(   Úlistsr   r   r   r
   Ú__copy__Y   s   
þzMultiValueDict.__copy__c              	   C   sJ   |   ¡ }||t| ƒ< t | ¡D ]\}}t |t ||¡t ||¡¡ q|S r   )r(   Úidr   Úitemsr1   ÚcopyÚdeepcopy)r   ÚmemoÚresultr.   r3   r   r   r
   Ú__deepcopy___   s   
ÿzMultiValueDict.__deepcopy__c                    s    i ˆ j ¥d‡ fdd„ˆ D ƒi¥S )NÚ_datac                    s   i | ]}|ˆ   |¡“qS r   ©Ú_getlist)r5   r6   r   r   r
   Ú
<dictcomp>h   s    z/MultiValueDict.__getstate__.<locals>.<dictcomp>)Ú__dict__r   r   r   r
   Ú__getstate__g   s    zMultiValueDict.__getstate__c                 C   s:   |  di ¡}| ¡ D ]
\}}|  ||¡ q
| j |¡ d S )NrB   )Úpopr<   ÚsetlistrF   Úupdate)r   Úobj_dictÚdatar6   r7   r   r   r
   Ú__setstate__j   s   zMultiValueDict.__setstate__Nc                 C   s4   z| | }W n t y   | Y S w |g kr|S |S )zŠ
        Return the last data value for the passed key. If key doesn't exist
        or value is an empty list, return `default`.
        )r   )r   r.   ÚdefaultÚvalr   r   r
   Úgetp   s   ÿzMultiValueDict.getFc                    sT   zt ƒ  |¡}W n ty   |du rg  Y S | Y S w |r(|dur&t|ƒnd}|S )z¦
        Return a list of values for the key.

        Used internally to manipulate values list. If force_list is True,
        return a new copy of values.
        N)r%   r+   r   Úlist)r   r.   rN   Ú
force_listÚvaluesr'   r   r
   rD   }   s   ýzMultiValueDict._getlistc                 C   s   | j ||dd�S )zn
        Return the list of values for the key. If key doesn't exist, return a
        default value.
        T)rR   rC   ©r   r.   rN   r   r   r
   Úgetlist�   s   zMultiValueDict.getlistc                    s   t ƒ  ||¡ d S r   r0   r-   r'   r   r
   rI   –   ó   zMultiValueDict.setlistc                 C   s   || vr|| |< | | S r   r   rT   r   r   r
   Ú
setdefault™   s   zMultiValueDict.setdefaultc                 C   s*   || vr|d u r
g }|   ||¡ |  |¡S r   )rI   rD   )r   r.   Údefault_listr   r   r
   Úsetlistdefault    s
   
zMultiValueDict.setlistdefaultc                 C   s   |   |¡ |¡ dS )z8Append an item to the internal list associated with key.N)rY   Úappendr2   r   r   r
   Ú
appendlist©   s   zMultiValueDict.appendlistc                 c   s   � | D ]	}|| | fV  qdS )zu
        Yield (key, value) pairs, where value is the last item in the list
        associated with the key.
        Nr   ©r   r.   r   r   r
   r<   ­   s   €ÿzMultiValueDict.itemsc                    s   t tƒ  ¡ ƒS )zYield (key, list) pairs.)r   r%   r<   r   r'   r   r
   r9   µ   s   zMultiValueDict.listsc                 c   s   � | D ]}| | V  qdS )z'Yield the last value on every key list.Nr   r\   r   r   r
   rS   ¹   s   €ÿzMultiValueDict.valuesc                 C   s
   t   | ¡S )z%Return a shallow copy of this object.)r=   r   r   r   r
   r=   ¾   s   
zMultiValueDict.copyc                 O   sº   t |ƒdkrtdt |ƒ ƒ‚|rJ|d }t|tƒr+| ¡ D ]\}}|  |¡ |¡ qnz| ¡ D ]\}}|  |¡ |¡ q0W n tyI   t	dƒ‚w | ¡ D ]\}}|  |¡ |¡ qNdS )z.Extend rather than replace existing key lists.é   z*update expected at most 1 argument, got %dr   zCMultiValueDict.update() takes either a MultiValueDict or dictionaryN)
r   Ú	TypeErrorÚ
isinstancer$   r9   rY   Úextendr<   rZ   Ú
ValueError)r   ÚargsÚkwargsÚ
other_dictr.   Ú
value_listr3   r   r   r
   rJ   Â   s$   
ÿÿÿÿzMultiValueDict.updatec                    s   ‡ fdd„ˆ D ƒS )z5Return current object as a dict with singular values.c                    s   i | ]}|ˆ | “qS r   r   )r5   r.   r   r   r
   rE   Ö   ó    z'MultiValueDict.dict.<locals>.<dictcomp>r   r   r   r   r
   r   Ô   s   zMultiValueDict.dict)r   r   )NF)r   r    r!   r"   r   r)   r+   r1   r:   rA   rG   rM   rP   rD   rU   rI   rW   rY   r[   r<   r9   rS   r=   rJ   r   Ú__classcell__r   r   r'   r
   r$   ,   s.    



	r$   c                   @   sZ   e Zd ZdZddœdd„Zdd„ ZeZeZeZeZ	eZ
eZeZeZeZeZeZeZeZdS )	ÚImmutableLista0  
    A tuple-like object that raises useful errors when it is asked to mutate.

    Example::

        >>> a = ImmutableList(range(5), warning="You cannot mutate this.")
        >>> a[3] = '4'
        Traceback (most recent call last):
            ...
        AttributeError: You cannot mutate this.
    z"ImmutableList object is immutable.)Úwarningc                O   s"   t j| g|¢R i |¤Ž}||_|S r   )ÚtupleÚ__new__ri   )Úclsri   rb   rc   r   r   r   r
   rk   æ   s   zImmutableList.__new__c                 O   s   t | jtƒr	| j‚t| jƒ‚r   )r_   ri   Ú	ExceptionÚAttributeError)r   Úwargsrc   r   r   r
   Úcomplainë   s   
zImmutableList.complainN)r   r    r!   r"   rk   rp   Ú__delitem__Ú__delslice__Ú__iadd__Ú__imul__r1   Ú__setslice__rZ   r`   ÚinsertrH   r   ÚsortÚreverser   r   r   r
   rh   Ù   s"    rh   c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚDictWrapperaG  
    Wrap accesses to a dictionary so that certain values (those starting with
    the specified prefix) are passed through a function before being returned.
    The prefix is removed before looking up the real value.

    Used by the SQL construction code to ensure that values are correctly
    quoted before being used.
    c                    s   t ƒ  |¡ || _|| _d S r   )r%   r   ÚfuncÚprefix)r   rL   rz   r{   r'   r   r
   r   
  s   
zDictWrapper.__init__c                    s@   |  | j¡}|r|t| jƒd… }tƒ  |¡}|r|  |¡S |S )zÖ
        Retrieve the real value after stripping the prefix string (if
        present). If the prefix is present, pass the value through self.func
        before returning, otherwise return the raw value.
        N)Ú
startswithr{   r   r%   r+   rz   )r   r.   Úuse_funcr3   r'   r   r
   r+     s   
zDictWrapper.__getitem__)r   r    r!   r"   r   r+   rg   r   r   r'   r
   ry     s    ry   c                 c   s`   � t | ƒD ](\}}t|ƒdkrtd |t|ƒ¡ƒ‚t|d tƒs(td|d  ƒ‚t|ƒV  qd S )Né   zDdictionary update sequence element #{} has length {}; 2 is required.r   z0Element key %r invalid, only strings are allowed)Ú	enumerater   ra   Úformatr_   Ústrrj   )rL   ÚiÚelemr   r   r
   Ú!_destruct_iterable_mapping_values  s   €þør„   c                   @   sH   e Z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S )ÚCaseInsensitiveMappinga•  
    Mapping allowing case-insensitive key lookups. Original case of keys is
    preserved for iteration and string representation.

    Example::

        >>> ci_map = CaseInsensitiveMapping({'name': 'Jane'})
        >>> ci_map['Name']
        Jane
        >>> ci_map['NAME']
        Jane
        >>> ci_map['name']
        Jane
        >>> ci_map  # original case preserved
        {'name': 'Jane'}
    c                 C   s4   t |tƒsdd„ t|ƒD ƒ}dd„ | ¡ D ƒ| _d S )Nc                 S   ó   i | ]\}}||“qS r   r   r4   r   r   r
   rE   >  rf   z3CaseInsensitiveMapping.__init__.<locals>.<dictcomp>c                 S   s   i | ]\}}|  ¡ ||f“qS r   ©Úlowerr4   r   r   r
   rE   ?  s    )r_   r   r„   r<   Ú_store)r   rL   r   r   r
   r   <  s   
zCaseInsensitiveMapping.__init__c                 C   s   | j | ¡  d S )Nr]   )r‰   rˆ   r\   r   r   r
   r+   A  rV   z"CaseInsensitiveMapping.__getitem__c                 C   r   r   )r   r‰   r   r   r   r
   r   D  r   zCaseInsensitiveMapping.__len__c                 C   s.   t |tƒodd„ |  ¡ D ƒdd„ | ¡ D ƒkS )Nc                 S   ó   i | ]	\}}|  ¡ |“qS r   r‡   r4   r   r   r
   rE   H  ó    ÿz1CaseInsensitiveMapping.__eq__.<locals>.<dictcomp>c                 S   rŠ   r   r‡   r4   r   r   r
   rE   J  r‹   )r_   r   r<   )r   Úotherr   r   r
   Ú__eq__G  s   ÿÿþzCaseInsensitiveMapping.__eq__c                 C   s   dd„ | j  ¡ D ƒS )Nc                 s   s   � | ]\}}|V  qd S r   r   )r5   Úoriginal_keyr3   r   r   r
   Ú	<genexpr>O  s   € z2CaseInsensitiveMapping.__iter__.<locals>.<genexpr>)r‰   rS   r   r   r   r
   r   N  r   zCaseInsensitiveMapping.__iter__c                 C   s   t dd„ | j ¡ D ƒƒS )Nc                 S   r†   r   r   )r5   r.   r3   r   r   r
   rE   R  rf   z3CaseInsensitiveMapping.__repr__.<locals>.<dictcomp>)Úreprr‰   rS   r   r   r   r
   r)   Q  s   zCaseInsensitiveMapping.__repr__c                 C   s   | S r   r   r   r   r   r
   r=   T  s   zCaseInsensitiveMapping.copyN)r   r    r!   r"   r   r+   r   r�   r   r)   r=   r   r   r   r
   r…   *  s    r…   )r=   Úcollectionsr   Úcollections.abcr   r   r   r#   r   r$   rj   rh   ry   r„   r…   r   r   r   r
   Ú<module>   s    " .(