_i;dZddlZddlmZ ddlmZmZe dZ dZ dZ GddeeZ y#e$r ddlmZmZY)wxYw) z An OrderedSet is a custom MutableSet that remembers its order, so that every entry has an index that can be looked up. Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger, and released under the MIT license. N)deque) MutableSetSequencez3.1cft|dxr$t|t xrt|t S)a  Are we being asked to look up a list of things, instead of a single thing? We check for the `__iter__` attribute so that this can cover types that don't have to be known by this module, such as NumPy arrays. Strings, however, should be considered as atomic values to look up, not iterables. The same goes for tuples, since they are immutable and therefore valid entries. We don't need to check for the Python 2 `unicode` type, because it doesn't have an `__iter__` attribute anyway. __iter__)hasattr isinstancestrtuple)objs /builddir/build/BUILDROOT/alt-python312-setuptools-69.0.2-3.el8.x86_64/opt/alt/python312/lib/python3.12/site-packages/setuptools/_vendor/ordered_set.py is_iterablers7 Z  '3$ $ '3& &ceZdZdZddZdZdZdZdZdZ d Z d Z e Z d Z d ZeZeZd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"y) OrderedSetz An OrderedSet is a custom MutableSet that remembers its order, so that every entry has an index that can be looked up. Example: >>> OrderedSet([1, 1, 2, 3, 2]) OrderedSet([1, 2, 3]) Nc0g|_i|_|||z}yyN)itemsmap)selfiterables r __init__zOrderedSet.__init__4s%    H D rc,t|jS)z Returns the number of unique elements in the ordered set Example: >>> len(OrderedSet([])) 0 >>> len(OrderedSet([1, 2])) 2 )lenrrs r __len__zOrderedSet.__len__:s4::rcft|tr|tk(r|jSt |r|Dcgc]}|j |c}St |dst|tr2|j |}t|tr|j|S|Std|zcc}w)aQ Get the item at a given index. If `index` is a slice, you will get back that slice of items, as a new OrderedSet. If `index` is a list or a similar iterable, you'll get a list of items corresponding to those indices. This is similar to NumPy's "fancy indexing". The result is not an OrderedSet because you may ask for duplicate indices, and the number of elements returned should be the number of elements asked for. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset[1] 2 __index__z+Don't know how to index an OrderedSet by %r) r slice SLICE_ALLcopyrrrlist __class__ TypeError)rindexiresults r __getitem__zOrderedSet.__getitem__Fs$ eU #(:99;   +015aDJJqM51 1 UK (Jue,DZZ&F&$'~~f-- IEQR R2sB.c$|j|S)z Return a shallow copy of this object. Example: >>> this = OrderedSet([1, 2, 3]) >>> other = this.copy() >>> this == other True >>> this is other False )r#rs r r!zOrderedSet.copyes~~d##rc6t|dk(ryt|S)Nrr)rr"rs r __getstate__zOrderedSet.__getstate__ss t9>: rcT|dk(r|jgy|j|y)Nr)r)rstates r __setstate__zOrderedSet.__setstate__s" G  MM"  MM% rc||jvS)z Test if the item is in this ordered set Example: >>> 1 in OrderedSet([1, 3, 2]) True >>> 5 in OrderedSet([1, 3, 2]) False )rrkeys r __contains__zOrderedSet.__contains__sdhhrc||jvr=t|j|j|<|jj||j|S)aE Add `key` as an item to this OrderedSet, then return its index. If `key` is already in the OrderedSet, return the index it already had. Example: >>> oset = OrderedSet() >>> oset.append(3) 0 >>> print(oset) OrderedSet([3]) )rrrappendr0s r addzOrderedSet.addsE dhh  ODHHSM JJ  c "xx}rcd} |D]}|j|} |S#t$rtdt|zwxYw)a< Update the set with the given iterable sequence, then return the index of the last element inserted. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.update([3, 1, 5, 1, 4]) 4 >>> print(oset) OrderedSet([1, 2, 3, 5, 4]) Nz(Argument needs to be an iterable, got %s)r5r$ ValueErrortype)rsequence item_indexitems r updatezOrderedSet.updatesW   !XXd^ !   :T(^K  s !Ac~t|r|Dcgc]}|j|c}S|j|Scc}w)aH Get the index of a given entry, raising an IndexError if it's not present. `key` can be an iterable of entries that is not a string, in which case this returns a list of indices. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.index(2) 1 )rr%r)rr1subkeys r r%zOrderedSet.indexs= s 589S6DJJv&S9 9xx}:s:c|js td|jd}|jd=|j|=|S)z Remove and return the last element from the set. Raises KeyError if the set is empty. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.pop() 3 z Set is empty)rKeyErrorr)relems r popzOrderedSet.pops>zz>* *zz"~ JJrN HHTN rc||vrd|j|}|j|=|j|=|jjD]\}}||k\s |dz |j|<yy)a Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) N)rr)rr1r&kvs r discardzOrderedSet.discardsd $; A 1  (16"#a%DHHQK) rcV|jdd=|jjy)z8 Remove all items from this OrderedSet. N)rrclearrs r rJzOrderedSet.clears JJqM rc,t|jS)zb Example: >>> list(iter(OrderedSet([1, 2, 3]))) [1, 2, 3] )iterrrs r rzOrderedSet.__iter__s DJJrc,t|jS)zf Example: >>> list(reversed(OrderedSet([1, 2, 3]))) [3, 2, 1] )reversedrrs r __reversed__zOrderedSet.__reversed__ s  ##rc|s|jjdS|jjdt|dS)Nz()())r#__name__r"rs r __repr__zOrderedSet.__repr__s1!^^446 6>>22DJ??rct|ttfrt|t|k(S t |}t ||k(S#t $rYywxYw)a Returns true if the containers have the same items. If `other` is a Sequence, then order is checked, otherwise it is ignored. Example: >>> oset = OrderedSet([1, 3, 2]) >>> oset == [1, 3, 2] True >>> oset == [1, 2, 3] False >>> oset == [2, 3] False >>> oset == OrderedSet([3, 2, 1]) False F)r rrr"setr$)rother other_as_sets r __eq__zOrderedSet.__eq__s[$ eh. /:e, , -u:L t9 , ,   s A AAct|tr |jnt}ttt j |g|}t j j|}||S)a Combines all unique items. Each items order is defined by its first appearance. Example: >>> oset = OrderedSet.union(OrderedSet([3, 1, 4, 1, 5]), [1, 3], [2, 0]) >>> print(oset) OrderedSet([3, 1, 4, 5, 2, 0]) >>> oset.union([8, 9]) OrderedSet([3, 1, 4, 5, 2, 0, 8, 9]) >>> oset | {10} OrderedSet([3, 1, 4, 5, 2, 0, 10]) )r rr#rr"itchain from_iterable)rsetscls containersrs r unionzOrderedSet.union6sO!+4 >> oset = OrderedSet.intersection(OrderedSet([0, 1, 2, 3]), [1, 2, 3]) >>> print(oset) OrderedSet([1, 2, 3]) >>> oset.intersection([2, 4, 5], [1, 2, 3, 4]) OrderedSet([2]) >>> oset.intersection() OrderedSet([1, 2, 3]) c3,K|] }|vs| ywr).0r;commons r z*OrderedSet.intersection..^s=dddfnTd )r rr#rVrcr)rr^r_rrjs @r rczOrderedSet.intersectionMsK!+4 >> OrderedSet([1, 2, 3]).difference(OrderedSet([2])) OrderedSet([1, 3]) >>> OrderedSet([1, 2, 3]).difference(OrderedSet([2]), OrderedSet([3])) OrderedSet([1]) >>> OrderedSet([1, 2, 3]) - OrderedSet([2]) OrderedSet([1, 3]) >>> OrderedSet([1, 2, 3]).difference() OrderedSet([1, 2, 3]) c3,K|] }|vs| ywrrhrir;rWs r rkz(OrderedSet.difference..ts@ddd%.?Tdrl)r#rVrar)rr^r_rrWs @r differencezOrderedSet.differencecs>nn IIs3~.E@d@EE5zrc\t|tkDrytfd|DS)a7 Report whether another set contains this set. Example: >>> OrderedSet([1, 2, 3]).issubset({1, 2}) False >>> OrderedSet([1, 2, 3]).issubset({1, 2, 3, 4}) True >>> OrderedSet([1, 2, 3]).issubset({1, 4, 3, 5}) False Fc3&K|]}|v ywrrhros r rkz&OrderedSet.issubset..s2TT45=Trallrds `r issubsetzOrderedSet.issubsetys) t9s5z !2T222rc\tt|krytfd|DS)a= Report whether this set contains another set. Example: >>> OrderedSet([1, 2]).issuperset([1, 2, 3]) False >>> OrderedSet([1, 2, 3, 4]).issuperset({1, 2, 3}) True >>> OrderedSet([1, 4, 3, 5]).issuperset({1, 2, 3}) False Fc3&K|]}|v ywrrh)rir;rs r rkz(OrderedSet.issuperset..s2ED44>> this = OrderedSet([1, 4, 3, 5, 7]) >>> other = OrderedSet([9, 7, 1, 3, 2]) >>> this.symmetric_difference(other) OrderedSet([4, 5, 9, 2]) )r rr#rpra)rrWr_diff1diff2s r symmetric_differencezOrderedSet.symmetric_differencesO!+4 >> this = OrderedSet([1, 2, 3]) >>> this.difference_update(OrderedSet([2, 4])) >>> print(this) OrderedSet([1, 3]) >>> this = OrderedSet([1, 2, 3, 4, 5]) >>> this.difference_update(OrderedSet([2, 4]), OrderedSet([1, 4, 6])) >>> print(this) OrderedSet([3, 5]) NrVrr)rr^items_to_removerWr;s r difference_updatezOrderedSet.difference_updatesN%E s5z )O TZZWZT4;VDZWXWs AAct|}|j|jDcgc] }||vs| c}ycc}w)a^ Update this OrderedSet to keep only items in another set, preserving their order in this set. Example: >>> this = OrderedSet([1, 4, 3, 5, 7]) >>> other = OrderedSet([9, 7, 1, 3, 2]) >>> this.intersection_update(other) >>> print(this) OrderedSet([1, 3, 7]) Nr)rrWr;s r intersection_updatezOrderedSet.intersection_updates7E  TZZIZT45=DZIJIs ;;c|Dcgc] }||vs| }}t|}|j|jDcgc] }||vs| c}|zycc}wcc}w)a Update this OrderedSet to remove items from another set, then add items from the other set that were not present in this set. Example: >>> this = OrderedSet([1, 4, 3, 5, 7]) >>> other = OrderedSet([9, 7, 1, 3, 2]) >>> this.symmetric_difference_update(other) >>> print(this) OrderedSet([4, 5, 9, 2]) Nr)rrWr; items_to_addrs r symmetric_difference_updatez&OrderedSet.symmetric_difference_updatesd*/C$d2B Ce* "jj HjdD,GTj H< W D Is AA AAr)#rS __module__ __qualname____doc__rrr(r!r+r.r2r5r4r<r%get_loc get_indexerrCrHrJrrOrTrYrarercrprvryr}rrrrrhrr rr*s S> $ ! &F,$GK&(0 $@ -<&(,,3 3 "(CY( K rr)r itertoolsr[ collectionsrcollections.abcrr ImportErrorrr __version__rrrhrr rsV14 $K  (~ X~ 91001s0 AA