]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
dns.ipv6.inet_ntoa() should return a string.
authorBob Halley <halley@dnspython.org>
Tue, 31 May 2016 13:46:41 +0000 (06:46 -0700)
committerBob Halley <halley@dnspython.org>
Tue, 31 May 2016 13:46:41 +0000 (06:46 -0700)
[issue #167]

Makefile
dns/_compat.py
dns/ipv6.py
tests/test_name.py
tests/test_ntoaaton.py

index 78360f12f0c4f6b7567309b0c85b4b906305adc0..fdc4792a377370ebfd50a376dbfbdef33873e008 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -58,4 +58,4 @@ tags:
 check: test
 
 test:
-       cd tests; make test
+       cd tests; make PYTHON=${PYTHON} test
index cffe4bb92790e4dda091c9a644c96f018336fe79..60a00836bdc7fec79bab70f039f42a029021d9d8 100644 (file)
@@ -14,8 +14,12 @@ if sys.version_info > (3,):
     binary_type = bytes
     string_types = (str,)
     unichr = chr
+    def maybe_decode(x):
+        return x.decode()
 else:
     text_type = unicode
     binary_type = str
     string_types = (basestring,)
     unichr = unichr
+    def maybe_decode(x):
+        return x
index ee991e85b1ee33edd14d7db2e161641919c57058..cbaee8edc34a2ce2dc7144f6872bcd732b78c8de 100644 (file)
@@ -20,7 +20,7 @@ import binascii
 
 import dns.exception
 import dns.ipv4
-from ._compat import xrange, binary_type
+from ._compat import xrange, binary_type, maybe_decode
 
 _leading_zero = re.compile(b'0+([0-9a-f]+)')
 
@@ -89,7 +89,7 @@ def inet_ntoa(address):
                   b':'.join(chunks[best_start + best_len:])
     else:
         hex = b':'.join(chunks)
-    return hex
+    return maybe_decode(hex)
 
 _v4_ending = re.compile(b'(.*):(\d+\.\d+\.\d+\.\d+)$')
 _colon_colon_start = re.compile(b'::.*')
index f8e3d23af502ac53dfa1e2afbeb61ff0b775be63..a166a3e860a02a1ec41f5f7198b9bb4bd3ef256f 100644 (file)
@@ -682,7 +682,7 @@ class NameTestCase(unittest.TestCase):
 
     def testForwardIPv6(self):
         n = dns.name.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.')
-        e = b'::1'
+        e = '::1'
         text = dns.reversename.to_address(n)
         self.assertEqual(text, e)
 
index 11c8fdad25ee850a6739fb56cb25fb83278de4e0..24fe3453434f5da2a0d98bae084e0372522f127a 100644 (file)
@@ -90,72 +90,72 @@ class NtoAAtoNTestCase(unittest.TestCase):
     def test_ntoa1(self):
         b = binascii.unhexlify(b'00010002000300040005000600070008')
         t = ntoa6(b)
-        self.assertEqual(t, b'1:2:3:4:5:6:7:8')
+        self.assertEqual(t, '1:2:3:4:5:6:7:8')
 
     def test_ntoa2(self):
         b = b'\x00' * 16
         t = ntoa6(b)
-        self.assertEqual(t, b'::')
+        self.assertEqual(t, '::')
 
     def test_ntoa3(self):
         b = b'\x00' * 15 + b'\x01'
         t = ntoa6(b)
-        self.assertEqual(t, b'::1')
+        self.assertEqual(t, '::1')
 
     def test_ntoa4(self):
         b = b'\x80' + b'\x00' * 15
         t = ntoa6(b)
-        self.assertEqual(t, b'8000::')
+        self.assertEqual(t, '8000::')
 
     def test_ntoa5(self):
         b = b'\x01\xcd' + b'\x00' * 12 + b'\x03\xef'
         t = ntoa6(b)
-        self.assertEqual(t, b'1cd::3ef')
+        self.assertEqual(t, '1cd::3ef')
 
     def test_ntoa6(self):
         b = binascii.unhexlify(b'ffff00000000ffff000000000000ffff')
         t = ntoa6(b)
-        self.assertEqual(t, b'ffff:0:0:ffff::ffff')
+        self.assertEqual(t, 'ffff:0:0:ffff::ffff')
 
     def test_ntoa7(self):
         b = binascii.unhexlify(b'00000000ffff000000000000ffffffff')
         t = ntoa6(b)
-        self.assertEqual(t, b'0:0:ffff::ffff:ffff')
+        self.assertEqual(t, '0:0:ffff::ffff:ffff')
 
     def test_ntoa8(self):
         b = binascii.unhexlify(b'ffff0000ffff00000000ffff00000000')
         t = ntoa6(b)
-        self.assertEqual(t, b'ffff:0:ffff::ffff:0:0')
+        self.assertEqual(t, 'ffff:0:ffff::ffff:0:0')
 
     def test_ntoa9(self):
         b = binascii.unhexlify(b'0000000000000000000000000a000001')
         t = ntoa6(b)
-        self.assertEqual(t, b'::10.0.0.1')
+        self.assertEqual(t, '::10.0.0.1')
 
     def test_ntoa10(self):
         b = binascii.unhexlify(b'0000000000000000000000010a000001')
         t = ntoa6(b)
-        self.assertEqual(t, b'::1:a00:1')
+        self.assertEqual(t, '::1:a00:1')
 
     def test_ntoa11(self):
         b = binascii.unhexlify(b'00000000000000000000ffff0a000001')
         t = ntoa6(b)
-        self.assertEqual(t, b'::ffff:10.0.0.1')
+        self.assertEqual(t, '::ffff:10.0.0.1')
 
     def test_ntoa12(self):
         b = binascii.unhexlify(b'000000000000000000000000ffffffff')
         t = ntoa6(b)
-        self.assertEqual(t, b'::255.255.255.255')
+        self.assertEqual(t, '::255.255.255.255')
 
     def test_ntoa13(self):
         b = binascii.unhexlify(b'00000000000000000000ffffffffffff')
         t = ntoa6(b)
-        self.assertEqual(t, b'::ffff:255.255.255.255')
+        self.assertEqual(t, '::ffff:255.255.255.255')
 
     def test_ntoa14(self):
         b = binascii.unhexlify(b'0000000000000000000000000001ffff')
         t = ntoa6(b)
-        self.assertEqual(t, b'::0.1.255.255')
+        self.assertEqual(t, '::0.1.255.255')
 
     def test_bad_ntoa1(self):
         def bad():
@@ -199,7 +199,7 @@ class NtoAAtoNTestCase(unittest.TestCase):
             self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr))
 
     def test_rfc5952_section_4_2_2(self):
-        addr = b'2001:db8:0:1:1:1:1:1'
+        addr = '2001:db8:0:1:1:1:1:1'
         b1 = aton6(addr)
         t1 = ntoa6(b1)
         self.assertEqual(t1, addr)