]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
The IPv4 and IPv6 inet_ntoa() functions were returning binary
authorBob Halley <halley@dnspython.org>
Mon, 2 Jan 2017 14:41:05 +0000 (06:41 -0800)
committerBob Halley <halley@dnspython.org>
Mon, 2 Jan 2017 14:41:05 +0000 (06:41 -0800)
instead of text, a Py2/Py3 merge bug.

ChangeLog
dns/ipv4.py
dns/ipv6.py
dns/rdtypes/IN/A.py
tests/test_edns.py
tests/test_name.py
tests/test_ntoaaton.py

index 223607d42a21aaac87838870847b5eff764c06e1..e79663873979738f61daeefc2d217d6ba7adc66d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
 2017-01-02  Bob Halley  <halley@dnspython.org>
 
        * dns/e164.py: to_e164() was returning binary instead of text,
-         another Py2/Py3 merge bug.
+         a Py2/Py3 merge bug.
+
+       * The IPv4 and IPv6 inet_ntoa() functions were returning binary
+         instead of text, a Py2/Py3 merge bug.
 
 2017-01-01  Bob Halley  <halley@dnspython.org>
 
index 3fef282b66faba6e40eac26fe91c386c77578e72..b9ce00d410bbf6460593131465bbc6659688e03b 100644 (file)
@@ -31,8 +31,8 @@ def inet_ntoa(address):
         raise dns.exception.SyntaxError
     if not isinstance(address, bytearray):
         address = bytearray(address)
-    return (u'%u.%u.%u.%u' % (address[0], address[1],
-                              address[2], address[3])).encode()
+    return ('%u.%u.%u.%u' % (address[0], address[1],
+                             address[2], address[3]))
 
 def inet_aton(text):
     """Convert an IPv4 address in text form to network form.
index cbaee8edc34a2ce2dc7144f6872bcd732b78c8de..9ced9bf7a02f463103549e17dbf6aa086d945bc5 100644 (file)
@@ -22,7 +22,7 @@ import dns.exception
 import dns.ipv4
 from ._compat import xrange, binary_type, maybe_decode
 
-_leading_zero = re.compile(b'0+([0-9a-f]+)')
+_leading_zero = re.compile('0+([0-9a-f]+)')
 
 def inet_ntoa(address):
     """Convert a network format IPv6 address into text.
@@ -40,7 +40,7 @@ def inet_ntoa(address):
     i = 0
     l = len(hex)
     while i < l:
-        chunk = hex[i : i + 4]
+        chunk = maybe_decode(hex[i : i + 4])
         # strip leading zeros.  we do this with an re instead of
         # with lstrip() because lstrip() didn't support chars until
         # python 2.2.2
@@ -57,7 +57,7 @@ def inet_ntoa(address):
     start = -1
     last_was_zero = False
     for i in xrange(8):
-        if chunks[i] != b'0':
+        if chunks[i] != '0':
             if last_was_zero:
                 end = i
                 current_len = end - start
@@ -77,19 +77,19 @@ def inet_ntoa(address):
     if best_len > 1:
         if best_start == 0 and \
            (best_len == 6 or
-            best_len == 5 and chunks[5] == b'ffff'):
+            best_len == 5 and chunks[5] == 'ffff'):
             # We have an embedded IPv4 address
             if best_len == 6:
-                prefix = b'::'
+                prefix = '::'
             else:
-                prefix = b'::ffff:'
+                prefix = '::ffff:'
             hex = prefix + dns.ipv4.inet_ntoa(address[12:])
         else:
-            hex = b':'.join(chunks[:best_start]) + b'::' + \
-                  b':'.join(chunks[best_start + best_len:])
+            hex = ':'.join(chunks[:best_start]) + '::' + \
+                  ':'.join(chunks[best_start + best_len:])
     else:
-        hex = b':'.join(chunks)
-    return maybe_decode(hex)
+        hex = ':'.join(chunks)
+    return hex
 
 _v4_ending = re.compile(b'(.*):(\d+\.\d+\.\d+\.\d+)$')
 _colon_colon_start = re.compile(b'::.*')
index 3775548f2046d1b62e2efb231b15a67a0aee7100..31f3e7f8a4cf4c086dee9341c78047a652d795f3 100644 (file)
@@ -48,5 +48,5 @@ class A(dns.rdata.Rdata):
 
     @classmethod
     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
-        address = dns.ipv4.inet_ntoa(wire[current: current + rdlen]).decode()
+        address = dns.ipv4.inet_ntoa(wire[current: current + rdlen])
         return cls(rdclass, rdtype, address)
index 69d88e23a2b0e93a0726aa1685784e6c8152d88a..f15a28a333d54f82dd5382532b3163df824c0bfd 100644 (file)
@@ -44,7 +44,7 @@ class OptionTestCase(unittest.TestCase):
         opt = dns.edns.option_from_wire(8, b'\x00\x01\x14\x00\x01\x02\xf0',
                                         0, 7)
         self.assertEqual(opt.otype, dns.edns.ECS)
-        self.assertEqual(opt.address, b'1.2.240.0')
+        self.assertEqual(opt.address, '1.2.240.0')
         self.assertEqual(opt.srclen, 20)
         self.assertEqual(opt.scopelen, 0)
 
index fecbaafe28cd6235d9ff1bab76d61632a4fcd487..cb7dee02e6404239e79c78b293a6497c61afb806 100644 (file)
@@ -764,7 +764,7 @@ class NameTestCase(unittest.TestCase):
 
     def testForwardIPv4(self):
         n = dns.name.from_text('1.0.0.127.in-addr.arpa.')
-        e = b'127.0.0.1'
+        e = '127.0.0.1'
         text = dns.reversename.to_address(n)
         self.assertEqual(text, e)
 
index 05fb95a8df475ece01fae75dc8b78d930b96c1dc..f51592b6e581506e10d71eb6edce7e3db08a9ed3 100644 (file)
@@ -171,9 +171,9 @@ class NtoAAtoNTestCase(unittest.TestCase):
         self.failUnlessRaises(ValueError, bad)
 
     def test_good_v4_aton(self):
-        pairs = [(b'1.2.3.4', b'\x01\x02\x03\x04'),
-                 (b'255.255.255.255', b'\xff\xff\xff\xff'),
-                 (b'0.0.0.0', b'\x00\x00\x00\x00')]
+        pairs = [('1.2.3.4', b'\x01\x02\x03\x04'),
+                 ('255.255.255.255', b'\xff\xff\xff\xff'),
+                 ('0.0.0.0', b'\x00\x00\x00\x00')]
         for (t, b) in pairs:
             b1 = aton4(t)
             t1 = ntoa4(b1)