o
    þ§Ýj  ã                   @  sÚ   d 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 ddlmZ ddlmZ ddlmZ ddlmZ G dd„ deeef eeef ƒZG dd„ deeef ƒZdS )z3Provide :class:`MutableBidict` and :class:`bidict`.é    )ÚannotationsNé   )ÚMutableBidirectionalMapping)Ú
BidictBase)ÚON_DUP_DROP_OLD)ÚON_DUP_RAISE)ÚOnDup)ÚDT)ÚKT)ÚMISSING)ÚODT)ÚVT)Ú
MapOrItemsc                   @  sÜ   e Zd ZdZejred8dd„ƒZed8dd„ƒZd9dd„Z	d:dd„Z
d;dd„Zefd<dd„Zd;dd„Zd=dd„Zejd9dd„ƒZejd>d?d!d„ƒZefd@d#d„ZdAd%d&„ZdBdCd+d,„ZdBdCd-d.„ZefdDd0d1„ZdEd5d6„Zd7S )FÚMutableBidictz.Base class for mutable bidirectional mappings.ÚreturnúMutableBidict[VT, KT]c                 C  ó   d S ©N© ©Úselfr   r   úI/var/www/html/chatgpt/venv/lib/python3.10/site-packages/bidict/_bidict.pyÚinverse'   ó   zMutableBidict.inversec                 C  r   r   r   r   r   r   r   Úinv*   r   zMutableBidict.invÚkeyr
   r   c                 C  s   | j  |¡}| j|= |S r   )Ú_fwdmÚpopÚ_invm©r   r   Úvalr   r   r   Ú_pop-   s   zMutableBidict._popÚNonec                 C  s   |   |¡ dS )u#   *x.__delitem__(y)ã€€âŸºã€€del x[y]*N)r!   ©r   r   r   r   r   Ú__delitem__2   s   zMutableBidict.__delitem__r    c                 C  s   | j ||| jd� dS )a*  Set the value for *key* to *val*.

        If *key* is already associated with *val*, this is a no-op.

        If *key* is already associated with a different value,
        the old value will be replaced with *val*,
        as with dict's :meth:`__setitem__`.

        If *val* is already associated with a different key,
        an exception is raised
        to protect against accidental removal of the key
        that's currently associated with *val*.

        Use :meth:`put` instead if you want to specify different behavior in
        the case that the provided key or value duplicates an existing one.
        Or use :meth:`forceput` to unconditionally associate *key* with *val*,
        replacing any existing items as necessary to preserve uniqueness.

        :raises bidict.ValueDuplicationError: if *val* duplicates that of an
            existing item.

        :raises bidict.KeyAndValueDuplicationError: if *key* duplicates the key of an
            existing item and *val* duplicates the value of a different
            existing item.
        ©Úon_dupN)Úputr&   r   r   r   r   Ú__setitem__6   s   zMutableBidict.__setitem__r&   r   c                 C  s   | j ||ff|d� dS )aM  Associate *key* with *val*, honoring the :class:`OnDup` given in *on_dup*.

        For example, if *on_dup* is :attr:`~bidict.ON_DUP_RAISE`,
        then *key* will be associated with *val* if and only if
        *key* is not already associated with an existing value and
        *val* is not already associated with an existing key,
        otherwise an exception will be raised.

        If *key* is already associated with *val*, this is a no-op.

        :raises bidict.KeyDuplicationError: if attempting to insert an item
            whose key only duplicates an existing item's, and *on_dup.key* is
            :attr:`~bidict.RAISE`.

        :raises bidict.ValueDuplicationError: if attempting to insert an item
            whose value only duplicates an existing item's, and *on_dup.val* is
            :attr:`~bidict.RAISE`.

        :raises bidict.KeyAndValueDuplicationError: if attempting to insert an
            item whose key duplicates one existing item's, and whose value
            duplicates another existing item's, and *on_dup.val* is
            :attr:`~bidict.RAISE`.
        r%   N©Ú_update)r   r   r    r&   r   r   r   r'   R   s   zMutableBidict.putc                 C  ó   | j ||td� dS )z¬Associate *key* with *val* unconditionally.

        Replace any existing mappings containing key *key* or value *val*
        as necessary to preserve uniqueness.
        r%   N)r'   r   r   r   r   r   Úforceputl   s   zMutableBidict.forceputc                 C  s   | j  ¡  | j ¡  dS )zRemove all items.N)r   Úclearr   r   r   r   r   r-   t   s   
zMutableBidict.clearc                C  r   r   r   r#   r   r   r   r   y   r   zMutableBidict.pop.Údefaultr	   úVT | DTc                C  r   r   r   ©r   r   r.   r   r   r   r   {   r   úODT[DT]c                C  s.   z|   |¡W S  ty   |tu r‚ | Y S w )u¯   *x.pop(k[, d]) â†’ v*

        Remove specified key and return the corresponding value.

        :raises KeyError: if *key* is not found and no *default* is provided.
        )r!   ÚKeyErrorr   r0   r   r   r   r   ~   s   ýútuple[KT, VT]c                 C  s   | j  ¡ \}}| j|= ||fS )uŠ   *x.popitem() â†’ (k, v)*

        Remove and return some item as a (key, value) pair.

        :raises KeyError: if *x* is empty.
        )r   Úpopitemr   r   r   r   r   r4   Œ   s   zMutableBidict.popitemr   ÚargúMapOrItems[KT, VT]Úkwc                K  ó   | j ||d� dS )zCLike calling :meth:`putall` with *self.on_dup* passed for *on_dup*.)r7   Nr)   ©r   r5   r7   r   r   r   Úupdate—   s   zMutableBidict.updatec                K  r+   )zLike a bulk :meth:`forceput`.)r7   r&   N)r*   r   r9   r   r   r   Úforceupdate›   s   zMutableBidict.forceupdateÚitemsc                 C  r8   )z�Like a bulk :meth:`put`.

        If one of the given items causes an exception to be raised,
        none of the items is inserted.
        r%   Nr)   )r   r<   r&   r   r   r   ÚputallŸ   s   zMutableBidict.putallÚotherút.Mapping[KT, VT]úMutableBidict[KT, VT]c                 C  s   |   |¡ | S )zReturn self|=other.)r:   )r   r>   r   r   r   Ú__ior__©   s   
zMutableBidict.__ior__N)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   r
   r.   r	   r   r/   )r   r
   r.   r1   r   r/   )r   r3   )r   )r5   r6   r7   r   r   r"   )r<   r6   r&   r   r   r"   )r>   r?   r   r@   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtÚTYPE_CHECKINGÚpropertyr   r   r!   r$   r(   r   r'   r,   r-   Úoverloadr   r   r4   r:   r;   r=   rA   r   r   r   r   r   "   s.    






r   c                   @  s6   e Zd ZdZejred	dd„ƒZed	dd„ƒZdS dS )
Úbidictz®The main bidirectional mapping type.

    See :ref:`intro:Introduction` and :ref:`basic-usage:Basic Usage`
    to get started (also available at https://bidict.rtfd.io).
    r   úbidict[VT, KT]c                 C  r   r   r   r   r   r   r   r   ¸   r   zbidict.inversec                 C  r   r   r   r   r   r   r   r   »   r   z
bidict.invN)r   rK   )	rB   rC   rD   rE   rF   rG   rH   r   r   r   r   r   r   rJ   ¯   s    úrJ   )rE   Ú
__future__r   ÚtypingrF   Ú_abcr   Z_baser   Z_dupr   r   r   Z_typingr	   r
   r   r   r   r   r   rJ   r   r   r   r   Ú<module>   s"   " 