]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
lint
authorBob Halley <halley@dnspython.org>
Fri, 12 Jun 2020 13:40:40 +0000 (06:40 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 12 Jun 2020 13:40:40 +0000 (06:40 -0700)
dns/_asyncbackend.py
dns/asyncbackend.py
dns/asyncquery.py
dns/asyncresolver.py

index 9bfdaba84ffabd94cbb41c77bcaf3b37b8c23a08..0dbcd742ecb6f708b712cb11a16379b4edeb8666 100644 (file)
@@ -1,5 +1,6 @@
 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
 
+import socket
 
 import dns.inet
 
index 069eaf07e1f62876cb58cd96ffe335bcea7daf13..23256fedd76693a7ecfec7905e8787766ed19a38 100644 (file)
@@ -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
-
-
index ed51fdcccf00bc702b87126b206144613c8e66f1..3e377278364c64903e069019b979e5b5e580f937 100644 (file)
 
 """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.
 
index b45a35b5af59da62808efb62b1b62c2e1454a7b5..bee8cdd3cf7a49616d3cbccf049b1eef46dd5c15 100644 (file)
@@ -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