%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/utils/ |
Current File : //lib/python2.7/site-packages/salt/utils/oset.pyc |
� ���^c @@ sf d Z d d l m Z m Z m Z d d l Z e d � Z d Z d � Z d e j f d � � YZ d S( u� Available at repository https://github.com/LuminosoInsight/ordered-set salt.utils.oset ~~~~~~~~~~~~~~~~ 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. Rob Speer's changes are as follows: - changed the content from a doubly-linked list to a regular Python list. Seriously, who wants O(1) deletes but O(N) lookups by index? - add() returns the index of the added item - index() just returns the index of an item - added a __getstate__ and __setstate__ so it can be pickled - added __getitem__ i ( t absolute_importt unicode_literalst print_functionNu 2.0.1c C@ s- t | d � o, t | t � o, t | t � S( u 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. u __iter__( t hasattrt isinstancet strt tuple( t obj( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt is_iterable s t OrderedSetc B@ s� e Z d Z d d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z e Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z RS( u� An OrderedSet is a custom MutableSet that remembers its order, so that every entry has an index that can be looked up. c C@ s/ g | _ i | _ | d k r+ | | O} n d S( N( t itemst mapt None( t selft iterable( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __init__4 s c C@ s t | j � S( N( t lenR ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __len__: s c C@ s� | t k r | St | d � s. t | t � r[ | j | } t | t � rT t | � S| SnK t | � r� t g | D] } | j | ^ qq � St d j t | � � � � d S( u� Get the item at a given index. If `index` is a slice, you will get back that slice of items. If it's the slice [:], exactly the same object is returned. (If you want an independent copy of an OrderedSet, use `OrderedSet.copy()`.) If `index` is an iterable, you'll get the OrderedSet of items corresponding to those indices. This is similar to NumPy's "fancy indexing". u __index__u+ Don't know how to index an OrderedSet by {}N( t SLICE_ALLR R t sliceR t listR R t TypeErrort formatt repr( R t indext resultt i( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __getitem__= s $c C@ s t | � S( N( R ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt copyV s c C@ s$ t | � d k r d St | � Sd S( Ni ( N( R R R ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __getstate__Y s c C@ s- | d k r | j g � n | j | � d S( N( N( R R ( R t state( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __setstate__e s c C@ s | | j k S( N( R ( R t key( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __contains__k s c C@ sC | | j k r8 t | j � | j | <| j j | � n | j | S( u� 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. ( R R R t append( R R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt addn s c C@ s] d } y$ x | D] } | j | � } q WWn, t k rX t d j t | � � � � n X| S( u~ Update the set with the given iterable sequence, then return the index of the last element inserted. u( Argument needs to be an iterable, got {}N( R R# R t ValueErrorR t type( R t sequencet item_indext item( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt update{ s c C@ s7 t | � r, g | D] } | j | � ^ q S| j | S( u� 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. ( R R R ( R R t subkey( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyR � s c C@ s= | j s t d � � n | j d } | j d =| j | =| S( up Remove and return the last element from the set. Raises KeyError if the set is empty. u Set is emptyi����( R t KeyErrorR ( R t elem( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt pop� s c C@ st | | k rp | j | } | j | =| j | =x@ | j j � D], \ } } | | k r= | d | j | <q= q= Wn d S( u� 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. i N( R R ( R R R t kt v( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt discard� s c C@ s | j 2| j j � d S( u8 Remove all items from this OrderedSet. N( R R t clear( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyR1 � s c C@ s t | j � S( N( t iterR ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __iter__� s c C@ s t | j � S( N( t reversedR ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __reversed__� s c C@ s; | s d j | j j � Sd j | j j t t | � � � S( Nu {}()u {}({})( R t __class__t __name__R R ( R ( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __repr__� s c C@ sp t | t � r7 t | � t | � k o6 | j | j k Sy t | � } Wn t k r[ t SXt | � | k Sd S( N( R R R R t setR t False( R t othert other_as_set( ( s3 /usr/lib/python2.7/site-packages/salt/utils/oset.pyt __eq__� s ( N( R7 t __module__t __doc__R R R R R R R R! R# R"