diff options
author | Bob Halley <halley@dnspython.org> | 2020-06-13 11:25:42 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2020-06-13 11:25:42 -0700 |
commit | dfff63e1d4cefc8af15abe37e9b8cce39951ac72 (patch) | |
tree | 0a27492864b842bb84b03125d6feb2126a7fb55c /dns/inet.py | |
parent | dce23a614f2d11bd802c7f9aed8f3ab0e883f468 (diff) | |
download | dnspython-dfff63e1d4cefc8af15abe37e9b8cce39951ac72.tar.gz |
move low_level_address_tuple() to dns.inet; add some no-coverage comments
Diffstat (limited to 'dns/inet.py')
-rw-r--r-- | dns/inet.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/dns/inet.py b/dns/inet.py index f5b1fcb..7960e9f 100644 --- a/dns/inet.py +++ b/dns/inet.py @@ -139,3 +139,19 @@ def is_address(text): return True except Exception: return False + + +def low_level_address_tuple(af, high_tuple): + """Given an address family and a "high-level" address tuple, i.e. + an (address, port) return the appropriate "low-level" address tuple + suitable for use in socket calls. + """ + address, port = high_tuple + if af == dns.inet.AF_INET: + return (address, port) + elif af == dns.inet.AF_INET6: + ai_flags = socket.AI_NUMERICHOST + ((*_, tup), *_) = socket.getaddrinfo(address, port, flags=ai_flags) + return tup + else: + raise NotImplementedError(f'unknown address family {af}') |