instead of text, a Py2/Py3 merge bug.
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>
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.
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.
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
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
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'::.*')
@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)
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)
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)
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)