From: Bob Halley Date: Wed, 17 Jun 2020 21:05:30 +0000 (-0700) Subject: make passing a socket to async routines actually work X-Git-Tag: v2.0.0rc1~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffdd837961fceab98c763fb5fbc63ab157e78e9c;p=thirdparty%2Fdnspython.git make passing a socket to async routines actually work --- diff --git a/dns/_asyncbackend.py b/dns/_asyncbackend.py index d96dce11..c7ecfada 100644 --- a/dns/_asyncbackend.py +++ b/dns/_asyncbackend.py @@ -28,7 +28,7 @@ class Socket: # pragma: no cover pass async def __aenter__(self): - pass + return self async def __aexit__(self, exc_type, exc_value, traceback): await self.close() diff --git a/dns/asyncquery.py b/dns/asyncquery.py index 709c246a..b36a2f64 100644 --- a/dns/asyncquery.py +++ b/dns/asyncquery.py @@ -191,15 +191,15 @@ async def udp(q, where, timeout=None, port=53, source=None, source_port=0, s = None # After 3.6 is no longer supported, this can use an AsyncExitStack. try: + af = dns.inet.af_for_address(where) + destination = _lltuple((where, port), af) if sock: s = sock else: if not backend: backend = dns.asyncbackend.get_default_backend() - af = dns.inet.af_for_address(where) stuple = _source_tuple(af, source, source_port) s = await backend.make_socket(af, socket.SOCK_DGRAM, 0, stuple) - destination = _lltuple((where, port), af) await send_udp(s, wire, destination, expiration) (r, received_time) = await receive_udp(s, destination, expiration, ignore_unexpected,