diff options
author | Brian Wellington <bwelling@xbill.org> | 2020-06-03 15:56:58 -0700 |
---|---|---|
committer | Brian Wellington <bwelling@xbill.org> | 2020-06-03 15:56:58 -0700 |
commit | cc55d17f5478751da21a7b325b2b46e8d94d8ffb (patch) | |
tree | cfe1f182855d91fef11be31e4f4b77eeb214790d /dns | |
parent | 8643c7d660fcc3bf620b085c2e483d1419408f96 (diff) | |
download | dnspython-cc55d17f5478751da21a7b325b2b46e8d94d8ffb.tar.gz |
Minor Python 3 cleanups.
Classes inherit from object by default; there's no need to explicitly
include this.
Replace super(Foo, self) with super().
Diffstat (limited to 'dns')
-rw-r--r-- | dns/edns.py | 6 | ||||
-rw-r--r-- | dns/entropy.py | 2 | ||||
-rw-r--r-- | dns/exception.py | 6 | ||||
-rw-r--r-- | dns/message.py | 6 | ||||
-rw-r--r-- | dns/name.py | 16 | ||||
-rw-r--r-- | dns/namedict.py | 2 | ||||
-rw-r--r-- | dns/node.py | 2 | ||||
-rw-r--r-- | dns/query.py | 6 | ||||
-rw-r--r-- | dns/query.pyi | 2 | ||||
-rw-r--r-- | dns/rdata.py | 4 | ||||
-rw-r--r-- | dns/rdataset.py | 14 | ||||
-rw-r--r-- | dns/rdtypes/ANY/RP.py | 2 | ||||
-rw-r--r-- | dns/rdtypes/CH/A.py | 2 | ||||
-rw-r--r-- | dns/rdtypes/IN/APL.py | 2 | ||||
-rw-r--r-- | dns/renderer.py | 2 | ||||
-rw-r--r-- | dns/resolver.py | 21 | ||||
-rw-r--r-- | dns/rrset.py | 16 | ||||
-rw-r--r-- | dns/set.py | 2 | ||||
-rw-r--r-- | dns/tokenizer.py | 4 | ||||
-rw-r--r-- | dns/trio/query.pyi | 2 | ||||
-rw-r--r-- | dns/update.py | 4 | ||||
-rw-r--r-- | dns/zone.py | 4 |
22 files changed, 63 insertions, 64 deletions
diff --git a/dns/edns.py b/dns/edns.py index dc050e6..109679a 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -43,7 +43,7 @@ PADDING = 12 #: CHAIN CHAIN = 13 -class Option(object): +class Option: """Base class for all EDNS option types.""" @@ -132,7 +132,7 @@ class GenericOption(Option): """ def __init__(self, otype, data): - super(GenericOption, self).__init__(otype) + super().__init__(otype) self.data = data def to_wire(self, file): @@ -169,7 +169,7 @@ class ECSOption(Option): must be 0 in queries, and should be set in responses. """ - super(ECSOption, self).__init__(ECS) + super().__init__(ECS) af = dns.inet.af_for_address(address) if af == dns.inet.AF_INET6: diff --git a/dns/entropy.py b/dns/entropy.py index 293d00b..cd79083 100644 --- a/dns/entropy.py +++ b/dns/entropy.py @@ -25,7 +25,7 @@ except ImportError: import dummy_threading as _threading # type: ignore -class EntropyPool(object): +class EntropyPool: # This is an entropy pool for Python implementations that do not # have a working SystemRandom. I'm not sure there are any, but diff --git a/dns/exception.py b/dns/exception.py index 71ff04f..8f1d488 100644 --- a/dns/exception.py +++ b/dns/exception.py @@ -59,9 +59,9 @@ class DNSException(Exception): # doc string is better implicit message than empty string self.msg = self.__doc__ if args: - super(DNSException, self).__init__(*args) + super().__init__(*args) else: - super(DNSException, self).__init__(self.msg) + super().__init__(self.msg) def _check_params(self, *args, **kwargs): """Old exceptions supported only args and not kwargs. @@ -103,7 +103,7 @@ class DNSException(Exception): return self.fmt.format(**fmtargs) else: # print *args directly in the same way as old DNSException - return super(DNSException, self).__str__() + return super().__str__() class FormError(DNSException): diff --git a/dns/message.py b/dns/message.py index 103bec8..55a9ba1 100644 --- a/dns/message.py +++ b/dns/message.py @@ -90,7 +90,7 @@ AUTHORITY = 2 #: The additional section number ADDITIONAL = 3 -class Message(object): +class Message: """A DNS message.""" def __init__(self, id=None): @@ -592,7 +592,7 @@ class Message(object): self.flags |= dns.opcode.to_flags(opcode) -class _WireReader(object): +class _WireReader: """Wire format reader. @@ -852,7 +852,7 @@ def from_wire(wire, keyring=None, request_mac=b'', xfr=False, origin=None, return m -class _TextReader(object): +class _TextReader: """Text format reader. diff --git a/dns/name.py b/dns/name.py index fb64f42..677f324 100644 --- a/dns/name.py +++ b/dns/name.py @@ -95,7 +95,7 @@ class IDNAException(dns.exception.DNSException): fmt = "IDNA processing exception: {idna_exception}" -class IDNACodec(object): +class IDNACodec: """Abstract base class for IDNA encoder/decoders.""" def __init__(self): @@ -128,7 +128,7 @@ class IDNA2003Codec(IDNACodec): was encoded with IDNA2008. The default is `False`. """ - super(IDNA2003Codec, self).__init__() + super().__init__() self.strict_decode = strict_decode def encode(self, label): @@ -144,7 +144,7 @@ class IDNA2003Codec(IDNACodec): def decode(self, label): """Decode *label*.""" if not self.strict_decode: - return super(IDNA2003Codec, self).decode(label) + return super().decode(label) if label == b'': return '' try: @@ -181,7 +181,7 @@ class IDNA2008Codec(IDNACodec): is done when decoding. This can cause failures if the name was encoded with IDNA2003. The default is False. """ - super(IDNA2008Codec, self).__init__() + super().__init__() self.uts_46 = uts_46 self.transitional = transitional self.allow_pure_ascii = allow_pure_ascii @@ -203,7 +203,7 @@ class IDNA2008Codec(IDNACodec): def decode(self, label): if not self.strict_decode: - return super(IDNA2008Codec, self).decode(label) + return super().decode(label) if label == b'': return '' if not have_idna_2008: @@ -300,7 +300,7 @@ def _maybe_convert_to_binary(label): raise ValueError -class Name(object): +class Name: """A DNS name. @@ -316,7 +316,7 @@ class Name(object): """ labels = [_maybe_convert_to_binary(x) for x in labels] - super(Name, self).__setattr__('labels', tuple(labels)) + super().__setattr__('labels', tuple(labels)) _validate_labels(self.labels) def __setattr__(self, name, value): @@ -338,7 +338,7 @@ class Name(object): return {'labels': self.labels} def __setstate__(self, state): - super(Name, self).__setattr__('labels', state['labels']) + super().__setattr__('labels', state['labels']) _validate_labels(self.labels) def is_absolute(self): diff --git a/dns/namedict.py b/dns/namedict.py index 5807453..ce51e52 100644 --- a/dns/namedict.py +++ b/dns/namedict.py @@ -44,7 +44,7 @@ class NameDict(MutableMapping): __slots__ = ["max_depth", "max_depth_items", "__store"] def __init__(self, *args, **kwargs): - super(NameDict, self).__init__() + super().__init__() self.__store = dict() #: the maximum depth of the keys that have ever been added self.max_depth = 0 diff --git a/dns/node.py b/dns/node.py index 6ac79fd..1425bbc 100644 --- a/dns/node.py +++ b/dns/node.py @@ -24,7 +24,7 @@ import dns.rdatatype import dns.renderer -class Node(object): +class Node: """A Node is a set of rdatasets.""" diff --git a/dns/query.py b/dns/query.py index 0ccbcc9..b13bb7c 100644 --- a/dns/query.py +++ b/dns/query.py @@ -47,7 +47,7 @@ except ImportError: try: import ssl except ImportError: - class ssl(object): # type: ignore + class ssl: # type: ignore class WantReadException(Exception): pass @@ -55,7 +55,7 @@ except ImportError: class WantWriteException(Exception): pass - class SSLSocket(object): + class SSLSocket: pass def create_default_context(self, *args, **kwargs): @@ -78,7 +78,7 @@ class TransferError(dns.exception.DNSException): def __init__(self, rcode): message = 'Zone transfer error: %s' % dns.rcode.to_text(rcode) - super(TransferError, self).__init__(message) + super().__init__(message) self.rcode = rcode diff --git a/dns/query.pyi b/dns/query.pyi index 219e50f..6411b9e 100644 --- a/dns/query.pyi +++ b/dns/query.pyi @@ -10,7 +10,7 @@ from requests.sessions import Session try: import ssl except ImportError: - class ssl(object): # type: ignore + class ssl: # type: ignore SSLContext : Dict = {} have_doh: bool diff --git a/dns/rdata.py b/dns/rdata.py index be5d3db..ae668b3 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -103,7 +103,7 @@ def _constify(o): return tuple(_constify(elt) for elt in o) return o -class Rdata(object): +class Rdata: """Base class for all DNS rdata types.""" __slots__ = ['rdclass', 'rdtype'] @@ -340,7 +340,7 @@ class GenericRdata(Rdata): __slots__ = ['data'] def __init__(self, rdclass, rdtype, data): - super(GenericRdata, self).__init__(rdclass, rdtype) + super().__init__(rdclass, rdtype) object.__setattr__(self, 'data', data) def to_text(self, origin=None, relativize=True, **kw): diff --git a/dns/rdataset.py b/dns/rdataset.py index 1e0d7d3..660415e 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -58,14 +58,14 @@ class Rdataset(dns.set.Set): *ttl*, an ``int``, the TTL. """ - super(Rdataset, self).__init__() + super().__init__() self.rdclass = rdclass self.rdtype = rdtype self.covers = covers self.ttl = ttl def _clone(self): - obj = super(Rdataset, self)._clone() + obj = super()._clone() obj.rdclass = self.rdclass obj.rdtype = self.rdtype obj.covers = self.covers @@ -123,15 +123,15 @@ class Rdataset(dns.set.Set): raise DifferingCovers if dns.rdatatype.is_singleton(rd.rdtype) and len(self) > 0: self.clear() - super(Rdataset, self).add(rd) + super().add(rd) def union_update(self, other): self.update_ttl(other.ttl) - super(Rdataset, self).union_update(other) + super().union_update(other) def intersection_update(self, other): self.update_ttl(other.ttl) - super(Rdataset, self).intersection_update(other) + super().intersection_update(other) def update(self, other): """Add all rdatas in other to self. @@ -141,7 +141,7 @@ class Rdataset(dns.set.Set): """ self.update_ttl(other.ttl) - super(Rdataset, self).update(other) + super().update(other) def _rdata_repr(self): def maybe_truncate(s): @@ -170,7 +170,7 @@ class Rdataset(dns.set.Set): self.rdtype != other.rdtype or \ self.covers != other.covers: return False - return super(Rdataset, self).__eq__(other) + return super().__eq__(other) def __ne__(self, other): return not self.__eq__(other) diff --git a/dns/rdtypes/ANY/RP.py b/dns/rdtypes/ANY/RP.py index 5c4cc59..fa3aaac 100644 --- a/dns/rdtypes/ANY/RP.py +++ b/dns/rdtypes/ANY/RP.py @@ -29,7 +29,7 @@ class RP(dns.rdata.Rdata): __slots__ = ['mbox', 'txt'] def __init__(self, rdclass, rdtype, mbox, txt): - super(RP, self).__init__(rdclass, rdtype) + super().__init__(rdclass, rdtype) object.__setattr__(self, 'mbox', mbox) object.__setattr__(self, 'txt', txt) diff --git a/dns/rdtypes/CH/A.py b/dns/rdtypes/CH/A.py index fefbab6..ca34932 100644 --- a/dns/rdtypes/CH/A.py +++ b/dns/rdtypes/CH/A.py @@ -28,7 +28,7 @@ class A(dns.rdtypes.mxbase.MXBase): __slots__ = ['domain', 'address'] def __init__(self, rdclass, rdtype, address, domain): - super(A, self).__init__(rdclass, rdtype, address, domain) + super().__init__(rdclass, rdtype, address, domain) object.__setattr__(self, 'domain', domain) object.__setattr__(self, 'address', address) diff --git a/dns/rdtypes/IN/APL.py b/dns/rdtypes/IN/APL.py index 5facf05..7149a64 100644 --- a/dns/rdtypes/IN/APL.py +++ b/dns/rdtypes/IN/APL.py @@ -25,7 +25,7 @@ import dns.ipv6 import dns.rdata import dns.tokenizer -class APLItem(object): +class APLItem: """An APL list item.""" diff --git a/dns/renderer.py b/dns/renderer.py index 02a9e3d..27d96a6 100644 --- a/dns/renderer.py +++ b/dns/renderer.py @@ -32,7 +32,7 @@ AUTHORITY = 2 ADDITIONAL = 3 -class Renderer(object): +class Renderer: """Helper class for building DNS wire-format messages. Most applications can use the higher-level L{dns.message.Message} diff --git a/dns/resolver.py b/dns/resolver.py index 54ed529..e00aead 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -66,7 +66,7 @@ class NXDOMAIN(dns.exception.DNSException): def __str__(self): if 'qnames' not in self.kwargs: - return super(NXDOMAIN, self).__str__() + return super().__str__() qnames = self.kwargs['qnames'] if len(qnames) > 1: msg = 'None of DNS query names exist' @@ -145,8 +145,7 @@ class NoAnswer(dns.exception.DNSException): supp_kwargs = {'response'} def _fmt_kwargs(self, **kwargs): - return super(NoAnswer, self)._fmt_kwargs( - query=kwargs['response'].question) + return super()._fmt_kwargs(query=kwargs['response'].question) class NoNameservers(dns.exception.DNSException): @@ -167,8 +166,8 @@ class NoNameservers(dns.exception.DNSException): for err in kwargs['errors']: srv_msgs.append('Server {} {} port {} answered {}'.format(err[0], 'TCP' if err[1] else 'UDP', err[2], err[3])) - return super(NoNameservers, self)._fmt_kwargs( - query=kwargs['request'].question, errors='; '.join(srv_msgs)) + return super()._fmt_kwargs(query=kwargs['request'].question, + errors='; '.join(srv_msgs)) class NotAbsolute(dns.exception.DNSException): @@ -185,7 +184,7 @@ class NoMetaqueries(dns.exception.DNSException): class NoResolverConfiguration(dns.exception.DNSException): """Resolver configuration could not be read or specified no nameservers.""" -class Answer(object): +class Answer: """DNS stub resolver answer. Instances of this class bundle up the result of a successful DNS @@ -286,7 +285,7 @@ class Answer(object): del self.rrset[i] -class Cache(object): +class Cache: """Simple thread-safe DNS answer cache.""" def __init__(self, cleaning_interval=300.0): @@ -363,7 +362,7 @@ class Cache(object): self.next_cleaning = time.time() + self.cleaning_interval -class LRUCacheNode(object): +class LRUCacheNode: """LRUCache node.""" def __init__(self, key, value): @@ -389,7 +388,7 @@ class LRUCacheNode(object): self.prev.next = self.next -class LRUCache(object): +class LRUCache: """Thread-safe, bounded, least-recently-used DNS answer cache. This cache is better than the simple cache (above) if you're @@ -486,7 +485,7 @@ class LRUCache(object): node = next self.data = {} -class _Resolution(object): +class _Resolution: """Helper class for dns.resolver.Resolver.resolve(). All of the "business logic" of resolution is encapsulated in this @@ -677,7 +676,7 @@ class _Resolution(object): dns.rcode.to_text(rcode), response)) return (None, False) -class Resolver(object): +class Resolver: """DNS stub resolver.""" # We initialize in reset() diff --git a/dns/rrset.py b/dns/rrset.py index ac4289d..68136f4 100644 --- a/dns/rrset.py +++ b/dns/rrset.py @@ -41,12 +41,12 @@ class RRset(dns.rdataset.Rdataset): deleting=None): """Create a new RRset.""" - super(RRset, self).__init__(rdclass, rdtype, covers) + super().__init__(rdclass, rdtype, covers) self.name = name self.deleting = deleting def _clone(self): - obj = super(RRset, self)._clone() + obj = super()._clone() obj.name = self.name obj.deleting = self.deleting return obj @@ -73,14 +73,14 @@ class RRset(dns.rdataset.Rdataset): return False if self.name != other.name: return False - return super(RRset, self).__eq__(other) + return super().__eq__(other) def match(self, name, rdclass, rdtype, covers, deleting=None): """Returns ``True`` if this rrset matches the specified class, type, covers, and deletion state. """ - if not super(RRset, self).match(rdclass, rdtype, covers): + if not super().match(rdclass, rdtype, covers): return False if self.name != name or self.deleting != deleting: return False @@ -103,8 +103,8 @@ class RRset(dns.rdataset.Rdataset): to *origin*. """ - return super(RRset, self).to_text(self.name, origin, relativize, - self.deleting, **kw) + return super().to_text(self.name, origin, relativize, + self.deleting, **kw) def to_wire(self, file, compress=None, origin=None, **kw): """Convert the RRset to wire format. @@ -115,8 +115,8 @@ class RRset(dns.rdataset.Rdataset): Returns an ``int``, the number of records emitted. """ - return super(RRset, self).to_wire(self.name, file, compress, origin, - self.deleting, **kw) + return super().to_wire(self.name, file, compress, origin, + self.deleting, **kw) def to_rdataset(self): """Convert an RRset into an Rdataset. @@ -23,7 +23,7 @@ if sys.version_info >= (3, 7): else: from collections import OrderedDict as odict -class Set(object): +class Set: """A simple set class. diff --git a/dns/tokenizer.py b/dns/tokenizer.py index a13268d..8e7ac42 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -40,7 +40,7 @@ class UngetBufferFull(dns.exception.DNSException): """An attempt was made to unget a token when the unget buffer was full.""" -class Token(object): +class Token: """A DNS master file format token. ttype: The token type @@ -183,7 +183,7 @@ class Token(object): return Token(self.ttype, bytes(unescaped)) -class Tokenizer(object): +class Tokenizer: """A DNS master file format tokenizer. A token object is basically a (type, value) tuple. The valid diff --git a/dns/trio/query.pyi b/dns/trio/query.pyi index 642c7c0..c51f000 100644 --- a/dns/trio/query.pyi +++ b/dns/trio/query.pyi @@ -9,7 +9,7 @@ from . import rdatatype, rdataclass, name, message try: import ssl except ImportError: - class ssl(object): # type: ignore + class ssl: # type: ignore SSLContext : Dict = {} def udp(q : message.Message, where : str, port=53, diff --git a/dns/update.py b/dns/update.py index d4cddb2..951d895 100644 --- a/dns/update.py +++ b/dns/update.py @@ -53,7 +53,7 @@ class Update(dns.message.Message): *keyalgorithm*, a ``dns.name.Name``, the TSIG algorithm to use. """ - super(Update, self).__init__() + super().__init__() self.flags |= dns.opcode.to_flags(dns.opcode.UPDATE) if isinstance(zone, str): zone = dns.name.from_text(zone) @@ -267,4 +267,4 @@ class Update(dns.message.Message): if origin is None: origin = self.origin - return super(Update, self).to_wire(origin, max_size) + return super().to_wire(origin, max_size) diff --git a/dns/zone.py b/dns/zone.py index 3ca9d28..741d24c 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -56,7 +56,7 @@ class UnknownOrigin(BadZone): """The DNS zone's origin is unknown.""" -class Zone(object): +class Zone: """A DNS zone. @@ -636,7 +636,7 @@ class Zone(object): raise NoNS -class _MasterReader(object): +class _MasterReader: """Read a DNS master file |