summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-06-12 06:40:40 -0700
committerBob Halley <halley@dnspython.org>2020-06-12 06:40:40 -0700
commitdbf4731303b9d49fd34c2da3968a40e9f8d5921d (patch)
tree2d1bf4efe028d800f79a7b855f4578290983965a
parentce923bf7f14533596d775ce580ce7ddb15f12bf9 (diff)
downloaddnspython-dbf4731303b9d49fd34c2da3968a40e9f8d5921d.tar.gz
lint
-rw-r--r--dns/_asyncbackend.py1
-rw-r--r--dns/asyncbackend.py4
-rw-r--r--dns/asyncquery.py18
-rw-r--r--dns/asyncresolver.py12
4 files changed, 18 insertions, 17 deletions
diff --git a/dns/_asyncbackend.py b/dns/_asyncbackend.py
index 9bfdaba..0dbcd74 100644
--- a/dns/_asyncbackend.py
+++ b/dns/_asyncbackend.py
@@ -1,5 +1,6 @@
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+import socket
import dns.inet
diff --git a/dns/asyncbackend.py b/dns/asyncbackend.py
index 069eaf0..23256fe 100644
--- a/dns/asyncbackend.py
+++ b/dns/asyncbackend.py
@@ -2,7 +2,7 @@
from dns._asyncbackend import Socket, DatagramSocket, \
- StreamSocket, Backend, low_level_address_tuple
+ StreamSocket, Backend, low_level_address_tuple # noqa:
_default_backend = None
@@ -81,5 +81,3 @@ def set_default_backend(name):
global _default_backend
_default_backend = get_backend(name)
return _default_backend
-
-
diff --git a/dns/asyncquery.py b/dns/asyncquery.py
index ed51fdc..3e37727 100644
--- a/dns/asyncquery.py
+++ b/dns/asyncquery.py
@@ -17,12 +17,9 @@
"""Talk to a DNS server."""
-import os
import socket
import struct
import time
-import base64
-import ipaddress
import dns.asyncbackend
import dns.exception
@@ -33,8 +30,8 @@ import dns.rcode
import dns.rdataclass
import dns.rdatatype
-from dns.query import _addresses_equal, _destination_and_source, \
- _compute_times, UnexpectedSource
+from dns.query import _addresses_equal, _compute_times, UnexpectedSource, \
+ BadResponse
# for brevity
@@ -220,7 +217,7 @@ async def udp(q, where, timeout=None, port=53, source=None, source_port=0,
async def udp_with_fallback(q, where, timeout=None, port=53, source=None,
source_port=0, ignore_unexpected=False,
one_rr_per_rrset=False, ignore_trailing=False,
- udp_sock=None, tcp_sock=None):
+ udp_sock=None, tcp_sock=None, backend=None):
"""Return the response to the query, trying UDP first and falling back
to TCP if UDP results in a truncated response.
@@ -259,21 +256,24 @@ async def udp_with_fallback(q, where, timeout=None, port=53, source=None,
socket is created. Note that if a socket is provided *where*,
*source* and *source_port* are ignored for the TCP query.
+ *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``,
+ the default, then dnspython will use the default backend.
+
Returns a (``dns.message.Message``, tcp) tuple where tcp is ``True``
if and only if TCP was used.
"""
try:
response = await udp(q, where, timeout, port, source, source_port,
ignore_unexpected, one_rr_per_rrset,
- ignore_trailing, True, udp_sock)
+ ignore_trailing, True, udp_sock, backend)
return (response, False)
except dns.message.Truncated:
response = await tcp(q, where, timeout, port, source, source_port,
- one_rr_per_rrset, ignore_trailing, tcp_sock)
+ one_rr_per_rrset, ignore_trailing, tcp_sock,
+ backend)
return (response, True)
-
async def send_tcp(sock, what, expiration=None):
"""Send a DNS message to the specified TCP socket.
diff --git a/dns/asyncresolver.py b/dns/asyncresolver.py
index b45a35b..bee8cdd 100644
--- a/dns/asyncresolver.py
+++ b/dns/asyncresolver.py
@@ -106,7 +106,6 @@ class Resolver(dns.resolver.Resolver):
if answer is not None:
# cache hit!
return answer
- loops = 1
done = False
while not done:
(nameserver, port, tcp, backoff) = resolution.next_nameserver()
@@ -189,7 +188,7 @@ def reset_default_resolver():
async def resolve(qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
tcp=False, source=None, raise_on_no_answer=True,
- source_port=0, search=None):
+ source_port=0, search=None, backend=None):
"""Query nameservers asynchronously to find the answer to the question.
This is a convenience function that uses the default resolver
@@ -201,7 +200,7 @@ async def resolve(qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
return await get_default_resolver().resolve(qname, rdtype, rdclass, tcp,
source, raise_on_no_answer,
- source_port, search)
+ source_port, search, backend)
async def resolve_address(ipaddr, *args, **kwargs):
@@ -215,7 +214,7 @@ async def resolve_address(ipaddr, *args, **kwargs):
async def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False,
- resolver=None):
+ resolver=None, backend=None):
"""Find the name of the zone which contains the specified name.
*name*, an absolute ``dns.name.Name`` or ``str``, the query name.
@@ -227,6 +226,9 @@ async def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False,
*resolver*, a ``dns.asyncresolver.Resolver`` or ``None``, the
resolver to use. If ``None``, the default resolver is used.
+ *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``,
+ the default, then dnspython will use the default backend.
+
Raises ``dns.resolver.NoRootSOA`` if there is no SOA RR at the DNS
root. (This is only likely to happen if you're using non-default
root servers in your network and they are misconfigured.)
@@ -243,7 +245,7 @@ async def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False,
while True:
try:
answer = await resolver.resolve(name, dns.rdatatype.SOA, rdclass,
- tcp)
+ tcp, backend=backend)
if answer.rrset.name == name:
return name
# otherwise we were CNAMEd or DNAMEd and need to look higher