Python collections.Set() Examples

The following are code examples for showing how to use collections.Set(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: code   Author: ActiveState   File: recipe-577982.py    (MIT License) View Source Project 6 votes vote down vote up
def objwalk(obj, path=(), memo=None):
    if memo is None:
        memo = set()
    iterator = None
    if isinstance(obj, Mapping):
        iterator = iteritems
    elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, string_types):
        iterator = enumerate
    if iterator:
        if id(obj) not in memo:
            memo.add(id(obj))
            for path_component, value in iterator(obj):
                for result in objwalk(value, path + (path_component,), memo):
                    yield result
            memo.remove(id(obj))
    else:
        yield path, obj

# optional test code from here on 
Example 2
Project: ngraph   Author: NervanaSystems   File: hetrtransform.py    (license) View Source Project 6 votes vote down vote up
def __call__(self, *args, **kwargs):
        """
        Executes child computations in parallel.

        :arg args: list of values to the placeholders specified in __init__ *args

        :return: tuple of return values, one per return specified in __init__ returns list.
        """
        args = self.unpack_args_or_feed_dict(args, kwargs)
        for child in itervalues(self.child_computations):
            child.feed_input([args[i] for i in child.param_idx])

        return_vals = dict()
        for child in itervalues(self.child_computations):
            return_vals.update(child.get_results())

        if isinstance(self.computation_op.returns, Op):
            return return_vals[self.computation_op.returns]
        elif isinstance(self.computation_op.returns, (collections.Sequence, OrderedSet)):
            return tuple(return_vals[op] for op in self.computation_op.returns)
        elif isinstance(self.computation_op.returns, collections.Set):
            return return_vals
        else:
            return None 
Example 3
Project: oil   Author: oilshell   File: test_dictviews.py    (license) View Source Project 6 votes vote down vote up
def test_abc_registry(self):
        d = dict(a=1)

        self.assertIsInstance(d.viewkeys(), collections.KeysView)
        self.assertIsInstance(d.viewkeys(), collections.MappingView)
        self.assertIsInstance(d.viewkeys(), collections.Set)
        self.assertIsInstance(d.viewkeys(), collections.Sized)
        self.assertIsInstance(d.viewkeys(), collections.Iterable)
        self.assertIsInstance(d.viewkeys(), collections.Container)

        self.assertIsInstance(d.viewvalues(), collections.ValuesView)
        self.assertIsInstance(d.viewvalues(), collections.MappingView)
        self.assertIsInstance(d.viewvalues(), collections.Sized)

        self.assertIsInstance(d.viewitems(), collections.ItemsView)
        self.assertIsInstance(d.viewitems(), collections.MappingView)
        self.assertIsInstance(d.viewitems(), collections.Set)
        self.assertIsInstance(d.viewitems(), collections.Sized)
        self.assertIsInstance(d.viewitems(), collections.Iterable)
        self.assertIsInstance(d.viewitems(), collections.Container) 
Example 4
Project: python2-tracer   Author: extremecoders-re   File: test_dictviews.py    (license) View Source Project 6 votes vote down vote up
def test_abc_registry(self):
        d = dict(a=1)

        self.assertIsInstance(d.viewkeys(), collections.KeysView)
        self.assertIsInstance(d.viewkeys(), collections.MappingView)
        self.assertIsInstance(d.viewkeys(), collections.Set)
        self.assertIsInstance(d.viewkeys(), collections.Sized)
        self.assertIsInstance(d.viewkeys(), collections.Iterable)
        self.assertIsInstance(d.viewkeys(), collections.Container)

        self.assertIsInstance(d.viewvalues(), collections.ValuesView)
        self.assertIsInstance(d.viewvalues(), collections.MappingView)
        self.assertIsInstance(d.viewvalues(), collections.Sized)

        self.assertIsInstance(d.viewitems(), collections.ItemsView)
        self.assertIsInstance(d.viewitems(), collections.MappingView)
        self.assertIsInstance(d.viewitems(), collections.Set)
        self.assertIsInstance(d.viewitems(), collections.Sized)
        self.assertIsInstance(d.viewitems(), collections.Iterable)
        self.assertIsInstance(d.viewitems(), collections.Container) 
Example 5
Project: nirum-python   Author: spoqa   File: validate.py    (license) View Source Project 6 votes vote down vote up
def validate_type(data, type_):
    instance_check = False
    abstract_types = {typing.AbstractSet, typing.Sequence, typing.Mapping}
    if hasattr(type_, '__origin__') and type_.__origin__ in abstract_types:
        param_type = get_abstract_param_types(type_)
        imp_types = {
            typing.AbstractSet: collections.Set,
            typing.Sequence: collections.Sequence,
            typing.Mapping: collections.Mapping,
        }
        instance_check = isinstance(data, imp_types[type_.__origin__]) and \
            all(isinstance(item, param_type[0]) for item in data)
    else:
        try:
            instance_check = isinstance(data, type_)
        except TypeError:
            if is_union_type(type_):
                instance_check = any(
                    isinstance(data, t) for t in get_union_types(type_)
                )
            else:
                raise ValueError('{!r} cannot validated.'.format(type_))
    return instance_check 
Example 6
Project: nirum-python   Author: spoqa   File: serialize.py    (license) View Source Project 6 votes vote down vote up
def serialize_meta(data):
    if hasattr(data, '__nirum_serialize__'):
        d = data.__nirum_serialize__()
    elif isinstance(data, (string_types, bool, int, float)):
        # FIXME: str in py2 represents binary string as well as text string.
        # It should be refactored so that the function explicitly takes
        # an expected type as like deserialize_meta() does.
        d = data
    elif (isinstance(data, datetime.datetime) or
            isinstance(data, datetime.date)):
        d = data.isoformat()
    elif isinstance(data, decimal.Decimal) or isinstance(data, uuid.UUID):
        d = str(data)
    elif (isinstance(data, collections.Set) or
          isinstance(data, collections.Sequence)):
        d = [serialize_meta(e) for e in data]
    elif isinstance(data, collections.Mapping):
        d = [
            {'key': serialize_meta(k), 'value': serialize_meta(v)}
            for k, v in data.items()
        ]
    else:
        d = data
    return d 
Example 7
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sortedset.py    (license) View Source Project 6 votes vote down vote up
def _make_cmp(self, set_op, doc):
        "Make comparator method."
        def comparer(self, that):
            "Compare method for sorted set and set-like object."
            # pylint: disable=protected-access
            if isinstance(that, SortedSet):
                return set_op(self._set, that._set)
            elif isinstance(that, Set):
                return set_op(self._set, that)
            else:
                return NotImplemented

        comparer.__name__ = '__{0}__'.format(set_op.__name__)
        doc_str = 'Return True if and only if Set is {0} `that`.'
        comparer.__doc__ = doc_str.format(doc)

        return comparer 
Example 8
Project: TA-SyncKVStore   Author: georgestarcher   File: sortedset.py    (license) View Source Project 6 votes vote down vote up
def _make_cmp(self, set_op, doc):
        "Make comparator method."
        def comparer(self, that):
            "Compare method for sorted set and set-like object."
            # pylint: disable=protected-access
            if isinstance(that, SortedSet):
                return set_op(self._set, that._set)
            elif isinstance(that, Set):
                return set_op(self._set, that)
            else:
                return NotImplemented

        comparer.__name__ = '__{0}__'.format(set_op.__name__)
        doc_str = 'Return True if and only if Set is {0} `that`.'
        comparer.__doc__ = doc_str.format(doc)

        return comparer 
Example 9
Project: cb-defense-splunk-app   Author: carbonblack   File: sortedset.py    (license) View Source Project 6 votes vote down vote up
def _make_cmp(self, set_op, doc):
        "Make comparator method."
        def comparer(self, that):
            "Compare method for sorted set and set-like object."
            # pylint: disable=protected-access
            if isinstance(that, SortedSet):
                return set_op(self._set, that._set)
            elif isinstance(that, Set):
                return set_op(self._set, that)
            else:
                return NotImplemented

        comparer.__name__ = '__{0}__'.format(set_op.__name__)
        doc_str = 'Return True if and only if Set is {0} `that`.'
        comparer.__doc__ = doc_str.format(doc)

        return comparer 
Example 10
Project: django-clubhouse   Author: chazmead   File: enum.py    (license) View Source Project 6 votes vote down vote up
def __hash__(self):
        # taken from collections.Set
        max_i = sys.maxint
        mask = 2 * max_i + 1
        n = len(self)
        h = 1927868237 * (n + 1)
        h &= mask
        for x in self:
            hx = hash(x)
            h ^= (hx ^ (hx << 16) ^ 89869747) * 3644798167
            h &= mask
        h = h * 69069 + 907133923
        h &= mask
        if h > max_i:
            h -= mask + 1
        if h == -1:
            h = 590923713
        return h 
Example 11
Project: bubblesub   Author: rr-   File: util.py    (license) View Source Project 6 votes vote down vote up
def getsize(top_obj):
    visited = set()

    def inner(obj):
        obj_id = id(obj)
        if obj_id in visited:
            return 0
        visited.add(obj_id)
        size = sys.getsizeof(obj)
        if isinstance(obj, (str, bytes, Number, range, bytearray)):
            pass
        elif isinstance(obj, (tuple, list, Set, deque)):
            size += sum(inner(i) for i in obj)
        elif isinstance(obj, Mapping) or hasattr(obj, 'items'):
            size += sum(inner(k) + inner(v) for k, v in obj.items())
        if hasattr(obj, '__dict__'):
            size += inner(vars(obj))
        if hasattr(obj, '__slots__'):
            size += sum(
                inner(getattr(obj, s))
                for s in obj.__slots__ if hasattr(obj, s))
        return size

    return inner(top_obj) 
Example 12
Project: pyomo   Author: Pyomo   File: component_tuple.py    (license) View Source Project 6 votes vote down vote up
def children(self, return_key=False):
        """Iterate over the children of this container.

        Args:
            return_key (bool): Set to :const:`True` to
                indicate that the return type should be a
                2-tuple consisting of the child storage key
                and the child object. By default, only the
                child objects are returned.

        Returns:
            iterator of objects or (key,object) tuples
        """
        if return_key:
            return enumerate(self._data)
        else:
            return self._data.__iter__()

    #
    # Define the Sequence abstract methods
    # 
Example 13
Project: yatta_reader   Author: sound88   File: properties.py    (license) View Source Project 6 votes vote down vote up
def __init__(
        self,
        types=None,  # type: typing.Sequence[Union[type, Property]]
        name=None,  # type: Optional[str]
        required=False,  # type: bool
        versions=None,  # type: Optional[Sequence[Union[str, Version]]]
        name_space=None,  # type: Optional[str]
        prefix=None,  # type: Optional[str]
        attribute=False,  # type: bool
    ):
        if isinstance(types, (type, Property)):
            types = (types,)
        else:
            types = copy(types)
        self.types = types  # type: Optional[Sequence[type]]
        self.name = name
        self.required = required
        self._versions = None  # type: Optional[Union[Mapping[str, Optional[Property]], Set[Union[str, Number]]]]
        self.versions = versions  # type: Optional[Union[Mapping[str, Optional[Property]], Set[Union[str, Number]]]]
        self.name_space = name_space  # type: Optional[str]
        self.prefix = prefix  # type: Optional[str]
        self.attribute = attribute  # type: Optional[str] 
Example 14
Project: yatta_reader   Author: sound88   File: properties.py    (license) View Source Project 6 votes vote down vote up
def versions(
        self,
        versions  # type: Optional[Sequence[Union[str, Version]]]
    ):
        # type: (...) -> Optional[Union[Mapping[str, Optional[Property]], Set[Union[str, Number]]]]
        if versions is not None:
            if isinstance(versions, (str, Number, meta.Version)):
                versions = (versions,)
            if isinstance(versions, Iterable):
                versions = tuple(
                    (v if isinstance(v, meta.Version) else meta.Version(v))
                    for v in versions
                )
            else:
                raise TypeError(
                    '``Property.versions`` requires a sequence of version strings or ' +
                    '``serial.properties.metadata.Version`` instances, not ' +
                    '``%s``.' % type(versions).__name__
                )
        self._versions = versions 
Example 15
Project: yatta_reader   Author: sound88   File: properties.py    (license) View Source Project 6 votes vote down vote up
def __init__(
        self,
        types=None,  # type: Optional[Sequence[Union[type, Property]]]
        values=None,  # type: Optional[Union[typing.Sequence, typing.Set]]
        name=None,  # type: Optional[str]
        required=False,  # type: bool
        versions=None,  # type: Optional[typing.Collection]
        name_space=None,  # type: Optional[str]
        prefix=None,  # type: Optional[str]
        attribute=False,  # type: bool
    ):
        super().__init__(
            types=types,
            name=name,
            required=required,
            versions=versions,
            name_space=name_space,
            prefix=prefix,
            attribute=attribute
        )
        self._values = None
        self.values = values  # type: Optional[typing.Sequence] 
Example 16
Project: py-flags   Author: pasztorpisti   File: flags.py    (license) View Source Project 6 votes vote down vote up
def process_inline_members_definition(members):
    """
    :param members: this can be any of the following:
    - a string containing a space and/or comma separated list of names: e.g.:
      "item1 item2 item3" OR "item1,item2,item3" OR "item1, item2, item3"
    - tuple/list/Set of strings (names)
    - Mapping of (name, data) pairs
    - any kind of iterable that yields (name, data) pairs
    :return: An iterable of (name, data) pairs.
    """
    if isinstance(members, str):
        members = ((name, UNDEFINED) for name in members.replace(',', ' ').split())
    elif isinstance(members, (tuple, list, collections.Set)):
        if members and isinstance(next(iter(members)), str):
            members = ((name, UNDEFINED) for name in members)
    elif isinstance(members, collections.Mapping):
        members = members.items()
    return members 
Example 17
Project: aws-cfn-plex   Author: lordmuffin   File: types.py    (license) View Source Project 5 votes vote down vote up
def _is_set(self, value):
        if isinstance(value, Set):
            return True
        return False 
Example 18
Project: Intranet-Penetration   Author: yuxiaokui   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 19
Project: Intranet-Penetration   Author: yuxiaokui   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def _make_cmp(set_op, doc):
        def comparer(self, that):
            if isinstance(that, SortedSet):
                return set_op(self._set, that._set)
            elif isinstance(that, Set):
                return set_op(self._set, that)
            else:
                raise TypeError('can only compare to a Set')

        comparer.__name__ = '__{0}__'.format(set_op.__name__)
        comparer.__doc__ = 'Return True if and only if ' + doc

        return comparer 
Example 20
Project: MKFQ   Author: maojingios   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 21
Project: MKFQ   Author: maojingios   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def _make_cmp(set_op, doc):
        def comparer(self, that):
            if isinstance(that, SortedSet):
                return set_op(self._set, that._set)
            elif isinstance(that, Set):
                return set_op(self._set, that)
            else:
                raise TypeError('can only compare to a Set')

        comparer.__name__ = '__{0}__'.format(set_op.__name__)
        comparer.__doc__ = 'Return True if and only if ' + doc

        return comparer 
Example 22
Project: zippy   Author: securesystemslab   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_Set(self):
        for sample in [set, frozenset]:
            self.assertIsInstance(sample(), Set)
            self.assertTrue(issubclass(sample, Set))
        self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__')
        class MySet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        self.validate_comparison(MySet()) 
Example 23
Project: zippy   Author: securesystemslab   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_hash_Set(self):
        class OneTwoThreeSet(Set):
            def __init__(self):
                self.contents = [1, 2, 3]
            def __contains__(self, x):
                return x in self.contents
            def __len__(self):
                return len(self.contents)
            def __iter__(self):
                return iter(self.contents)
            def __hash__(self):
                return self._hash()
        a, b = OneTwoThreeSet(), OneTwoThreeSet()
        self.assertTrue(hash(a) == hash(b)) 
Example 24
Project: zippy   Author: securesystemslab   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_MutableMapping_subclass(self):
        # Test issue 9214
        mymap = UserDict()
        mymap['red'] = 5
        self.assertIsInstance(mymap.keys(), Set)
        self.assertIsInstance(mymap.keys(), KeysView)
        self.assertIsInstance(mymap.items(), Set)
        self.assertIsInstance(mymap.items(), ItemsView)

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.keys() | {'orange'}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), ['orange', 'red'])

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.items() | {('orange', 3)}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), [('orange', 3), ('red', 5)]) 
Example 25
Project: aws-ec2rescue-linux   Author: awslabs   File: types.py    (license) View Source Project 5 votes vote down vote up
def _is_set(self, value):
        if isinstance(value, Set):
            return True
        return False 
Example 26
Project: fg21sim   Author: liweitianux   File: profile.py    (license) View Source Project 5 votes vote down vote up
def getsize(obj):
    """
    Recursively iterate to sum size of object & members.

    Returns
    -------
    size : int
        The size of the object in units of "Bytes".

    Credit
    ------
    * How do I determine the size of an object in Python?
      https://stackoverflow.com/a/30316760/4856091
    """
    zero_depth_bases = (str, bytes, Number, range, bytearray)

    def inner(obj, _seen_ids=set()):
        obj_id = id(obj)
        if obj_id in _seen_ids:
            return 0

        _seen_ids.add(obj_id)
        size = sys.getsizeof(obj)
        if isinstance(obj, zero_depth_bases):
            # bypass remaining control flow and return
            pass
        elif isinstance(obj, (tuple, list, Set, deque)):
            size += sum(inner(i) for i in obj)
        elif isinstance(obj, Mapping) or hasattr(obj, "items"):
            size += sum(inner(k) + inner(v) for k, v in obj.items())
        # Check for custom object instances - may subclass above too
        if hasattr(obj, "__dict__"):
            size += inner(vars(obj))
        if hasattr(obj, "__slots__"):
            # can have ``__slots__`` with ``__dict__``
            size += sum(inner(getattr(obj, s))
                        for s in obj.__slots__ if hasattr(obj, s))
        return size

    return inner(obj) 
Example 27
Project: driveboardapp   Author: nortd   File: compat.py    (license) View Source Project 5 votes vote down vote up
def machine():
    """
    Return machine suffix to use in directory name when looking
    for bootloader.

    PyInstaller is reported to work even on ARM architecture. For that
    case functions system() and architecture() are not enough.
    Path to bootloader has to be composed from system(), architecture()
    and machine() like:
        'Linux-32bit-arm'
    """
    mach = platform.machine()
    if mach.startswith('arm'):
        return 'arm'
    else:
        # Assume x86/x86_64 machine.
        return None


# Set and get environment variables does not handle unicode strings correctly
# on Windows.

# Acting on os.environ instead of using getenv()/setenv()/unsetenv(),
# as suggested in <http://docs.python.org/library/os.html#os.environ>:
# "Calling putenv() directly does not change os.environ, so it's
# better to modify os.environ." (Same for unsetenv.) 
Example 28
Project: oil   Author: oilshell   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_Set(self):
        for sample in [set, frozenset]:
            self.assertIsInstance(sample(), Set)
            self.assertTrue(issubclass(sample, Set))
        self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__')
        class MySet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        self.validate_comparison(MySet()) 
Example 29
Project: oil   Author: oilshell   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_hash_Set(self):
        class OneTwoThreeSet(Set):
            def __init__(self):
                self.contents = [1, 2, 3]
            def __contains__(self, x):
                return x in self.contents
            def __len__(self):
                return len(self.contents)
            def __iter__(self):
                return iter(self.contents)
            def __hash__(self):
                return self._hash()
        a, b = OneTwoThreeSet(), OneTwoThreeSet()
        self.assertTrue(hash(a) == hash(b)) 
Example 30
Project: oil   Author: oilshell   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_issue16373(self):
        # Recursion error comparing comparable and noncomparable
        # Set instances
        class MyComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        class MyNonComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
            def __le__(self, x):
                return NotImplemented
            def __lt__(self, x):
                return NotImplemented

        cs = MyComparableSet()
        ncs = MyNonComparableSet()

        # Run all the variants to make sure they don't mutually recurse
        ncs < cs
        ncs <= cs
        ncs > cs
        ncs >= cs
        cs < ncs
        cs <= ncs
        cs > ncs
        cs >= ncs 
Example 31
Project: python2-tracer   Author: extremecoders-re   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_Set(self):
        for sample in [set, frozenset]:
            self.assertIsInstance(sample(), Set)
            self.assertTrue(issubclass(sample, Set))
        self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__')
        class MySet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        self.validate_comparison(MySet()) 
Example 32
Project: python2-tracer   Author: extremecoders-re   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_hash_Set(self):
        class OneTwoThreeSet(Set):
            def __init__(self):
                self.contents = [1, 2, 3]
            def __contains__(self, x):
                return x in self.contents
            def __len__(self):
                return len(self.contents)
            def __iter__(self):
                return iter(self.contents)
            def __hash__(self):
                return self._hash()
        a, b = OneTwoThreeSet(), OneTwoThreeSet()
        self.assertTrue(hash(a) == hash(b)) 
Example 33
Project: python2-tracer   Author: extremecoders-re   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
def test_issue16373(self):
        # Recursion error comparing comparable and noncomparable
        # Set instances
        class MyComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        class MyNonComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
            def __le__(self, x):
                return NotImplemented
            def __lt__(self, x):
                return NotImplemented

        cs = MyComparableSet()
        ncs = MyNonComparableSet()

        # Run all the variants to make sure they don't mutually recurse
        ncs < cs
        ncs <= cs
        ncs > cs
        ncs >= cs
        cs < ncs
        cs <= ncs
        cs > ncs
        cs >= ncs 
Example 34
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 35
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list) 
Example 36
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __reversed__(self):
        """
        Return an iterator over the Set. Elements are iterated in their reverse
        sorted order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return reversed(self._list) 
Example 37
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 38
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list) 
Example 39
Project: splunk_ta_ps4_f1_2016   Author: jonathanvarley   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __reversed__(self):
        """
        Return an iterator over the Set. Elements are iterated in their reverse
        sorted order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return reversed(self._list) 
Example 40
Project: TA-SyncKVStore   Author: georgestarcher   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 41
Project: TA-SyncKVStore   Author: georgestarcher   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list) 
Example 42
Project: TA-SyncKVStore   Author: georgestarcher   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __reversed__(self):
        """
        Return an iterator over the Set. Elements are iterated in their reverse
        sorted order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return reversed(self._list) 
Example 43
Project: TA-SyncKVStore   Author: georgestarcher   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 44
Project: TA-SyncKVStore   Author: georgestarcher   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list) 
Example 45
Project: pytruth   Author: google   File: truth.py    (license) View Source Project 5 votes vote down vote up
def ContainsNoDuplicates(self):
    # Dictionaries and Sets have unique members by definition; avoid iterating.
    if isinstance(self._actual, (collections.Mapping, collections.Set)):
      return
    duplicates = []
    entries = set()
    for i in self._actual:
      if i in entries:
        duplicates.append(i)
      entries.add(i)
    if duplicates:
      self._FailWithSubject(
          'has the following duplicates: <{0}>'.format(duplicates)) 
Example 46
Project: cb-defense-splunk-app   Author: carbonblack   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 47
Project: cb-defense-splunk-app   Author: carbonblack   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list) 
Example 48
Project: cb-defense-splunk-app   Author: carbonblack   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __reversed__(self):
        """
        Return an iterator over the Set. Elements are iterated in their reverse
        sorted order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return reversed(self._list) 
Example 49
Project: cb-defense-splunk-app   Author: carbonblack   File: sorteddict.py    (license) View Source Project 5 votes vote down vote up
def __setitem__(self, key, value):
        """Set `d[key]` to *value*."""
        if key not in self:
            self._list_add(key)
        self._setitem(key, value) 
Example 50
Project: cb-defense-splunk-app   Author: carbonblack   File: sortedset.py    (license) View Source Project 5 votes vote down vote up
def __iter__(self):
        """
        Return an iterator over the Set. Elements are iterated in their sorted
        order.

        Iterating the Set while adding or deleting values may raise a
        `RuntimeError` or fail to iterate over all entries.
        """
        return iter(self._list)