Update dnspython-2.2.0

This commit is contained in:
JonnyWong16 2021-10-14 21:36:41 -07:00
parent 4b28040d59
commit 4d62245cf5
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
111 changed files with 9077 additions and 5877 deletions

View file

@ -1,4 +1,6 @@
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
# 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,
@ -13,52 +15,61 @@
# 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."""
import itertools
import sys
if sys.version_info >= (3, 7):
odict = dict
else:
from collections import OrderedDict as odict # pragma: no cover
class Set(object):
class Set:
"""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']
def __init__(self, items=None):
"""Initialize the set.
@param items: the initial set of items
@type items: any iterable or None
*items*, an iterable or ``None``, the initial set of items.
"""
self.items = []
self.items = odict()
if items is not None:
for item in items:
self.add(item)
def __repr__(self):
return "dns.simpleset.Set(%s)" % repr(self.items)
return "dns.set.Set(%s)" % repr(list(self.items.keys()))
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)
self.items[item] = None
def remove(self, item):
"""Remove an item from the set."""
self.items.remove(item)
"""Remove an item from the set.
"""
try:
del self.items[item]
except KeyError:
raise ValueError
def discard(self, item):
"""Remove an item from the set if present."""
try:
self.items.remove(item)
except ValueError:
pass
"""Remove an item from the set if present.
"""
self.items.pop(item, None)
def _clone(self):
"""Make a (shallow) copy of the set.
@ -75,23 +86,26 @@ class Set(object):
cls = self.__class__
obj = cls.__new__(cls)
obj.items = list(self.items)
obj.items = self.items.copy()
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:
@ -102,9 +116,8 @@ class Set(object):
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:
@ -113,28 +126,25 @@ class Set(object):
# the list without breaking the iterator.
for item in list(self.items):
if item not in other.items:
self.items.remove(item)
del self.items[item]
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.items = []
self.items.clear()
else:
for item in other.items:
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()
@ -142,11 +152,10 @@ class Set(object):
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()
@ -154,12 +163,10 @@ class Set(object):
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()
@ -197,25 +204,26 @@ class Set(object):
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)
def clear(self):
"""Make the set empty."""
self.items = []
self.items.clear()
def __eq__(self, other):
# Yes, this is inefficient but the sets we're dealing with are
# usually quite small, so it shouldn't hurt too much.
for item in self.items:
if item not in other.items:
if odict == dict:
return self.items == other.items
else:
# We don't want an ordered comparison.
if len(self.items) != len(other.items):
return False
for item in other.items:
if item not in self.items:
return False
return True
return all(elt in other.items for elt in self.items)
def __ne__(self, other):
return not self.__eq__(other)
@ -227,21 +235,22 @@ class Set(object):
return iter(self.items)
def __getitem__(self, i):
return self.items[i]
if isinstance(i, slice):
return list(itertools.islice(self.items, i.start, i.stop, i.step))
else:
return next(itertools.islice(self.items, i, i + 1))
def __delitem__(self, i):
del self.items[i]
def __getslice__(self, i, j):
return self.items[i:j]
def __delslice__(self, i, j):
del self.items[i:j]
if isinstance(i, slice):
for elt in list(self[i]):
del self.items[elt]
else:
del self.items[self[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):
@ -252,9 +261,9 @@ class Set(object):
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):