]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Use the proper URL syntax for IPv6 address literals.
authorBob Halley <halley@dnspython.org>
Tue, 16 Jun 2020 14:57:21 +0000 (07:57 -0700)
committerBob Halley <halley@dnspython.org>
Tue, 16 Jun 2020 14:57:21 +0000 (07:57 -0700)
dns/query.py

index 6d9a10bef69e8e968a06975b5301c999670cc9b7..17f1bae8b85615a1699fc62405ee8b613a469e6d 100644 (file)
@@ -302,17 +302,17 @@ def https(q, where, timeout=None, port=443, source=None, source_port=0,
     headers = {
         "accept": "application/dns-message"
     }
-    try:
-        _ = ipaddress.ip_address(where)
+    if af == dns.inet.AF_INET:
         url = 'https://{}:{}{}'.format(where, port, path)
-    except ValueError:
-        if bootstrap_address is not None:
-            split_url = urllib.parse.urlsplit(where)
-            headers['Host'] = split_url.hostname
-            url = where.replace(split_url.hostname, bootstrap_address)
-            transport_adapter = HostHeaderSSLAdapter()
-        else:
-            url = where
+    elif af == dns.inet.AF_INET6:
+        url = 'https://[{}]:{}{}'.format(where, port, path)
+    elif bootstrap_address is not None:
+        split_url = urllib.parse.urlsplit(where)
+        headers['Host'] = split_url.hostname
+        url = where.replace(split_url.hostname, bootstrap_address)
+        transport_adapter = HostHeaderSSLAdapter()
+    else:
+        url = where
     if source is not None:
         # set source port and source address
         transport_adapter = SourceAddressAdapter(source)