o
    þ§Ýj¨  ã                   @  s  U 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 G dd„ deeef e
eef ƒZG dd„ dee ƒZG dd„ dejeef ƒZejejee  ejeeejf  f Zd ¡ Zded< ddd„Zeedƒ eedƒ dS )zProvide :class:`OrderedBidict`.é    )ÚannotationsN)ÚSeté   )ÚBidictKeysView)ÚMutableBidict)ÚOrderedBidictBase)ÚKT)ÚVTc                      s~   e Zd ZdZejreddd„ƒZeddd„ƒZd‡ fd	d
„Z	d ‡ fdd„Z
d!d"dd„Zd!d#dd„Zd$dd„Zd%dd„Z‡  ZS )&ÚOrderedBidictz<Mutable bidict type that maintains items in insertion order.ÚreturnúOrderedBidict[VT, KT]c                 C  ó   d S ©N© ©Úselfr   r   úP/var/www/html/chatgpt/venv/lib/python3.10/site-packages/bidict/_orderedbidict.pyÚinverse"   ó   zOrderedBidict.inversec                 C  r   r   r   r   r   r   r   Úinv%   r   zOrderedBidict.invÚNonec                   s*   t ƒ  ¡  | j ¡  | j | j_| j_dS )zRemove all items.N)ÚsuperÚclearÚ_node_by_korvÚ_sntlÚnxtÚprvr   ©Ú	__class__r   r   r   (   s   

zOrderedBidict.clearÚkeyr   r	   c                   s.   t ƒ  |¡}| j| jr|n| }|  |¡ |S r   )r   Ú_popr   Ú_bykeyZ_dissoc_node)r   r   ÚvalÚnoder   r   r   r    .   s   
zOrderedBidict._popTÚlastÚboolútuple[KT, VT]c                 C  sP   | st dƒ‚t| j|rdndƒ}| jj| }| jr ||  |¡fS | j |¡|fS )uü   *b.popitem() â†’ (k, v)*

        If *last* is true,
        remove and return the most recently added item as a (key, value) pair.
        Otherwise, remove and return the least recently added item.

        :raises KeyError: if *b* is empty.
        zOrderedBidict is emptyr   r   )ÚKeyErrorÚgetattrr   r   r   r!   r    )r   r$   r#   Úkorvr   r   r   Úpopitem4   s   	zOrderedBidict.popitemc                 C  s€   | j r|n| j| }| j| }|j|j_|j|j_| j}|r/|j}||_||_| |_|_dS |j}||_||_| |_|_dS )z�Move the item with the given key to the end if *last* is true, else to the beginning.

        :raises KeyError: if *key* is missing
        N)r!   Ú_fwdmr   r   r   r   )r   r   r$   r)   r#   ZsntlZlastnodeZ	firstnoder   r   r   Úmove_to_endE   s   


zOrderedBidict.move_to_endút.KeysView[KT]c                 C  ó   t | ƒS )z9A set-like object providing a view on the contained keys.)Ú_OrderedBidictKeysViewr   r   r   r   Úkeys^   ó   zOrderedBidict.keysút.ItemsView[KT, VT]c                 C  r.   )z:A set-like object providing a view on the contained items.)Ú_OrderedBidictItemsViewr   r   r   r   Úitemsb   r1   zOrderedBidict.items)r   r   )r   r   )r   r   r   r	   )T)r$   r%   r   r&   )r   r   r$   r%   r   r   )r   r-   )r   r2   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtÚTYPE_CHECKINGÚpropertyr   r   r   r    r*   r,   r0   r4   Ú__classcell__r   r   r   r   r
      s    
r
   c                   @  ó    e Zd ZU ded< ddd„ZdS )	r/   zOrderedBidict[KT, t.Any]Ú_mappingr   út.Iterator[KT]c                 C  s
   t | jƒS r   )Úreversedr>   r   r   r   r   Ú__reversed__o   s   
z#_OrderedBidictKeysView.__reversed__N)r   r?   ©r5   r6   r7   Ú__annotations__rA   r   r   r   r   r/   l   ó   
 r/   c                   @  r=   )	r3   zOrderedBidict[KT, VT]r>   r   út.Iterator[tuple[KT, VT]]c                 c  s(   � | j }t|ƒD ]	}||| fV  qd S r   )r>   r@   )r   Úobr   r   r   r   rA   v   s
   €ÿz$_OrderedBidictItemsView.__reversed__N)r   rE   rB   r   r   r   r   r3   s   rD   r3   zv__lt__ __le__ __gt__ __ge__ __eq__ __ne__ __sub__ __rsub__ __or__ __ror__ __xor__ __rxor__ __and__ __rand__ isdisjointzt.Iterable[str]Ú_setmethodnamesÚclsú
_OView[KT]ÚviewnameÚstrr   r   c                   s.   d‡ ‡fdd„}t D ]
}tˆ |||ƒƒ q
d S )NÚ
methodnamerK   r   út.Anyc                   s,   d	‡ ‡fdd„}ˆ |_ ˆj› dˆ › �|_|S )
Nr   ú?_OrderedBidictKeysView[KT] | _OrderedBidictItemsView[KT, t.Any]ÚargsrM   r   c                   s�   | j j}t|tƒsttˆ ƒ| g|¢R Ž S t|ˆƒƒ }t|ˆ ƒ}t|ƒdks6t|d  }| jƒr6t|j jtƒs:||Ž S |j j}t|ˆƒƒ }||ƒS )Nr   r   )r>   r+   Ú
isinstanceÚdictr(   r   Úlenr   )r   rO   ZfwdmZfwdm_dict_viewZfwdm_dict_view_methodÚargZarg_dictZarg_dict_view)rL   rJ   r   r   Úmethodˆ   s   

ÿþzT_override_set_methods_to_use_backing_dict.<locals>.make_proxy_method.<locals>.methodÚ.)r   rN   rO   rM   r   rM   )r5   r7   )rL   rT   ©rH   rJ   )rL   r   Úmake_proxy_method‡   s   zD_override_set_methods_to_use_backing_dict.<locals>.make_proxy_method)rL   rK   r   rM   )rG   Úsetattr)rH   rJ   rW   Únamer   rV   r   Ú)_override_set_methods_to_use_backing_dict†   s   ÿrZ   r0   r4   )rH   rI   rJ   rK   r   r   )r8   Ú
__future__r   Útypingr9   Úcollections.abcr   Z_baser   Z_bidictr   Z_orderedbaser   Z_typingr   r	   r
   r/   Ú	ItemsViewr3   ÚUnionÚTypeÚAnyZ_OViewÚsplitrG   rC   rZ   r   r   r   r   Ú<module>   s&   "O(
ý

