From: darkdragon-001 Date: Thu, 1 Jan 2026 21:16:41 +0000 (+0100) Subject: Various small improvements (#1248) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=864308a3df742776777a8f02407e48fa852963b0;p=thirdparty%2Fdnspython.git Various small improvements (#1248) * Use name parameter This increases clarity and is less error-prone. * Improve optional error ignore * Prefix private classes with underscore to avoid confusion The public interface is the base class in dns._asyncbackend. * Inherit from asyncio.DatagramProtocol --- diff --git a/dns/_asyncio_backend.py b/dns/_asyncio_backend.py index cc683985..e0c367ed 100644 --- a/dns/_asyncio_backend.py +++ b/dns/_asyncio_backend.py @@ -21,7 +21,7 @@ def _get_running_loop(): return asyncio.get_event_loop() -class _DatagramProtocol: +class _DatagramProtocol(asyncio.DatagramProtocol): def __init__(self): self.transport = None self.recvfrom = None @@ -63,7 +63,7 @@ async def _maybe_wait_for(awaitable, timeout): return await awaitable -class DatagramSocket(dns._asyncbackend.DatagramSocket): +class _DatagramSocket(dns._asyncbackend.DatagramSocket): def __init__(self, family, transport, protocol): super().__init__(family, socket.SOCK_DGRAM) self.transport = transport @@ -98,7 +98,7 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): raise NotImplementedError -class StreamSocket(dns._asyncbackend.StreamSocket): +class _StreamSocket(dns._asyncbackend.StreamSocket): def __init__(self, af, reader, writer): super().__init__(af, socket.SOCK_STREAM) self.reader = reader @@ -235,12 +235,12 @@ class Backend(dns._asyncbackend.Backend): source = (dns.inet.any_for_af(af), 0) transport, protocol = await loop.create_datagram_endpoint( _DatagramProtocol, # type: ignore - source, + local_addr=source, family=af, proto=proto, remote_addr=destination, ) - return DatagramSocket(af, transport, protocol) + return _DatagramSocket(af, transport, protocol) elif socktype == socket.SOCK_STREAM: if destination is None: # This shouldn't happen, but we check to make code analysis software @@ -258,7 +258,7 @@ class Backend(dns._asyncbackend.Backend): ), timeout, ) - return StreamSocket(af, r, w) + return _StreamSocket(af, r, w) raise NotImplementedError( "unsupported socket " + f"type {socktype}" ) # pragma: no cover diff --git a/dns/asyncquery.py b/dns/asyncquery.py index 7ec7ed82..426381a8 100644 --- a/dns/asyncquery.py +++ b/dns/asyncquery.py @@ -158,6 +158,7 @@ async def receive_udp( one_rr_per_rrset=one_rr_per_rrset, ignore_trailing=ignore_trailing, raise_on_truncation=raise_on_truncation, + continue_on_error=ignore_errors, ) except dns.message.Truncated as e: # See the comment in query.py for details. @@ -359,6 +360,7 @@ async def receive_tcp( keyring: dict[dns.name.Name, dns.tsig.Key] | None = None, request_mac: bytes | None = b"", ignore_trailing: bool = False, + ignore_errors: bool = False, ) -> tuple[dns.message.Message, float]: """Read a DNS message from a TCP socket. @@ -378,6 +380,7 @@ async def receive_tcp( request_mac=request_mac, one_rr_per_rrset=one_rr_per_rrset, ignore_trailing=ignore_trailing, + continue_on_error=ignore_errors, ) return (r, received_time)