-# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2003-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-"""A simple Set class."""
-
-
class Set(object):
"""A simple set class.
- Sets are not in Python until 2.3, and rdata are not immutable so
- we cannot use sets.Set anyway. This class implements subset of
- the 2.3 Set interface using a list as the container.
-
- @ivar items: A list of the items which are in the set
- @type items: list"""
+ This class was originally used to deal with sets being missing in
+ ancient versions of python, but dnspython will continue to use it
+ as these sets are based on lists and are thus indexable, and this
+ ability is widely used in dnspython applications.
+ """
__slots__ = ['items']
return "dns.simpleset.Set(%s)" % repr(self.items)
def add(self, item):
- """Add an item to the set."""
+ """Add an item to the set.
+ """
+
if item not in self.items:
self.items.append(item)
def remove(self, item):
- """Remove an item from the set."""
+ """Remove an item from the set.
+ """
+
self.items.remove(item)
def discard(self, item):
- """Remove an item from the set if present."""
+ """Remove an item from the set if present.
+ """
+
try:
self.items.remove(item)
except ValueError:
return obj
def __copy__(self):
- """Make a (shallow) copy of the set."""
+ """Make a (shallow) copy of the set.
+ """
+
return self._clone()
def copy(self):
- """Make a (shallow) copy of the set."""
+ """Make a (shallow) copy of the set.
+ """
+
return self._clone()
def union_update(self, other):
"""Update the set, adding any elements from other which are not
already in the set.
- @param other: the collection of items with which to update the set
- @type other: Set object
"""
+
if not isinstance(other, Set):
raise ValueError('other must be a Set instance')
if self is other:
def intersection_update(self, other):
"""Update the set, removing any elements from other which are not
in both sets.
- @param other: the collection of items with which to update the set
- @type other: Set object
"""
+
if not isinstance(other, Set):
raise ValueError('other must be a Set instance')
if self is other:
def difference_update(self, other):
"""Update the set, removing any elements from other which are in
the set.
- @param other: the collection of items with which to update the set
- @type other: Set object
"""
+
if not isinstance(other, Set):
raise ValueError('other must be a Set instance')
if self is other:
self.discard(item)
def union(self, other):
- """Return a new set which is the union of I{self} and I{other}.
+ """Return a new set which is the union of ``self`` and ``other``.
- @param other: the other set
- @type other: Set object
- @rtype: the same type as I{self}
+ Returns the same Set type as this set.
"""
obj = self._clone()
return obj
def intersection(self, other):
- """Return a new set which is the intersection of I{self} and I{other}.
+ """Return a new set which is the intersection of ``self`` and
+ ``other``.
- @param other: the other set
- @type other: Set object
- @rtype: the same type as I{self}
+ Returns the same Set type as this set.
"""
obj = self._clone()
return obj
def difference(self, other):
- """Return a new set which I{self} - I{other}, i.e. the items
- in I{self} which are not also in I{other}.
+ """Return a new set which ``self`` - ``other``, i.e. the items
+ in ``self`` which are not also in ``other``.
- @param other: the other set
- @type other: Set object
- @rtype: the same type as I{self}
+ Returns the same Set type as this set.
"""
obj = self._clone()
def update(self, other):
"""Update the set, adding any elements from other which are not
already in the set.
- @param other: the collection of items with which to update the set
- @type other: any iterable type"""
+
+ *other*, the collection of items with which to update the set, which
+ may be any iterable type.
+ """
+
for item in other:
self.add(item)
del self.items[i]
def issubset(self, other):
- """Is I{self} a subset of I{other}?
+ """Is this set a subset of *other*?
- @rtype: bool
+ Returns a ``bool``.
"""
if not isinstance(other, Set):
return True
def issuperset(self, other):
- """Is I{self} a superset of I{other}?
+ """Is this set a superset of *other*?
- @rtype: bool
+ Returns a ``bool``.
"""
if not isinstance(other, Set):