
    wg                        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y)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                   ddd       ZefddZddZdddZdddZefddZd dZy)!MutableBidictz.Base class for mutable bidirectional mappings.c                     y N selfs    S/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/bidict/_bidict.pyinversezMutableBidict.inverse'   s    47    c                     y r   r   r   s    r   invzMutableBidict.inv*   s    03r   c                V    | j                   j                  |      }| j                  |= |S r   )_fwdmpop_invmr   keyvals      r   _popzMutableBidict._pop-   s$    jjnnS!JJsO
r   c                &    | j                  |       y)u#   *x.__delitem__(y)　⟺　del x[y]*N)r#   r   r!   s     r   __delitem__zMutableBidict.__delitem__2   s    		#r   c                @    | j                  ||| j                         y)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   c                0    | j                  ||ff|       y)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2r   c                4    | j                  ||t               y)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/2r   c                l    | j                   j                          | j                  j                          y)zRemove all items.N)r   clearr   r   s    r   r2   zMutableBidict.cleart   s"    



r   c                    y r   r   r%   s     r   r   zMutableBidict.popy   s    %(r   c                    y r   r   r   r!   defaults      r   r   zMutableBidict.pop{   s    =@r   c               Z    	 | j                  |      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   r5   s      r   r   zMutableBidict.pop~   s4    	99S>! 	'!N	s    **c                ^    | j                   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JJsOCxr   c               *    | j                  ||       y)zCLike calling :meth:`putall` with *self.on_dup* passed for *on_dup*.)kwNr-   r   argr<   s      r   updatezMutableBidict.update   s    SR r   c               4    | j                  ||t               y)zLike a bulk :meth:`forceput`.)r<   r)   N)r.   r   r=   s      r   forceupdatezMutableBidict.forceupdate   s    SR8r   c                *    | j                  ||       y)zLike 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   itemsr)   s      r   putallzMutableBidict.putall   s     	U6*r   c                (    | j                  |       | S )zReturn self|=other.)r?   )r   others     r   __ior__zMutableBidict.__ior__   s    Er   N)returnzMutableBidict[VT, KT])r!   r   rH   r   )r!   r   rH   None)r!   r   r"   r   rH   rI   )r!   r   r"   r   r)   r	   rH   rI   )rH   rI   ).)r!   r   r6   r
   rH   VT | DT)r!   r   r6   zODT[DT]rH   rJ   )rH   ztuple[KT, VT])r   )r>   MapOrItems[KT, VT]r<   r   rH   rI   )rC   rK   r)   r	   rH   rI   )rF   zt.Mapping[KT, VT]rH   zMutableBidict[KT, VT])__name__
__module____qualname____doc__tTYPE_CHECKINGpropertyr   r   r#   r&   r+   r   r*   r0   r2   overloadr   r   r:   r?   rA   rD   rG   r   r   r   r   r   "   s    8	7 
7	3 
3
/8 5A 343
 ZZ( (ZZ@ @.5 	!9 AM +r   r   c                  N    e Zd ZdZej
                  redd       Zedd       Zyy)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).
    c                     y r   r   r   s    r   r   zbidict.inverse   s    -0r   c                     y r   r   r   s    r   r   z
bidict.inv   s    ),r   N)rH   zbidict[VT, KT])	rL   rM   rN   rO   rP   rQ   rR   r   r   r   r   r   rU   rU      s1     		0 
0	, 
, r   rU   )rO   
__future__r   typingrP   _abcr   _baser   _dupr   r   r	   _typingr
   r   r   r   r   r   r   rU   r   r   r   <module>r^      sj    : "  -  !        JJr2v&(CBF(K JZ-]2r6" -r   