]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
The dns.inet.AF_* portability scheme is no longer needed.
authorBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 02:37:01 +0000 (19:37 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 02:37:01 +0000 (19:37 -0700)
dns/edns.py
dns/inet.py
dns/query.py
tests/test_ntoaaton.py
tests/test_query.py

index d3df6f94d8f6108cb8e7b58f8e8da46f0be64c7e..7d7813788ed1b2406821660a4fe1367a37bbd042 100644 (file)
@@ -18,6 +18,7 @@
 """EDNS Options"""
 
 import math
+import socket
 import struct
 
 import dns.enum
@@ -186,11 +187,11 @@ class ECSOption(Option):
         super().__init__(OptionType.ECS)
         af = dns.inet.af_for_address(address)
 
-        if af == dns.inet.AF_INET6:
+        if af == socket.AF_INET6:
             self.family = 2
             if srclen is None:
                 srclen = 56
-        elif af == dns.inet.AF_INET:
+        elif af == socket.AF_INET:
             self.family = 1
             if srclen is None:
                 srclen = 24
index 048a80c23c355156ef1e59fa5e54a265a4286b32..25d99c2cd43de3c28e6a0a5aa43982618b77c959 100644 (file)
@@ -22,18 +22,12 @@ import socket
 import dns.ipv4
 import dns.ipv6
 
-# We assume that AF_INET is always defined.
 
+# We assume that AF_INET and AF_INET6 are always defined.  We keep
+# these here for the benefit of any old code (unlikely though that
+# is!).
 AF_INET = socket.AF_INET
-
-# AF_INET6 might not be defined in the socket module, but we need it.
-# We'll try to use the socket module's value, and if it doesn't work,
-# we'll use our own value.
-
-try:
-    AF_INET6 = socket.AF_INET6
-except AttributeError:
-    AF_INET6 = 9999    # type: ignore
+AF_INET6 = socket.AF_INET6
 
 
 def inet_pton(family, text):
index 3c4bba09e7c764f6a43e4e1d8fe15a582edffb27..05796f87c323658b2d580779ad2db784b31b222b 100644 (file)
@@ -228,9 +228,9 @@ def _destination_and_source(where, port, source, source_port,
         # Caller has specified a source_port but not an address, so we
         # need to return a source, and we need to use the appropriate
         # wildcard address as the address.
-        if af == dns.inet.AF_INET:
+        if af == socket.AF_INET:
             source = '0.0.0.0'
-        elif af == dns.inet.AF_INET6:
+        elif af == socket.AF_INET6:
             source = '::'
         else:
             raise ValueError('source_port specified but address family is '
@@ -316,9 +316,9 @@ def https(q, where, timeout=None, port=443, source=None, source_port=0,
     }
     try:
         where_af = dns.inet.af_for_address(where)
-        if where_af == dns.inet.AF_INET:
+        if where_af == socket.AF_INET:
             url = 'https://{}:{}{}'.format(where, port, path)
-        elif where_af == dns.inet.AF_INET6:
+        elif where_af == socket.AF_INET6:
             url = 'https://[{}]:{}{}'.format(where, port, path)
     except ValueError:
         if bootstrap_address is not None:
index b5d425f996b321e0f03708145a3c766b757dfc9c..4a5818e67f749a18c23825ebf8876f757d7fc1dc 100644 (file)
@@ -261,8 +261,8 @@ class NtoAAtoNTestCase(unittest.TestCase):
         self.assertRaises(dns.exception.SyntaxError, bad)
 
     def test_ptontop(self):
-        for (af, a) in [(dns.inet.AF_INET, '1.2.3.4'),
-                        (dns.inet.AF_INET6, '2001:db8:0:1:1:1:1:1')]:
+        for (af, a) in [(socket.AF_INET, '1.2.3.4'),
+                        (socket.AF_INET6, '2001:db8:0:1:1:1:1:1')]:
             self.assertEqual(dns.inet.inet_ntop(af, dns.inet.inet_pton(af, a)),
                              a)
 
index 8016c8b3939c8fa59a0f36520553e8d86a2167b4..ab2e5e6258588cccdc9489834d79479a26ad4bd1 100644 (file)
@@ -197,16 +197,16 @@ class DestinationAndSourceTests(unittest.TestCase):
 
     def test_af_inferred_from_where(self):
         (af, d, s) = _d_and_s('1.2.3.4', 53, None, 0)
-        self.assertEqual(af, dns.inet.AF_INET)
+        self.assertEqual(af, socket.AF_INET)
 
     def test_af_inferred_from_where(self):
         (af, d, s) = _d_and_s('1::2', 53, None, 0)
-        self.assertEqual(af, dns.inet.AF_INET6)
+        self.assertEqual(af, socket.AF_INET6)
 
     def test_af_inferred_from_source(self):
         (af, d, s) = _d_and_s('https://example/dns-query', 443,
                               '1.2.3.4', 0, False)
-        self.assertEqual(af, dns.inet.AF_INET)
+        self.assertEqual(af, socket.AF_INET)
 
     def test_af_mismatch(self):
         def bad():