diff options
author | Bob Halley <halley@dnspython.org> | 2020-07-31 16:03:09 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2020-07-31 16:03:09 -0700 |
commit | 049eedd8ab25f211d0fcd88726098327cc27ddb2 (patch) | |
tree | 0b79e3da4f29d4d85a4eddac0e2879925c49dc7b /dns | |
parent | 96429bc53f2912fc8065439c7adac83a87ef806b (diff) | |
download | dnspython-049eedd8ab25f211d0fcd88726098327cc27ddb2.tar.gz |
pylint linting
Diffstat (limited to 'dns')
-rw-r--r-- | dns/_asyncio_backend.py | 4 | ||||
-rw-r--r-- | dns/_curio_backend.py | 2 | ||||
-rw-r--r-- | dns/_trio_backend.py | 2 | ||||
-rw-r--r-- | dns/asyncbackend.py | 5 | ||||
-rw-r--r-- | dns/asyncresolver.py | 8 | ||||
-rw-r--r-- | dns/dnssec.py | 2 | ||||
-rw-r--r-- | dns/ipv6.py | 2 | ||||
-rw-r--r-- | dns/message.py | 10 | ||||
-rw-r--r-- | dns/name.py | 4 | ||||
-rw-r--r-- | dns/query.py | 34 | ||||
-rw-r--r-- | dns/rdataset.py | 2 | ||||
-rw-r--r-- | dns/rdtypes/CH/A.py | 3 | ||||
-rw-r--r-- | dns/resolver.py | 35 | ||||
-rw-r--r-- | dns/rrset.py | 20 | ||||
-rw-r--r-- | dns/zone.py | 6 |
15 files changed, 91 insertions, 48 deletions
diff --git a/dns/_asyncio_backend.py b/dns/_asyncio_backend.py index 3af34ff..1cf1519 100644 --- a/dns/_asyncio_backend.py +++ b/dns/_asyncio_backend.py @@ -86,14 +86,12 @@ class StreamSocket(dns._asyncbackend.DatagramSocket): self.writer = writer async def sendall(self, what, timeout): - self.writer.write(what), + self.writer.write(what) return await _maybe_wait_for(self.writer.drain(), timeout) - raise dns.exception.Timeout(timeout=timeout) async def recv(self, count, timeout): return await _maybe_wait_for(self.reader.read(count), timeout) - raise dns.exception.Timeout(timeout=timeout) async def close(self): self.writer.close() diff --git a/dns/_curio_backend.py b/dns/_curio_backend.py index 300e1b8..894e87c 100644 --- a/dns/_curio_backend.py +++ b/dns/_curio_backend.py @@ -21,6 +21,8 @@ def _maybe_timeout(timeout): # for brevity _lltuple = dns.inet.low_level_address_tuple +# pylint: disable=redefined-outer-name + class DatagramSocket(dns._asyncbackend.DatagramSocket): def __init__(self, socket): diff --git a/dns/_trio_backend.py b/dns/_trio_backend.py index 92ea879..82512cd 100644 --- a/dns/_trio_backend.py +++ b/dns/_trio_backend.py @@ -21,6 +21,8 @@ def _maybe_timeout(timeout): # for brevity _lltuple = dns.inet.low_level_address_tuple +# pylint: disable=redefined-outer-name + class DatagramSocket(dns._asyncbackend.DatagramSocket): def __init__(self, socket): diff --git a/dns/asyncbackend.py b/dns/asyncbackend.py index 9582a6f..e6a42ce 100644 --- a/dns/asyncbackend.py +++ b/dns/asyncbackend.py @@ -2,9 +2,12 @@ import dns.exception +# pylint: disable=unused-import + from dns._asyncbackend import Socket, DatagramSocket, \ StreamSocket, Backend # noqa: +# pylint: enable=unused-import _default_backend = None @@ -25,6 +28,7 @@ def get_backend(name): Raises NotImplementError if an unknown backend name is specified. """ + # pylint: disable=import-outside-toplevel,redefined-outer-name backend = _backends.get(name) if backend: return backend @@ -50,6 +54,7 @@ def sniff(): Returns the name of the library, or raises AsyncLibraryNotFoundError if the library cannot be determined. """ + # pylint: disable=import-outside-toplevel try: if _no_sniffio: raise ImportError diff --git a/dns/asyncresolver.py b/dns/asyncresolver.py index b0af934..a6582b2 100644 --- a/dns/asyncresolver.py +++ b/dns/asyncresolver.py @@ -36,6 +36,8 @@ _tcp = dns.asyncquery.tcp class Resolver(dns.resolver.Resolver): + # pylint: disable=invalid-overridden-method, arguments-differ + async def resolve(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN, tcp=False, source=None, raise_on_no_answer=True, @@ -139,11 +141,15 @@ class Resolver(dns.resolver.Resolver): if answer is not None: return answer + # pylint: disable=signature-differs + async def query(self, *args, **kwargs): # We have to define something here as we don't want to inherit the # parent's query(). raise NotImplementedError + # pylint: enable=signature-differs + async def resolve_address(self, ipaddr, *args, **kwargs): """Use an asynchronous resolver to run a reverse query for PTR records. @@ -165,6 +171,8 @@ class Resolver(dns.resolver.Resolver): rdclass=dns.rdataclass.IN, *args, **kwargs) + # pylint: disable=redefined-outer-name + async def canonical_name(self, name): """Determine the canonical name of *name*. diff --git a/dns/dnssec.py b/dns/dnssec.py index e36e729..8919996 100644 --- a/dns/dnssec.py +++ b/dns/dnssec.py @@ -551,7 +551,7 @@ def nsec3_hash(domain, salt, iterations, algorithm): domain_encoded = domain.canonicalize().to_wire() digest = hashlib.sha1(domain_encoded + salt_encoded).digest() - for i in range(iterations): + for _ in range(iterations): digest = hashlib.sha1(digest + salt_encoded).digest() output = base64.b32encode(digest).decode("utf-8") diff --git a/dns/ipv6.py b/dns/ipv6.py index 5424fce..0905aaf 100644 --- a/dns/ipv6.py +++ b/dns/ipv6.py @@ -157,7 +157,7 @@ def inet_aton(text, ignore_scope=False): if seen_empty: raise dns.exception.SyntaxError seen_empty = True - for i in range(0, 8 - l + 1): + for _ in range(0, 8 - l + 1): canonical.append(b'0000') else: lc = len(c) diff --git a/dns/message.py b/dns/message.py index 52e3819..1dfb028 100644 --- a/dns/message.py +++ b/dns/message.py @@ -699,9 +699,13 @@ class Message: # What the caller picked is fine. return value + # pylint: disable=unused-argument + def _parse_rr_header(self, section, name, rdclass, rdtype): return (rdclass, rdtype, None, False) + # pylint: enable=unused-argument + def _parse_special_rr_header(self, section, count, position, name, rdclass, rdtype): if rdtype == dns.rdatatype.OPT: @@ -811,6 +815,8 @@ def _maybe_import_update(): # We avoid circular imports by doing this here. We do it in another # function as doing it in _message_factory_from_opcode() makes "dns" # a local symbol, and the first line fails :) + + # pylint: disable=redefined-outer-name,import-outside-toplevel,unused-import import dns.update # noqa: F401 @@ -857,7 +863,7 @@ class _WireReader: """ section = self.message.sections[section_number] - for i in range(qcount): + for _ in range(qcount): qname = self.parser.get_name(self.message.origin) (rdtype, rdclass) = self.parser.get_struct('!HH') (rdclass, rdtype, _, _) = \ @@ -1080,7 +1086,7 @@ class _TextReader: self.opcode = dns.opcode.QUERY self.flags = 0 - def _header_line(self, section): + def _header_line(self, _): """Process one line from the text format header section.""" token = self.tok.get() diff --git a/dns/name.py b/dns/name.py index 94d7b93..8775e0b 100644 --- a/dns/name.py +++ b/dns/name.py @@ -459,7 +459,7 @@ class Name: Returns a ``bool``. """ - (nr, o, nl) = self.fullcompare(other) + (nr, _, _) = self.fullcompare(other) if nr == NAMERELN_SUBDOMAIN or nr == NAMERELN_EQUAL: return True return False @@ -473,7 +473,7 @@ class Name: Returns a ``bool``. """ - (nr, o, nl) = self.fullcompare(other) + (nr, _, _) = self.fullcompare(other) if nr == NAMERELN_SUPERDOMAIN or nr == NAMERELN_EQUAL: return True return False diff --git a/dns/query.py b/dns/query.py index c2f619c..d4a3afa 100644 --- a/dns/query.py +++ b/dns/query.py @@ -95,10 +95,13 @@ def _compute_times(timeout): return (now, now + timeout) -def _wait_for(fd, readable, writable, error, expiration): +def _wait_for(fd, readable, writable, _, expiration): # Use the selected selector class to wait for any of the specified # events. An "expiration" absolute time is converted into a relative # timeout. + # + # The unused parameter is 'error', which is always set when + # selecting for read or write, and we have no error-only selects. if readable and isinstance(fd, ssl.SSLSocket) and fd.pending() > 0: return True @@ -278,27 +281,24 @@ def https(q, where, timeout=None, port=443, source=None, source_port=0, raise NoDOH # pragma: no cover wire = q.to_wire() - (af, destination, source) = _destination_and_source(where, port, - source, source_port, - False) + (af, _, source) = _destination_and_source(where, port, source, source_port, + False) transport_adapter = None headers = { "accept": "application/dns-message" } - try: - where_af = dns.inet.af_for_address(where) - if where_af == socket.AF_INET: + if af is not None: + if af == socket.AF_INET: url = 'https://{}:{}{}'.format(where, port, path) - elif where_af == socket.AF_INET6: + elif af == socket.AF_INET6: url = 'https://[{}]:{}{}'.format(where, port, path) - except ValueError: - if bootstrap_address is not None: - split_url = urllib.parse.urlsplit(where) - headers['Host'] = split_url.hostname - url = where.replace(split_url.hostname, bootstrap_address) - transport_adapter = HostHeaderSSLAdapter() - else: - url = where + elif bootstrap_address is not None: + split_url = urllib.parse.urlsplit(where) + headers['Host'] = split_url.hostname + url = where.replace(split_url.hostname, bootstrap_address) + transport_adapter = HostHeaderSSLAdapter() + else: + url = where if source is not None: # set source port and source address transport_adapter = SourceAddressAdapter(source) @@ -917,7 +917,7 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN, (expiration is not None and mexpiration > expiration): mexpiration = expiration if use_udp: - (wire, from_address) = _udp_recv(s, 65535, expiration) + (wire, _) = _udp_recv(s, 65535, expiration) else: ldata = _net_read(s, 2, mexpiration) (l,) = struct.unpack("!H", ldata) diff --git a/dns/rdataset.py b/dns/rdataset.py index 8e70a08..0e47139 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -87,7 +87,7 @@ class Rdataset(dns.set.Set): elif ttl < self.ttl: self.ttl = ttl - def add(self, rd, ttl=None): + def add(self, rd, ttl=None): # pylint: disable=arguments-differ """Add the specified rdata to the rdataset. If the optional *ttl* parameter is supplied, then diff --git a/dns/rdtypes/CH/A.py b/dns/rdtypes/CH/A.py index 330fcae..0cb89e2 100644 --- a/dns/rdtypes/CH/A.py +++ b/dns/rdtypes/CH/A.py @@ -15,9 +15,10 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import dns.rdtypes.mxbase import struct +import dns.rdtypes.mxbase + class A(dns.rdata.Rdata): """A record for Chaosnet""" diff --git a/dns/resolver.py b/dns/resolver.py index 9600c8e..eba0b44 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -43,6 +43,7 @@ import dns.reversename import dns.tsig if sys.platform == 'win32': + # pylint: disable=import-error import winreg class NXDOMAIN(dns.exception.DNSException): @@ -50,7 +51,10 @@ class NXDOMAIN(dns.exception.DNSException): supp_kwargs = {'qnames', 'responses'} fmt = None # we have our own __str__ implementation - def _check_kwargs(self, qnames, responses=None): + # pylint: disable=arguments-differ + + def _check_kwargs(self, qnames, + responses=None): if not isinstance(qnames, (list, tuple, set)): raise AttributeError("qnames must be a list, tuple or set") if len(qnames) == 0: @@ -161,6 +165,7 @@ class NoNameservers(dns.exception.DNSException): def _fmt_kwargs(self, **kwargs): srv_msgs = [] for err in kwargs['errors']: + # pylint: disable=bad-continuation srv_msgs.append('Server {} {} port {} answered {}'.format(err[0], 'TCP' if err[1] else 'UDP', err[2], err[3])) return super()._fmt_kwargs(query=kwargs['request'].question, @@ -854,34 +859,36 @@ class Resolver: self.search.append(dns.name.from_text(s)) def _config_win32_fromkey(self, key, always_try_domain): + # pylint: disable=undefined-variable + # (disabled for WindowsError) try: - servers, rtype = winreg.QueryValueEx(key, 'NameServer') - except WindowsError: # pylint: disable=undefined-variable + servers, _ = winreg.QueryValueEx(key, 'NameServer') + except WindowsError: # pragma: no cover servers = None if servers: self._config_win32_nameservers(servers) if servers or always_try_domain: try: - dom, rtype = winreg.QueryValueEx(key, 'Domain') + dom, _ = winreg.QueryValueEx(key, 'Domain') if dom: self._config_win32_domain(dom) # pragma: no cover except WindowsError: # pragma: no cover pass else: try: - servers, rtype = winreg.QueryValueEx(key, 'DhcpNameServer') + servers, _ = winreg.QueryValueEx(key, 'DhcpNameServer') except WindowsError: # pragma: no cover servers = None if servers: self._config_win32_nameservers(servers) try: - dom, rtype = winreg.QueryValueEx(key, 'DhcpDomain') + dom, _ = winreg.QueryValueEx(key, 'DhcpDomain') if dom: self._config_win32_domain(dom) except WindowsError: # pragma: no cover pass try: - search, rtype = winreg.QueryValueEx(key, 'SearchList') + search, _ = winreg.QueryValueEx(key, 'SearchList') except WindowsError: # pragma: no cover search = None if search: # pragma: no cover @@ -909,6 +916,7 @@ class Resolver: try: guid = winreg.EnumKey(interfaces, i) i += 1 + # XXXRTH why do we get this key and then not use it? key = winreg.OpenKey(interfaces, guid) if not self._win32_is_nic_enabled(lm, guid, key): continue @@ -923,8 +931,7 @@ class Resolver: finally: lm.Close() - def _win32_is_nic_enabled(self, lm, guid, - interface_key): + def _win32_is_nic_enabled(self, lm, guid, _): # Look in the Windows Registry to determine whether the network # interface corresponding to the given guid is enabled. # @@ -1027,7 +1034,7 @@ class Resolver: def resolve(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN, tcp=False, source=None, raise_on_no_answer=True, source_port=0, - lifetime=None, search=None): + lifetime=None, search=None): # pylint: disable=arguments-differ """Query nameservers to find the answer to the question. The *qname*, *rdtype*, and *rdclass* parameters may be objects @@ -1165,6 +1172,8 @@ class Resolver: rdclass=dns.rdataclass.IN, *args, **kwargs) + # pylint: disable=redefined-outer-name + def canonical_name(self, name): """Determine the canonical name of *name*. @@ -1186,6 +1195,8 @@ class Resolver: canonical_name = e.canonical_name return canonical_name + # pylint: enable=redefined-outer-name + def use_tsig(self, keyring, keyname=None, algorithm=dns.tsig.default_algorithm): """Add a TSIG signature to each query. @@ -1405,7 +1416,7 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0, raise socket.gaierror(socket.EAI_NONAME, 'Name or service not known') v6addrs = [] v4addrs = [] - canonical_name = None + canonical_name = None # pylint: disable=redefined-outer-name # Is host None or an address literal? If so, use the system's # getaddrinfo(). if host is None: @@ -1571,7 +1582,7 @@ def _gethostbyaddr(ip): 'Name or service not known') sockaddr = (ip, 80) family = socket.AF_INET - (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD) + (name, _) = _getnameinfo(sockaddr, socket.NI_NAMEREQD) aliases = [] addresses = [] tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP, diff --git a/dns/rrset.py b/dns/rrset.py index 68136f4..13737d3 100644 --- a/dns/rrset.py +++ b/dns/rrset.py @@ -69,13 +69,17 @@ class RRset(dns.rdataset.Rdataset): return self.to_text() def __eq__(self, other): - if not isinstance(other, RRset): - return False - if self.name != other.name: + if isinstance(other, RRset): + if self.name != other.name: + return False + elif not isinstance(other, dns.rdataset.Rdataset): return False return super().__eq__(other) - def match(self, name, rdclass, rdtype, covers, deleting=None): + # pylint: disable=arguments-differ + + def match(self, name, rdclass, rdtype, covers, + deleting=None): """Returns ``True`` if this rrset matches the specified class, type, covers, and deletion state. """ @@ -86,7 +90,8 @@ class RRset(dns.rdataset.Rdataset): return False return True - def to_text(self, origin=None, relativize=True, **kw): + def to_text(self, origin=None, relativize=True, + **kw): """Convert the RRset into DNS master file format. See ``dns.name.Name.choose_relativity`` for more information @@ -106,7 +111,8 @@ class RRset(dns.rdataset.Rdataset): return super().to_text(self.name, origin, relativize, self.deleting, **kw) - def to_wire(self, file, compress=None, origin=None, **kw): + def to_wire(self, file, compress=None, origin=None, + **kw): """Convert the RRset to wire format. All keyword arguments are passed to ``dns.rdataset.to_wire()``; see @@ -118,6 +124,8 @@ class RRset(dns.rdataset.Rdataset): return super().to_wire(self.name, file, compress, origin, self.deleting, **kw) + # pylint: enable=arguments-differ + def to_rdataset(self): """Convert an RRset into an Rdataset. diff --git a/dns/zone.py b/dns/zone.py index ad597e9..d5bb305 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -904,8 +904,10 @@ class _MasterReader: # rhs (required) rhs = token.value - lmod, lsign, loffset, lwidth, lbase = self._parse_modify(lhs) - rmod, rsign, roffset, rwidth, rbase = self._parse_modify(rhs) + # The code currently only supports base 'd', so the last value + # in the tuple _parse_modify returns is ignored + lmod, lsign, loffset, lwidth, _ = self._parse_modify(lhs) + rmod, rsign, roffset, rwidth, _ = self._parse_modify(rhs) for i in range(start, stop + 1, step): # +1 because bind is inclusive and python is exclusive |