
    i"                    >   S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \R*                  " S5      r " S S\R.                  \   5      r " S S5      r " S S\5      r " S S\\\4   5      rg)z#Provide :class:`OrderedBidictBase`.    )annotationsN)ref   )
BidictBase)Unwrites)bidict)	iteritems)KT)MISSING)OKT)OVT)VT)
MapOrItemsATc                  :    \ rS rSrSrSS jrS	S jrS
SS jjrSrg)WeakAttr%   zDescriptor to automatically manage (de)referencing the given slot as a weakref.

See https://docs.python.org/3/howto/descriptor.html#managed-attributes
for an intro to using descriptors like this for managed attributes.
c                   Xl         g Nslot)selfr   s     P/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/bidict/_orderedbase.py__init__WeakAttr.__init__,   s    	    c                B    [        XR                  [        U5      5        g r   )setattrr   weakref)r   instancevalues      r   __set__WeakAttr.__set__/   s    ))WU^4r   Nc                h    [         R                  " [        [        XR                  5      " 5       5      $ r   )tcastr   getattrr   )r   r    _WeakAttr__owners      r   __get__WeakAttr.__get__2   s    vvb'(II6899r   r   )r   strreturnNone)r    t.Anyr!   r   r,   r-   r   )r    r.   r(   r.   r,   r   )	__name__
__module____qualname____firstlineno____doc__r   r"   r)   __static_attributes__ r   r   r   r   %   s    5: :r   r   c                  \    \ rS rSr% Sr\" SS9rS\S'   SrS\S	'   SS
 jr	SS jr
SS jrSrg)Node6   a  A node in a circular doubly-linked list
used to encode the order of items in an ordered bidict.

A weak reference to the previous node is stored
to avoid creating strong reference cycles.
Referencing/dereferencing the weakref is handled automatically by :class:`WeakAttr`.
	_prv_weakr   WeakAttr[Node]prv)__weakref__r9   nxtzNode | WeakAttr[Node]r=   c                    Xl         X l        g r   r;   r=   )r   r;   r=   s      r   r   Node.__init__D   s    r   c                p    U R                   U R                  l         U R                  U R                   l        g)zzRemove self from in between prv and nxt.
Self's references to prv and nxt are retained so it can be relinked (see below).
Nr=   r;   r   s    r   unlinkNode.unlinkH   s"     xxxxr   c                H    U =U R                   l        U R                  l         g)z=Restore self between prv and nxt after unlinking (see above).Nr?   rC   s    r   relinkNode.relinkO   s    &**txx|r   rB   N)r;   r7   r=   r7   r,   r-   r,   r-   )r/   r0   r1   r2   r3   r   r;   __annotations__	__slots__r   rD   rG   r4   r5   r   r   r7   r7   6   s2     #4C43I	 +r   r7   c                  h   ^  \ rS rSr% Sr\" SS9rS\S'   SrSU 4S jjr	S	S
.SS jjr
SS jrSrU =r$ )SentinelNodeT   zSpecial node in a circular doubly-linked list
that links the first node with the last node.
When its next and previous references point back to itself
it represents an empty list.
	_nxt_weakr   r:   r=   )rO   c                $   > [         TU ]  X 5        g r   )superr   )r   	__class__s    r   r   SentinelNode.__init__^   s    $r   Freversec             #  l   #    U(       a  SOSn[        X5      nX0La  Uv   [        X25      nX0La  M  gg7f)z/Iterator yielding nodes in the requested order.r;   r=   N)r'   )r   rU   attrnodes       r   	iternodesSentinelNode.iternodesa   s5     uUt"J4&D s   .44c                P    U R                   n[        X5      nU=Ul        U l         U$ )z&Create and return a new terminal node.)r;   r7   r=   )r   old_lastnew_lasts      r   new_last_nodeSentinelNode.new_last_nodei   s(    88'"**txr   )r;   rI   )rU   boolr,   zt.Iterator[Node])r,   r7   )r/   r0   r1   r2   r3   r   r=   rJ   rK   r   rY   r^   r4   __classcell__rR   s   @r   rM   rM   T   s7     #4C4I% ,1 ' r   rM   c                     ^  \ rS rSr% SrS\S'   S\S'   SSU 4S jjjr\R                  (       a  \	SS j5       r
\	SS	 j5       rSU 4S
 jjrSS jrSS jrSU 4S jjrSU 4S jjrSS jrSS jrSS.SS jjrSrU =r$ )OrderedBidictBaseq   zABase class implementing an ordered :class:`BidirectionalMapping`.zbidict[t.Any, Node]_node_by_korvr`   _bykeyc               r   > [        5       U l        [        5       U l        SU l        [
        TU ]  " U40 UD6  g)aH  Make a new ordered bidirectional mapping.
The signature behaves like that of :class:`dict`.
Items passed in are added in the order they are passed,
respecting the :attr:`~bidict.BidictBase.on_dup`
class attribute in the process.

The order in which items are inserted is remembered,
similar to :class:`collections.OrderedDict`.
TN)rM   _sntlr   rf   rg   rQ   r   )r   argkwrR   s      r   r   OrderedBidictBase.__init__w   s1     "^
#X##r   c                    g r   r5   rC   s    r   inverseOrderedBidictBase.inverse   s    8;r   c                    g r   r5   rC   s    r   invOrderedBidictBase.inv   s    47r   c                   > [         R                  " [        [        [        4   [
        TU ]  5       5      nU R                  Ul        U R                  Ul        U R                  (       + Ul	        U$ r   )
r%   r&   rd   r   r
   rQ   _make_inverseri   rf   rg   )r   rq   rR   s     r   rt   OrderedBidictBase._make_inverse   sP    ff&r2v.0E0GHJJ	 .._

r   c                d    U R                   (       a  UOUnU R                  R                  XA5        g r   )rg   rf   forceput)r   rX   keyvalkorvs        r   _assoc_nodeOrderedBidictBase._assoc_node   s#    kkss##D/r   c                R    U R                   R                  U	 UR                  5         g r   )rf   rn   rD   )r   rX   s     r   _dissoc_nodeOrderedBidictBase._dissoc_node   s    &&t,r   c                z  > [         TU ]  U5        U R                  nU R                  R                  nUR                  5         UR                  nU R                  =U R                  l        U R                  l	        U R                  R                  n[        U5       H  u  pgU" U" 5       U(       a  UOU5        M     g)z"See :meth:`BidictBase._init_from`.N)rQ   
_init_fromrg   rf   rn   clear__setitem__ri   r=   r;   r^   r	   )	r   otherbykeykorv_by_nodekorv_by_node_setnew_nodekvrR   s	           r   r   OrderedBidictBase._init_from   s    5!))11'33*.**4

::++e$DAXZe; %r   c                  > [         TU ]  XX4U5        U R                  U R                  pvU R                  U R
                  pU[        L aC  U[        L a:  U R                  R                  5       n
U" XU5        Ub  UR                  Xz45        ggU[        LaZ  U[        LaQ  U	(       a	  X   nX   n
OX   nX   n
U" U5        U" XU5        Ub$  UR                  XjX4XkX24UR                  445        ggU[        La.  X(       a  UOU   nU" XU5        Ub  UR                  XlX45        ggU[        Ld   eX(       a  UOU   nU" XU5        Ub  UR                  XlX245        gg)z*See :meth:`bidict.BidictBase._spec_write`.N)rQ   _writer{   r~   rf   rg   r   ri   r^   appendextendrG   )r   newkeynewvaloldkeyoldvalunwritesassocdissocnode_by_korvr   newnodeoldnoderX   rR   s                r   r   OrderedBidictBase._write   s}   vvx@(($*;*;v"00$++eW7!2jj..0G'6*# 12 $7"vW'< &.&.&.&.7O'6*#V4V4^^%!  $ 7"  %V<D$'#f => $ (((  %V<D$'#f => $r   c                     U R                  SS9$ )z4Iterator over the contained keys in insertion order.FrT   _iterrC   s    r   __iter__OrderedBidictBase.__iter__   s    zz%z((r   c                     U R                  SS9$ )z<Iterator over the contained keys in reverse insertion order.TrT   r   rC   s    r   __reversed__OrderedBidictBase.__reversed__   s    zz$z''r   FrT   c             #     #    U R                   R                  US9nU R                  R                  nU R                  (       a  U H	  nX4   v   M     g U R
                  nU H  nX4   nXV   v   M     g 7f)NrT   )ri   rY   rf   rn   rg   _invm)r   rU   nodesr   rX   
key_by_valry   s          r   r   OrderedBidictBase._iter   sl     

$$W$5))11;;"((  J"( o% s   A1A3)rg   rf   ri   )r5   )rj   MapOrItems[KT, VT]rk   r   r,   r-   )r,   zOrderedBidictBase[VT, KT])rX   r7   rx   r
   ry   r   r,   r-   )rX   r7   r,   r-   )r   r   r,   r-   )r   r
   r   r   r   zOKT[KT]r   zOVT[VT]r   zUnwrites | Noner,   r-   )r,   t.Iterator[KT])rU   r`   r,   r   )r/   r0   r1   r2   r3   rJ   r   r%   TYPE_CHECKINGpropertyrn   rq   rt   r{   r~   r   r   r   r   r   r4   ra   rb   s   @r   rd   rd   q   ss    K&&L$ $ 		; 
;	7 
70
<+?Z)( (- 
& 
&r   rd   )r3   
__future__r   typingr%   r   r   _baser   r   _bidictr   r   r	   _typingr
   r   r   r   r   r   TypeVarr   Genericr   r7   rM   rd   r5   r   r   <module>r      s    * "  "           YYt_:qyy} :"+ +<4 :w&
2r6* w&r   