� L�gw_���dZddlmZddlZddlZddlmZddlm Z ddl m Z ddl m Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ej$eee e!fZ%ej&e%ee!fZ'ej(ej$ej)dfZ*ej+dd���Z,Gd�d ej-eej.e��Z/Gd!�d"e ee!f��Z0d*d'�Z1e0�2��Gd(�d)��Z3dS)+zProvide :class:`BidictBase`.�)� annotationsN)�starmap)�eq)�MappingProxyType�)�BidirectionalMapping)�DROP_NEW)�DROP_OLD)�ON_DUP_DEFAULT)�RAISE)�OnDup)�DuplicationError)�KeyAndValueDuplicationError)�KeyDuplicationError)�ValueDuplicationError)�inverted)� iteritems)�KT)�MISSING)�OKT)�OVT)�VT)�Maplike)� MapOrItems.�BTzBidictBase[t.Any, t.Any])�boundc��eZdZdZdS)�BidictKeysViewz�Since the keys of a bidict are the values of its inverse (and vice versa), the :class:`~collections.abc.ValuesView` result of calling *bi.values()* is also a :class:`~collections.abc.KeysView` of *bi.inverse*. N��__name__� __module__� __qualname__�__doc__���\/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/bidict/_base.pyrr4s���������r%rc����eZdZUdZeZded<ded<eZded<eZ ded<d ed <d[�fd � Z e d[d���Z ded<e d[d���Z e d[d���Ze d\d���Ze d]d���Zd^d_d�Zed`d���Zd`d �Zed`d!���Zdad#�Zdbd%�Zdcd'�Zdd�fd)� Zded-�Zdfd0�Zdfd1�Zdgd7�Zdhd@�Zei��fdAdAdB�didG�Z djdJ�Z!djdK�Z"e#dkdldO���Z$dmdP�Z%dndR�Z&dndS�Z'dodU�Z(dpdW�Z)dqdX�Z*drdZ�Z+�xZ,S)s� BidictBasez6Base class implementing :class:`BidirectionalMapping`.zt.MutableMapping[KT, VT]�_fwdmzt.MutableMapping[VT, KT]�_invmz0t.ClassVar[type[t.MutableMapping[t.Any, t.Any]]]� _fwdm_cls� _invm_clsz*t.ClassVar[type[BidictBase[t.Any, t.Any]]]�_inv_cls�return�Nonec�p��t�����|���dS�N)�super�__init_subclass__� _init_class)�cls� __class__s �r&r3zBidictBase.__init_subclass__Qs/��� ���!�!�#�#�#� �������r%c�V�|���|���dSr1)�_ensure_inv_cls� _set_reversed�r5s r&r4zBidictBase._init_classUs,�� ������ �������r%zt.ClassVar[t.Any]� __reversed__c��|tur|j}|tju}|rdStd�|j|jfD����}|rt nd|_dS)z�Set __reversed__ for subclasses that do not set it explicitly according to whether backing mappings are reversible. Nc3�JK�|]}t|tj��V��dSr1)� issubclass�t� Reversible)�.0�is r&� <genexpr>z+BidictBase._set_reversed.<locals>.<genexpr>fs.���� e� e���A�q�|�!<�!<� e� e� e� e� e� er%)r(r;�allr+r,�_fwdm_reversed)r5�resolved� overridden�backing_reversibles r&r9zBidictBase._set_reversed\sp�� �j� � ��'�H�!��)@�@�J�� ��� � e� e�s�}�VY�Vc�Fd� e� e� e�e�e��-?�I�>�>�T����r%c��t|di���d��rdS|���|_dS)aEnsure :attr:`_inv_cls` is set, computing it dynamically if necessary. All subclasses provided in :mod:`bidict` are their own inverse classes, i.e., their backing forward and inverse mappings are both the same type, but users may define subclasses where this is not the case. This method ensures that the inverse class is computed correctly regardless. See: :ref:`extending:Dynamic Inverse Class Generation` (https://bidict.rtfd.io/extending.html#dynamic-inverse-class-generation) �__dict__r-N)�getattr�get� _make_inv_clsr-r:s r&r8zBidictBase._ensure_inv_clsisB��, �3� �B� '� '� +� +�J� 7� 7� � �F��(�(�*�*�� � � r%r5�type[BT]c�D������}t�fd�|���D����}|r�S�|d<t�j�d��t f|��}�j|_tjtj t|��S)Nc3�R�K�|]!\}}t�|t��|kV��"dSr1)rKr)rA�k�vr5s �r&rCz+BidictBase._make_inv_cls.<locals>.<genexpr>�s8�����V�V�v��1�W�S�!�W�5�5��:�V�V�V�V�V�Vr%r-�Inv) �_inv_cls_dict_diffrD�items�typer �GeneratedBidictInverser!r?�cast�Typer)r5�diff�cls_is_own_inv�inv_clss` r&rMzBidictBase._make_inv_cls�s�����%�%�'�'���V�V�V�V������V�V�V�V�V�� � ��J���Z���#�,�+�+�+�c�3I�-J�D�Q�Q�� �^����v�a�f�R�j�'�*�*�*r%�dict[str, t.Any]c� �|j|jd�S)N)r+r,)r,r+r:s r&rTzBidictBase._inv_cls_dict_diff�s������ � � r%r$�arg�MapOrItems[KT, VT]�kwrc ��|���|_|���|_|�||d���dS)a8Make a new bidirectional mapping. The signature behaves like that of :class:`dict`. ktems passed via positional arg are processed first, followed by any items passed via keyword argument. Any duplication encountered along the way is handled as per :attr:`on_dup`. F��rollbackN)r+r)r,r*�_update)�selfr_ras r&�__init__zBidictBase.__init__�sD���^�^�%�%�� ��^�^�%�%�� � � � �S�"�u� �-�-�-�-�-r%�BidictBase[VT, KT]c���t|dd��}|�|St|dd��}|�|��}|�|S|���}||_d|_d|_t j|��|_|S)z3The inverse of this bidirectional mapping instance.�_invN�_invweak)rK� _make_inverserjrk�weakref�ref)rf�inv�invweaks r&�inversezBidictBase.inverse�s���*1��v�t�)D�)D�� �?��J��$� �D�1�1�� � ��'�)�)�C���� �� � �"�"��/2�� �JN�� �����{�4�(�(�� �� r%c�^�|���}|j|_|j|_|Sr1)r-r*r))rfros r&rlzBidictBase._make_inverse�s&��"&�-�-�/�/���J�� ��J�� �� r%c��|jS)zAlias for :attr:`inverse`.)rq�rfs r&rozBidictBase.inv�s ���|�r%�strc�t�|jj}|r!t|�����nd}|�d|�d�S)zSee :func:`repr`.��(�))r6r �dictrU)rf�clsnamerUs r&�__repr__zBidictBase.__repr__�sB���.�)��&*�2��T�Z�Z�\�\�"�"�"����$�$�E�$�$�$�$r%�BidictKeysView[VT]c�z�tjtt|j�����S)a;A set-like object providing a view on the contained values. Since the values of a bidict are equivalent to the keys of its inverse, this method returns a set-like object for this bidict's values rather than just a collections.abc.ValuesView. This object supports set operations like union and difference, and constant- rather than linear-time containment checks, and is no more expensive to provide than the less capable collections.abc.ValuesView would be. See :meth:`keys` for more information. )r?rXrrrq�keysrts r&�valueszBidictBase.values�s)���v�n�R�(�$�,�*;�*;�*=�*=�>�>�>r%�t.KeysView[KT]c�v�|j|j}}|tur|���nt |��S)a�A set-like object providing a view on the contained keys. When *b._fwdm* is a :class:`dict`, *b.keys()* returns a *dict_keys* object that behaves exactly the same as *collections.abc.KeysView(b)*, except for - offering better performance - being reversible on Python 3.8+ - having a .mapping attribute in Python 3.10+ that exposes a mappingproxy to *b._fwdm*. )r)r+rzrr)rf�fwdm�fwdm_clss r&rzBidictBase.keys�s5����T�^�h��&�$�.�.�t�y�y�{�{�{�N�4�4H�4H�Hr%�t.ItemsView[KT, VT]c���|jtur|j���nt �����S)a�A set-like object providing a view on the contained items. When *b._fwdm* is a :class:`dict`, *b.items()* returns a *dict_items* object that behaves exactly the same as *collections.abc.ItemsView(b)*, except for: - offering better performance - being reversible on Python 3.8+ - having a .mapping attribute in Python 3.10+ that exposes a mappingproxy to *b._fwdm*. )r+rzr)rUr2)rfr6s �r&rUzBidictBase.items�s6���&*�^�t�%;�%;�t�z���!�!�!��������Pr%�key�t.Any�boolc��||jvS)z;True if the mapping contains the specified key, else False.�r)�rfr�s r&� __contains__zBidictBase.__contains__ s���d�j� � r%�other�objectc��t|tj��r/|j���|���kSt S)u0*x.__eq__(other) ⟺ x == other* Equivalent to *dict(x.items()) == dict(other.items())* but more efficient. Note that :meth:`bidict's __eq__() <bidict.BidictBase.__eq__>` implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, :ref:`== comparison is order-insensitive <eq-order-insensitive>` (https://bidict.rtfd.io/other-bidict-types.html#eq-is-order-insensitive). *See also* :meth:`equals_order_sensitive` )� isinstancer?�Mappingr)rU�NotImplemented�rfr�s r&�__eq__zBidictBase.__eq__s?�� �e�Q�Y� '� '� 7��:�#�#�%�%������6� 6��r%c �"�t|tj��r t|��t|��krdSt t t t|���|���������S)z�Order-sensitive equality check. *See also* :ref:`eq-order-insensitive` (https://bidict.rtfd.io/other-bidict-types.html#eq-is-order-insensitive) F) r�r?r��lenrDrr�ziprUr�s r&�equals_order_sensitivez!BidictBase.equals_order_sensitive&se�� �%���+�+� �s�4�y�y�C��J�J�/F�/F��5��7�2�s�4�:�:�<�<������?�?�@�@�A�A�Ar%r�val�on_dupr �DedupResult[KT, VT]c�Z�|j|j}}|�|t��}|�|t��}|tu|tu} }|rQ| rO||kr ||ksJ�dS|jt urt ||���|jturdS|jtusJ�n|r>|j t urt|���|j turdS|j tusJ�n?| r=|jt urt|���|jturdS|jtusJ�||fS)a�Check *key* and *val* for any duplication in self. Handle any duplication as per the passed in *on_dup*. If (key, val) is already present, return None since writing (key, val) would be a no-op. If duplication is found and the corresponding :class:`~bidict.OnDupAction` is :attr:`~bidict.DROP_NEW`, return None. If duplication is found and the corresponding :class:`~bidict.OnDupAction` is :attr:`~bidict.RAISE`, raise the appropriate exception. If duplication is found and the corresponding :class:`~bidict.OnDupAction` is :attr:`~bidict.DROP_OLD`, or if no duplication is found, return *(oldkey, oldval)*. N) r)r*rLrr�r rr r r�rr) rfr�r�r�r��invm�oldval�oldkey�isdupkey�isdupvals r&�_dedupzBidictBase._dedup0sX��$�Z���d���(�(�3��0�0���(�(�3��0�0��#�7�2�F�'�4I�(�� � *�� *��f�}�}��f�}�}�}�}��t��z�U�"�"�1�#�s�;�;�;��z�X�%�%��t��:��)�)�)�)�)� � *��z�U�"�"�)�#�.�.�.��z�X�%�%��t��:��)�)�)�)�)� � *��z�U�"�"�+�C�0�0�0��z�X�%�%��t��:��)�)�)�)��v�~�r%�newkey�newvalr��OKT[KT]r��OVT[VT]�unwrites�Unwrites | Nonec�~�|j|j}}|j|j} }|j|j} } |||��| ||��|tur*|tur!|�|�| |f| |ff��dSdS|turJ|turA| |��| |��|�'|�|||f| ||f|||f| ||ff��dSdS|tur1| |��|�"|�|||f| ||f| |ff��dSdS|tusJ�| |��|�"|�|||f| ||f| |ff��dSdS)aInsert (newkey, newval), extending *unwrites* with associated inverse operations if provided. *oldkey* and *oldval* are as returned by :meth:`_dedup`. If *unwrites* is not None, it is extended with the inverse operations necessary to undo the write. This design allows :meth:`_update` to roll back a partially applied update that fails part-way through when necessary. This design also allows subclasses that require additional operations to easily extend this implementation. For example, :class:`bidict.OrderedBidictBase` calls this inherited implementation, and then extends *unwrites* with additional operations needed to keep its internal linked list nodes consistent with its items' order as changes are made. N)r)r*� __setitem__� __delitem__r�extend) rfr�r�r�r�r�r�r��fwdm_set�invm_set�fwdm_del�invm_dels r&�_writezBidictBase._writecs���Z���d��!�-�t�/?�(��!�-�t�/?�(������ � � ����� � � � �W� � ��7�!2�!2��#�����v�&��v�&�!������$�#� �7� "� "�v�W�'<�'<� �H�V� � � � �H�V� � � ��#�����v�v�.��v�v�.��v�v�.��v�v�.� !������$�#��7� "� "� �H�V� � � ��#�����v�v�.��v�v�.��v�&�!������$�#���(�(�(�(� �H�V� � � ��#�����v�v�.��v�v�.��v�&�!������$�#r%N�rdr��t.Mapping[str, VT]rd� bool | None� OnDup | Nonec��t|tjtf��st d|jj�d����|s|sdS|�|j}|� t|v}|s.|s,t|t��r|� |��dS|r�t|tj ��rtt|��t|��zt|��krD|� ��}|�||d|���|� |��dS|j}|rgnd}t!|fi|��D]W\}} |�|| |��} n*#t$$r|�t'|��D] ^} } | | �� �wxYw| � ||| g| �Rd|i��XdS)ziUpdate with the items from *arg* and *kw*, maybe failing and rolling back as per *on_dup* and *rollback*.�'z' object is not iterableNFr�r�)r�r?�Iterabler� TypeErrorr6r r�r r(� _init_from�Sizedr��copyrer�rr�r�reversed) rfr_rardr��tmp�writer�r�r�� dedup_result�fn�argss r&rezBidictBase._update�s����#�� �G�4�5�5� R��P�� � 6�P�P�P�Q�Q� Q�� �2� � �F� �>��[�F� � ����H�� �B� �:�c�:�#>�#>� � �O�O�C� � � � �F� � � �3���0�0� �S��X�X��B���5G�#�d�)�)�5S�5S��)�)�+�+�C� �K�K��R�%��K� ?� ?� ?� �O�O�C� � � � �F�� ��*2�$<�B�B���!�#�,�,��,�,� B� B�H�C�� �#�{�{�3��V�<�<� � ��#� � � ��'�%-�h�%7�%7�"�"� ��T���D� � � ��  ���� �'���c�3�A��A�A�A��A�A�A�� B� Bs �9E�'E8rfrc�*�|���S)z7Used for the copy protocol. See the :mod:`copy` module.)r�rts r&�__copy__zBidictBase.__copy__�s���y�y�{�{�r%c�8�|�|j|��S)z%Make a (shallow) copy of this bidict.)� _from_otherr6rts r&r�zBidictBase.copy�s�� ������5�5�5r%F�btroc��|��}|�|��|rtjt|j��n|S)aFast, private constructor based on :meth:`_init_from`. If *inv* is true, return the inverse of the instance instead of the instance itself. (Useful for pickling with dynamically-generated inverse classes -- see :meth:`__reduce__`.) )r�r?rXrrq)r�r�ro�insts r&r�zBidictBase._from_other�s?���r�t�t�� �������+.�8�q�v�b�$�,�'�'�'�D�8r%c�2�|j���|j���|j�|��t |t ��r|jnt|j��}|j�|��dS)zDFast init from *other*, bypassing item-by-item duplication checking.N)r)�clearr*�updater�r(rqr)rfr�ros r&r�zBidictBase._init_from�s��� � ������ � ������ � ���%� � � � *�%��<�<�V�e�m�m�(�4�:�BV�BV�� � ���#�����r%�t.Mapping[KT, VT]c��t|tj��stS|���}|�|d���|S)zReturn self|other.Frc)r�r?r�r�r�re�rfr��news r&�__or__zBidictBase.__or__�sD���%���+�+� "�!� !��i�i�k�k�� � � �E�E� �*�*�*�� r%c��t|tj��stS|�|��}|�|d���|S)zReturn other|self.Frc)r�r?r�r�r6rer�s r&�__ror__zBidictBase.__ror__�sH���%���+�+� "�!� !��n�n�U�#�#�� � � �D�5� �)�)�)�� r%�intc�*�t|j��S)zThe number of contained items.)r�r)rts r&�__len__zBidictBase.__len__s���4�:���r%�t.Iterator[KT]c�*�t|j��S)z!Iterator over the contained keys.)�iterr)rts r&�__iter__zBidictBase.__iter__s���D�J���r%c��|j|S)u*x.__getitem__(key) ⟺ x[key]*r�r�s r&� __getitem__zBidictBase.__getitem__ s���z�#��r%�tuple[t.Any, ...]c��|j}|}t|t��x}r|j}|j}|j|t |��|ffS)z&Return state information for pickling.)r6r�rWr-rqr�rz)rfr5r�� should_inverts r&� __reduce__zBidictBase.__reduce__sQ���n��(,��'�t�-C�D�D� D�=� ��-�C��<�D���#�t�D�z�z�=�!A�A�Ar%)r.r/)r5rNr.rN)r.r])r$)r_r`rarr.r/)r.rh)r.ru)r.r})r.r�)r.r�)r�r�r.r�)r�r�r.r�)r�rr�rr�r r.r�) r�rr�rr�r�r�r�r�r�r.r/) r_r`rar�rdr�r�r�r.r/)rfrr.r)F)r�rNr�r`ror�r.r)r�r`r.r/)rfrr�r�r.r)r.r�)r.r�)r�rr.r)r.r�)-r r!r"r#r r��__annotations__rzr+r,r3� classmethodr4r9r8rMrTrg�propertyrqrlror|r�rrUr�r�r�r�r�rrer�r�� staticmethodr�r�r�r�r�r�r�r�� __classcell__)r6s@r&r(r(;s���������@�@��F�#�#�#�#�#�#�#�#�CG�I�F�F�F�F�BF�I�F�F�F�F�9�8�8�8������������[��$�#�#�#�� J� J� J��[� J��+�+�+��[�+�2� +� +� +��[� +�� � � ��[� � .� .� .� .� .������X��@���� �����X��%�%�%�%� ?� ?� ?� ?�I�I�I�I�"Q�Q�Q�Q�Q�Q�&!�!�!�!�����(B�B�B�B�1�1�1�1�f8�8�8�8�z"2�!1�"�!5�!5�0B� !%�#� 0B�0B�0B�0B�0B�0B�d����6�6�6�6��9�9�9�9��\�9����������������� � � � ����� B� B� B� B� B� B� B� Br%r(rf�BidictBase[KT, t.Any]r.r�c�l�t|jtj��sJ�t |j��S)z2Iterator over the contained keys in reverse order.)r�r)r?r@r�rts r&rErEs,�� �d�j�!�,� /� /�/�/� /� �D�J� � �r%c��eZdZdZdS)rWz<Base class for dynamically-generated inverse bidict classes.Nrr$r%r&rWrW%s������F�F�F�Fr%rW)rfr�r.r�)4r#� __future__r�typingr?rm� itertoolsr�operatorr�typesr�_abcr�_dupr r r r r �_excrrrr�_iterrr�_typingrrrrrrr�Tuple�OldKV�Optional� DedupResult�List�Any�Unwrites�TypeVarr�KeysView� ValuesViewrr(rEr4rWr$r%r&�<module>r�s��#�"�"�"�"�"�"�"���������������������"�"�"�"�"�"�&�&�&�&�&�&������������� � � � � � �������������"�"�"�"�"�"�-�-�-�-�-�-�%�%�%�%�%�%�'�'�'�'�'�'������������������������������������������������������� ���B���R�� �!���j��r�2�v��'� � �6�!�'�!�%��*�%� &���Q�Y�t�5�6�6�6�������Q�Z��^�Q�\�"�%5����]B�]B�]B�]B�]B�%�b�"�f�-�]B�]B�]B�B � � � �  ������G�G�G�G�G�G�G�G�G�Gr%
Memory