a (šRe;ã@szdZddlZddlmZzddlmZmZWn"eyNddlmZmZYn0e dƒZ dZ dd„Z Gdd „d eeƒZ dS) 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)Ú MutableSetÚSequencez3.1cCs"t|dƒo t|tƒ o t|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Ú isinstanceÚstrÚtuple)Úobj©r ú”/builddir/build/BUILDROOT/alt-python39-setuptools-58.3.0-2.el8.x86_64/opt/alt/python39/lib/python3.9/site-packages/setuptools/_vendor/ordered_set.pyÚ is_iterables   ÿ ýr c@sþeZdZdZd;dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z e Z dd„Z dd„ZeZeZdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Z d7d8„Z!d9d:„Z"dS)<Ú 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]) NcCs g|_i|_|dur||O}dS©N)ÚitemsÚmap)ÚselfÚiterabler r r Ú__init__4szOrderedSet.__init__cCs t|jƒS)zÄ Returns the number of unique elements in the ordered set Example: >>> len(OrderedSet([])) 0 >>> len(OrderedSet([1, 2])) 2 )Úlenr©rr r r Ú__len__:s zOrderedSet.__len__cs|t|tƒr|tkrˆ ¡St|ƒr4‡fdd„|DƒSt|dƒsHt|tƒrlˆj|}t|tƒrfˆ |¡S|Sn t d|ƒ‚dS)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 csg|]}ˆj|‘qSr )r)Ú.0Úirr r Ú [óz*OrderedSet.__getitem__..Ú __index__z+Don't know how to index an OrderedSet by %rN) rÚsliceÚ SLICE_ALLÚcopyr rrÚlistÚ __class__Ú TypeError)rÚindexÚresultr rr Ú __getitem__Fs   zOrderedSet.__getitem__cCs | |¡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!rr r r res zOrderedSet.copycCst|ƒdkrdSt|ƒSdS)Nrr)rr rr r r Ú __getstate__ss zOrderedSet.__getstate__cCs"|dkr| g¡n | |¡dS)Nr)r)rÚstater r r Ú __setstate__s zOrderedSet.__setstate__cCs ||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 )r©rÚkeyr r r Ú __contains__…s zOrderedSet.__contains__cCs0||jvr&t|jƒ|j|<|j |¡|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]) )rrrÚappendr)r r r Úadd‘s  zOrderedSet.addcCsDd}z|D]}| |¡}q Wn"ty>tdt|ƒƒ‚Yn0|S)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)r-r"Ú ValueErrorÚtype)rÚsequenceZ item_indexÚitemr r r Úupdate¦s   ÿ zOrderedSet.updatecs$t|ƒr‡fdd„|DƒSˆj|S)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 csg|]}ˆ |¡‘qSr )r#)rÚsubkeyrr r rÊrz$OrderedSet.index..)r rr)r rr r#¼s zOrderedSet.indexcCs,|jstdƒ‚|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éÿÿÿÿ)rÚKeyErrorr)rÚelemr r r ÚpopÑs  zOrderedSet.popcCsP||vrL|j|}|j|=|j|=|j ¡D]\}}||kr,|d|j|<q,dS)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)rr*rÚkÚvr r r Údiscardäs zOrderedSet.discardcCs|jdd…=|j ¡dS)z8 Remove all items from this OrderedSet. N)rrÚclearrr r r r<üs zOrderedSet.clearcCs t|jƒS)zb Example: >>> list(iter(OrderedSet([1, 2, 3]))) [1, 2, 3] )Úiterrrr r r rszOrderedSet.__iter__cCs t|jƒS)zf Example: >>> list(reversed(OrderedSet([1, 2, 3]))) [3, 2, 1] )Úreversedrrr r r Ú __reversed__ szOrderedSet.__reversed__cCs&|sd|jjfSd|jjt|ƒfS)Nz%s()z%s(%r))r!Ú__name__r rr r r Ú__repr__szOrderedSet.__repr__cCsPt|ttfƒrt|ƒt|ƒkSz t|ƒ}Wnty>YdS0t|ƒ|kSdS)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 FN)rrrr Úsetr")rÚotherZ other_as_setr r r Ú__eq__s  zOrderedSet.__eq__cGs<t|tƒr|jnt}ttt |g|¡ƒ}tj |¡}||ƒ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]) )rrr!rr ÚitÚchainÚ from_iterable)rÚsetsÚclsZ containersrr r r Úunion6s zOrderedSet.unioncCs | |¡Sr)Ú intersection©rrCr r r Ú__and__IszOrderedSet.__and__csHt|tƒr|jnt}|r>> 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]) c3s|]}|ˆvr|VqdSrr ©rr1©Úcommonr r Ú ^rz*OrderedSet.intersection..)rrr!rBrKr©rrHrIrr rOr rKMs zOrderedSet.intersectioncs:|j}|r.tjtt|ƒŽ‰‡fdd„|Dƒ}n|}||ƒS)aÝ Returns all elements that are in this set but not the others. Example: >>> 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]) c3s|]}|ˆvr|VqdSrr rN©rCr r rQtrz(OrderedSet.difference..)r!rBrJrrRr rSr Ú differencecs zOrderedSet.differencecs*t|ƒtˆƒkrdSt‡fdd„|DƒƒS)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 Fc3s|]}|ˆvVqdSrr rNrSr r rQ‡rz&OrderedSet.issubset..©rÚallrLr rSr Úissubsetys zOrderedSet.issubsetcs*tˆƒt|ƒkrdSt‡fdd„|DƒƒS)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 Fc3s|]}|ˆvVqdSrr rNrr r rQ—rz(OrderedSet.issuperset..rUrLr rr Ú issuperset‰s zOrderedSet.issupersetcCs:t|tƒr|jnt}||ƒ |¡}||ƒ |¡}| |¡S)að Return the symmetric difference of two OrderedSets as a new set. That is, the new set will contain all elements that are in exactly one of the sets. Their order will be preserved, with elements from `self` preceding elements from `other`. Example: >>> this = OrderedSet([1, 4, 3, 5, 7]) >>> other = OrderedSet([9, 7, 1, 3, 2]) >>> this.symmetric_difference(other) OrderedSet([4, 5, 9, 2]) )rrr!rTrJ)rrCrIZdiff1Zdiff2r r r Úsymmetric_difference™szOrderedSet.symmetric_differencecCs||_dd„t|ƒDƒ|_dS)zt Replace the 'items' list of this OrderedSet with a new one, updating self.map accordingly. cSsi|]\}}||“qSr r )rÚidxr1r r r Ú ³rz,OrderedSet._update_items..N)rÚ enumerater)rrr r r Ú _update_items­szOrderedSet._update_itemscs:tƒ‰|D]}ˆt|ƒO‰q | ‡fdd„|jDƒ¡dS)aË Update this OrderedSet to remove items from one or more other sets. Example: >>> 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]) csg|]}|ˆvr|‘qSr r rN©Úitems_to_remover r rÇrz0OrderedSet.difference_update..N©rBr]r)rrHrCr r^r Údifference_updateµszOrderedSet.difference_updatecs&tˆƒ‰| ‡fdd„|jDƒ¡dS)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]) csg|]}|ˆvr|‘qSr r rNrSr r rÖrz2OrderedSet.intersection_update..Nr`rLr rSr Úintersection_updateÉs zOrderedSet.intersection_updatecs<‡fdd„|Dƒ}t|ƒ‰ˆ ‡fdd„ˆjDƒ|¡dS)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]) csg|]}|ˆvr|‘qSr r rNrr r rärz:OrderedSet.symmetric_difference_update..csg|]}|ˆvr|‘qSr r rNr^r r rçrNr`)rrCZ items_to_addr )r_rr Úsymmetric_difference_updateØs ÿz&OrderedSet.symmetric_difference_update)N)#r@Ú __module__Ú __qualname__Ú__doc__rrr%rr&r(r+r-r,r2r#Zget_locZ get_indexerr7r;r<rr?rArDrJrMrKrTrWrXrYr]rarbrcr r r r r*s@    r)rfÚ itertoolsrEÚ collectionsrÚcollections.abcrrÚ ImportErrorrrÚ __version__r rr r r r Ús