From: Bob Halley Date: Mon, 2 Jan 2017 14:41:05 +0000 (-0800) Subject: The IPv4 and IPv6 inet_ntoa() functions were returning binary X-Git-Tag: v1.16.0~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d8bdd395d1806d03ea6c8f3ad9f0a7c6b27a0c8;p=thirdparty%2Fdnspython.git The IPv4 and IPv6 inet_ntoa() functions were returning binary instead of text, a Py2/Py3 merge bug. --- diff --git a/ChangeLog b/ChangeLog index 223607d4..e7966387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ 2017-01-02 Bob Halley * 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 diff --git a/dns/ipv4.py b/dns/ipv4.py index 3fef282b..b9ce00d4 100644 --- a/dns/ipv4.py +++ b/dns/ipv4.py @@ -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. diff --git a/dns/ipv6.py b/dns/ipv6.py index cbaee8ed..9ced9bf7 100644 --- a/dns/ipv6.py +++ b/dns/ipv6.py @@ -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'::.*') diff --git a/dns/rdtypes/IN/A.py b/dns/rdtypes/IN/A.py index 3775548f..31f3e7f8 100644 --- a/dns/rdtypes/IN/A.py +++ b/dns/rdtypes/IN/A.py @@ -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) diff --git a/tests/test_edns.py b/tests/test_edns.py index 69d88e23..f15a28a3 100644 --- a/tests/test_edns.py +++ b/tests/test_edns.py @@ -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) diff --git a/tests/test_name.py b/tests/test_name.py index fecbaafe..cb7dee02 100644 --- a/tests/test_name.py +++ b/tests/test_name.py @@ -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) diff --git a/tests/test_ntoaaton.py b/tests/test_ntoaaton.py index 05fb95a8..f51592b6 100644 --- a/tests/test_ntoaaton.py +++ b/tests/test_ntoaaton.py @@ -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)