From 1e0c9a41844b4378c79fc81e83f003a11f8637d6 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sat, 5 Jan 2019 10:07:02 -0800 Subject: [PATCH] remove bytearray() wrapping used for python 2 compatibility --- dns/dnssec.py | 1 - dns/ipv4.py | 2 -- dns/ipv6.py | 2 +- dns/name.py | 8 ++++---- dns/rdata.py | 2 +- dns/reversename.py | 2 +- dns/wiredata.py | 2 +- tests/test_nsec3.py | 4 ++-- tests/test_wiredata.py | 4 ++-- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/dns/dnssec.py b/dns/dnssec.py index d5bd3fe7..62ca5a15 100644 --- a/dns/dnssec.py +++ b/dns/dnssec.py @@ -130,7 +130,6 @@ def key_id(key, origin=None): """ rdata = _to_rdata(key, origin) - rdata = bytearray(rdata) if key.algorithm == RSAMD5: return (rdata[-3] << 8) + rdata[-2] else: diff --git a/dns/ipv4.py b/dns/ipv4.py index c35775b4..ca6386d4 100644 --- a/dns/ipv4.py +++ b/dns/ipv4.py @@ -31,8 +31,6 @@ def inet_ntoa(address): if len(address) != 4: raise dns.exception.SyntaxError - if not isinstance(address, bytearray): - address = bytearray(address) return ('%u.%u.%u.%u' % (address[0], address[1], address[2], address[3])) diff --git a/dns/ipv6.py b/dns/ipv6.py index e501a41a..1f703a67 100644 --- a/dns/ipv6.py +++ b/dns/ipv6.py @@ -117,7 +117,7 @@ def inet_aton(text): # m = _v4_ending.match(text) if not m is None: - b = bytearray(dns.ipv4.inet_aton(m.group(2))) + b = dns.ipv4.inet_aton(m.group(2)) text = (u"{}:{:02x}{:02x}:{:02x}{:02x}".format(m.group(1).decode(), b[0], b[1], b[2], b[3])).encode() diff --git a/dns/name.py b/dns/name.py index 10167435..84968c16 100644 --- a/dns/name.py +++ b/dns/name.py @@ -227,7 +227,7 @@ class IDNA2008Codec(IDNACodec): except idna.IDNAError as e: raise IDNAException(idna_exception=e) -_escaped = bytearray(b'"().;\\@$') +_escaped = b'"().;\\@$' IDNA_2003_Practical = IDNA2003Codec(False) IDNA_2003_Strict = IDNA2003Codec(True) @@ -248,7 +248,7 @@ def _escapify(label, unicode_mode=False): text = '' if isinstance(label, str): label = label.encode() - for c in bytearray(label): + for c in label: if c in _escaped: text += '\\' + chr(c) elif c > 0x20 and c < 0x7F: @@ -374,7 +374,7 @@ class Name(object): h = 0 for label in self.labels: - for c in bytearray(label.lower()): + for c in label.lower(): h += (h << 3) + c return h % maxint @@ -899,7 +899,7 @@ def from_text(text, origin=root, idna_codec=None): if text: if text == b'.': return Name([b'']) - for c in bytearray(text): + for c in text: byte_ = struct.pack('!B', c) if escaping: if edigits == 0: diff --git a/dns/rdata.py b/dns/rdata.py index 01930a4f..93b4a31f 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -59,7 +59,7 @@ def _base64ify(data, chunksize=_base64_chunksize): for i in range(0, len(line), chunksize)]).decode() -__escaped = bytearray(b'"\\') +__escaped = b'"\\' def _escapify(qstring): """Escape the characters in a quoted string which need it.""" diff --git a/dns/reversename.py b/dns/reversename.py index 60618cc9..0e10bec0 100644 --- a/dns/reversename.py +++ b/dns/reversename.py @@ -49,7 +49,7 @@ def from_address(text): origin = ipv6_reverse_domain except Exception: parts = ['%d' % - byte for byte in bytearray(dns.ipv4.inet_aton(text))] + byte for byte in dns.ipv4.inet_aton(text)] origin = ipv4_reverse_domain parts.reverse() return dns.name.from_text('.'.join(parts), origin=origin) diff --git a/dns/wiredata.py b/dns/wiredata.py index 85412691..14f36fc1 100644 --- a/dns/wiredata.py +++ b/dns/wiredata.py @@ -54,7 +54,7 @@ class WireData(bytes): return WireData(super(WireData, self).__getitem__( slice(start, stop))) - return bytearray(self.unwrap())[key] + return self.unwrap()[key] except IndexError: raise dns.exception.FormError diff --git a/tests/test_nsec3.py b/tests/test_nsec3.py index 019dc48b..c07d3aca 100644 --- a/tests/test_nsec3.py +++ b/tests/test_nsec3.py @@ -29,8 +29,8 @@ class NSEC3TestCase(unittest.TestCase): u"1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715 A CAA TYPE65534") bitmap = bytearray(b'\0' * 32) bitmap[31] = bitmap[31] | 2 - self.assertEqual(rdata.windows, [(0, bytearray(b'@')), - (1, bytearray(b'@')), # CAA = 257 + self.assertEqual(rdata.windows, [(0, b'@'), + (1, b'@'), # CAA = 257 (255, bitmap) ]) diff --git a/tests/test_wiredata.py b/tests/test_wiredata.py index 9644de47..7b59c3cd 100644 --- a/tests/test_wiredata.py +++ b/tests/test_wiredata.py @@ -59,10 +59,10 @@ class WireDataSlicingTestCase(unittest.TestCase): """Get data one by one item""" data = b'0123456789' inst = WireData(data) - for i, byte in enumerate(bytearray(data)): + for i, byte in enumerate(data): self.assertEqual(inst[i], byte) for i in range(-1, len(data) * -1, -1): - self.assertEqual(inst[i], bytearray(data)[i]) + self.assertEqual(inst[i], data[i]) def testEmptySlice(self): """Test empty slice""" -- 2.47.3