summaryrefslogtreecommitdiff
path: root/dns/inet.py
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-06-13 11:40:54 -0700
committerBob Halley <halley@dnspython.org>2020-06-13 11:40:54 -0700
commit92b5b2d4a660a509aba0b818cf1889eb6d76c09e (patch)
tree19fa9ad78c521a2e41237a54637cc40c01006690 /dns/inet.py
parentdfff63e1d4cefc8af15abe37e9b8cce39951ac72 (diff)
downloaddnspython-async.tar.gz
Change parameter order of low_level_address_tuple; add test coverage.async
Diffstat (limited to 'dns/inet.py')
-rw-r--r--dns/inet.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/dns/inet.py b/dns/inet.py
index 7960e9f..71782ac 100644
--- a/dns/inet.py
+++ b/dns/inet.py
@@ -141,15 +141,22 @@ def is_address(text):
return False
-def low_level_address_tuple(af, high_tuple):
- """Given an address family and a "high-level" address tuple, i.e.
+def low_level_address_tuple(high_tuple, af=None):
+ """Given a "high-level" address tuple, i.e.
an (address, port) return the appropriate "low-level" address tuple
suitable for use in socket calls.
+
+ If an *af* other than ``None`` is provided, it is assumed the
+ address in the high-level tuple is valid and has that af. If af
+ is ``None``, then af_for_address will be called.
+
"""
address, port = high_tuple
- if af == dns.inet.AF_INET:
+ if af is None:
+ af = af_for_address(address)
+ if af == AF_INET:
return (address, port)
- elif af == dns.inet.AF_INET6:
+ elif af == AF_INET6:
ai_flags = socket.AI_NUMERICHOST
((*_, tup), *_) = socket.getaddrinfo(address, port, flags=ai_flags)
return tup