
    i                       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eeef         eeef                   Z G 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                     e Zd ZdZej        red*d            Zed*d            Zd+d	Z	d,dZ
d-dZefd.dZd-dZd/dZej        d+d            Zej        d0d1d            Zefd2dZd3dZd4d5d!Zd4d5d"Zefd6d$Zd7d(Zd)S )8MutableBidictz.Base class for mutable bidirectional mappings.returnMutableBidict[VT, KT]c                    d S N selfs    9/usr/local/lib/python3.11/dist-packages/bidict/_bidict.pyinversezMutableBidict.inverse'   s    47C    c                    d S r   r   r   s    r   invzMutableBidict.inv*   s    03r   keyr   r   c                J    | j                             |          }| j        |= |S r   )_fwdmpop_invmr   r   vals      r   _popzMutableBidict._pop-   s#    jnnS!!JsO
r   Nonec                0    |                      |           dS )u#   *x.__delitem__(y)　⟺　del x[y]*N)r%   r   r   s     r   __delitem__zMutableBidict.__delitem__2   s    		#r   r$   c                @    |                      ||| j                   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#   s      r   __setitem__zMutableBidict.__setitem__6   s$    4 	c$+.....r   r,   r	   c                :    |                      ||ff|           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,   s       r   r-   zMutableBidict.putR   s&    0 	sCj]622222r   c                @    |                      ||t                     dS )zAssociate *key* with *val* unconditionally.

        Replace any existing mappings containing key *key* or value *val*
        as necessary to preserve uniqueness.
        r+   N)r-   r   r#   s      r   forceputzMutableBidict.forceputl   s"     	c/22222r   c                j    | j                                          | j                                         dS )zRemove all items.N)r    clearr"   r   s    r   r5   zMutableBidict.cleart   s0    

r   c                   d S r   r   r(   s     r   r!   zMutableBidict.popy   s    %(Sr   .defaultr
   VT | DTc                   d S r   r   r   r   r7   s      r   r!   zMutableBidict.pop{   s    =@Sr   ODT[DT]c               f    	 |                      |          S # t          $ r |t          u r |cY S w xY 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   r:   s      r   r!   zMutableBidict.pop~   sI    	99S>>! 	 	 	'!!NNN	s    00tuple[KT, VT]c                R    | 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#   s      r   r@   zMutableBidict.popitem   s-     :%%''SJsOCxr   r   argMapOrItems[KT, VT]kwc               4    |                      ||           dS )zCLike calling :meth:`putall` with *self.on_dup* passed for *on_dup*.)rC   Nr0   r   rA   rC   s      r   updatezMutableBidict.update   s    SR     r   c               @    |                      ||t                     dS )zLike a bulk :meth:`forceput`.)rC   r,   N)r1   r   rE   s      r   forceupdatezMutableBidict.forceupdate   s     SR88888r   itemsc                4    |                      ||           dS )zLike a bulk :meth:`put`.

        If one of the given items causes an exception to be raised,
        none of the items is inserted.
        r+   Nr0   )r   rI   r,   s      r   putallzMutableBidict.putall   s      	U6*****r   othert.Mapping[KT, VT]MutableBidict[KT, VT]c                0    |                      |           | S )zReturn self|=other.)rF   )r   rL   s     r   __ior__zMutableBidict.__ior__   s    Er   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   r7   r
   r   r8   )r   r   r7   r;   r   r8   )r   r>   )r   )rA   rB   rC   r   r   r&   )rI   rB   r,   r	   r   r&   )rL   rM   r   rN   )__name__
__module____qualname____doc__tTYPE_CHECKINGpropertyr   r   r%   r)   r.   r   r-   r3   r5   overloadr!   r   r@   rF   rH   rK   rP   r   r   r   r   r   "   s       88 4	777 
7	333 
3   
   / / / /8 5A 3 3 3 3 343 3 3 3   
 Z((( Z(Z@@@@ Z@.5     	 	 	 	! ! ! ! !9 9 9 9 9 AM + + + + +     r   r   c                  T    e Zd ZdZej        redd            Zedd            ZdS dS )bidictzThe 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                    d S r   r   r   s    r   r   zbidict.inverse   s    -0Sr   c                    d S r   r   r   s    r   r   z
bidict.inv   s    ),r   N)r   r[   )	rQ   rR   rS   rT   rU   rV   rW   r   r   r   r   r   rZ   rZ      s\          	 -	000 
0	,,, 
,,,- -r   rZ   )rT   
__future__r   typingrU   _abcr   _baser   _dupr   r   r	   _typingr
   r   r   r   r   r   r   rZ   r   r   r   <module>rd      sv   : 9 " " " " " "     - - - - - -       ! ! ! ! ! !                                                J J J J JJr2v&(CBF(K J J JZ- - - - -]2r6" - - - - -r   