From efd6171d251021dddbba6bdd59c4c6dbab20cacf Mon Sep 17 00:00:00 2001 From: Arkadiusz Bulski Date: Wed, 24 Aug 2016 21:35:24 +0200 Subject: [PATCH] Removed six from remaining modules, only six.u remains --- construct/formats/data/cap.py | 3 +- construct/formats/data/snoop.py | 5 +- construct/formats/executable/elf32.py | 3 +- construct/formats/executable/pe32.py | 8 +- construct/formats/filesystem/fat16.py | 4 +- construct/formats/filesystem/mbr.py | 6 +- construct/formats/graphics/gif.py | 5 +- construct/protocols/application/dns.py | 8 +- construct/protocols/ipstack.py | 4 +- construct/protocols/layer2/arp.py | 10 +- construct/protocols/layer2/ethernet.py | 6 +- construct/protocols/layer3/dhcpv4.py | 6 +- construct/protocols/layer3/dhcpv6.py | 5 +- construct/protocols/layer3/icmpv4.py | 6 +- construct/protocols/layer3/igmpv2.py | 6 +- construct/protocols/layer3/ipv4.py | 9 +- construct/protocols/layer3/ipv6.py | 4 +- construct/protocols/layer4/tcp.py | 6 +- construct/protocols/layer4/udp.py | 6 +- tests/test_adaptors.py | 27 ++- tests/test_all.py | 272 ++++++++++++------------- tests/test_bit.py | 7 +- tests/test_mapping.py | 14 +- tests/test_overwrite.py | 16 +- tests/test_repeaters.py | 35 ++-- tests/test_sizeof.py | 8 +- tests/test_strings.py | 63 +++--- 27 files changed, 264 insertions(+), 288 deletions(-) diff --git a/construct/formats/data/cap.py b/construct/formats/data/cap.py index f95c5c1c2..1f4facbc1 100644 --- a/construct/formats/data/cap.py +++ b/construct/formats/data/cap.py @@ -1,10 +1,11 @@ """ tcpdump capture file """ -from construct import * import time from datetime import datetime +from construct import * + class MicrosecAdapter(Adapter): def _decode(self, obj, context): diff --git a/construct/formats/data/snoop.py b/construct/formats/data/snoop.py index a5fa799e5..ee8a0cd55 100644 --- a/construct/formats/data/snoop.py +++ b/construct/formats/data/snoop.py @@ -5,8 +5,9 @@ """ import time -from construct import (Adapter, Enum, Field, HexDumpAdapter, Magic, OptionalGreedyRange, - Padding, Struct, UBInt32) + +from construct import Adapter, Enum, Field, HexDumpAdapter, Magic, OptionalGreedyRange, Padding, Struct, UBInt32 + class EpochTimeStampAdapter(Adapter): """ Convert epoch timestamp <-> localtime """ diff --git a/construct/formats/executable/elf32.py b/construct/formats/executable/elf32.py index 246ae3210..4caaea445 100644 --- a/construct/formats/executable/elf32.py +++ b/construct/formats/executable/elf32.py @@ -5,7 +5,6 @@ Big-endian support kindly submitted by Craig McQueen (mcqueen-c#edsrd1!yzk!co!jp) """ from construct import * -import six def elf32_body(ElfInt16, ElfInt32): @@ -124,7 +123,7 @@ def elf32_body(ElfInt16, ElfInt32): elf32_file = Struct("elf32_file", Struct("identifier", - Magic(six.b("\x7fELF")), + Magic(b"\x7fELF"), Enum(Byte("file_class"), NONE = 0, CLASS32 = 1, diff --git a/construct/formats/executable/pe32.py b/construct/formats/executable/pe32.py index ae1d0a8cb..57039bf06 100644 --- a/construct/formats/executable/pe32.py +++ b/construct/formats/executable/pe32.py @@ -8,9 +8,9 @@ 2006 with updates relevant for .NET: http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/pecoff_v8.doc """ -from construct import * import time -import six + +from construct import * class UTCTimeStampAdapter(Adapter): @@ -92,7 +92,7 @@ def _decode(self, obj, context): ) symbol_table = Struct("symbol_table", - String("name", 8, padchar = six.b("\x00")), + String("name", 8, padchar = b"\x00"), ULInt32("value"), Enum(ExprAdapter(SLInt16("section_number"), encoder = lambda obj, ctx: obj + 1, @@ -308,7 +308,7 @@ def PEPlusField(name): ) section = Struct("section", - String("name", 8, padchar = six.b("\x00")), + String("name", 8, padchar = b"\x00"), ULInt32("virtual_size"), ULInt32("virtual_address"), ULInt32("raw_data_size"), diff --git a/construct/formats/filesystem/fat16.py b/construct/formats/filesystem/fat16.py index 0ac157c4a..aed729403 100644 --- a/construct/formats/filesystem/fat16.py +++ b/construct/formats/filesystem/fat16.py @@ -12,8 +12,8 @@ # print rootdir import numbers from io import BytesIO, BufferedReader -from construct import Struct, Byte, Bytes, ULInt16, ULInt32, Enum, \ - Array, Padding, Embed, Pass, BitStruct, Flag, Const + +from construct import Struct, Byte, Bytes, ULInt16, ULInt32, Enum, Array, Padding, Embed, Pass, BitStruct, Flag, Const def Fat16Header(name): diff --git a/construct/formats/filesystem/mbr.py b/construct/formats/filesystem/mbr.py index 1fd5a6240..df30bf85e 100644 --- a/construct/formats/filesystem/mbr.py +++ b/construct/formats/filesystem/mbr.py @@ -4,9 +4,9 @@ http://www.win.tue.nl/~aeb/partitions/partition_types-1.html """ -from construct import * from binascii import unhexlify -import six + +from construct import * mbr = Struct("mbr", @@ -46,7 +46,7 @@ UBInt32("size"), # in sectors ) ), - Const(Bytes("signature", 2), six.b("\x55\xAA")), + Const(Bytes("signature", 2), b"\x55\xAA"), ) diff --git a/construct/formats/graphics/gif.py b/construct/formats/graphics/gif.py index fa5015083..9a1173b0b 100644 --- a/construct/formats/graphics/gif.py +++ b/construct/formats/graphics/gif.py @@ -19,7 +19,6 @@ Comment Extension """ from construct import * -import six data_sub_block = Struct("data_sub_block", @@ -50,8 +49,8 @@ ) gif_header = Struct("gif_header", - Const(String("signature", 3), six.b("GIF")), - Const(String("version", 3), six.b("89a")), + Const(String("signature", 3), b"GIF"), + Const(String("version", 3), b"89a"), ) application_extension = Struct("application_extension", diff --git a/construct/protocols/application/dns.py b/construct/protocols/application/dns.py index 8a586cec0..85ed5b3fe 100644 --- a/construct/protocols/application/dns.py +++ b/construct/protocols/application/dns.py @@ -1,10 +1,10 @@ """ Domain Name System (TCP/IP protocol stack) """ +from binascii import unhexlify + from construct import * from construct.protocols.layer3.ipv4 import IpAddressAdapter -from binascii import unhexlify -import six class DnsStringAdapter(Adapter): @@ -51,7 +51,7 @@ def _decode(self, obj, context): rdata = Field("rdata", lambda ctx: ctx.rdata_length) resource_record = Struct("resource_record", - CString("name", terminators = six.b("\xc0\x00")), + CString("name", terminators = b"\xc0\x00"), Padding(1), dns_record_type, dns_record_class, @@ -118,7 +118,7 @@ def _decode(self, obj, context): if __name__ == "__main__": - cap1 = unhexlify(six.b("2624010000010000000000000377777706676f6f676c6503636f6d0000010001")) + cap1 = unhexlify(b"2624010000010000000000000377777706676f6f676c6503636f6d0000010001") cap2 = unhexlify(six.b( "2624818000010005000600060377777706676f6f676c6503636f6d0000010001c00c00" diff --git a/construct/protocols/ipstack.py b/construct/protocols/ipstack.py index 7c82fb637..90cf1ea88 100644 --- a/construct/protocols/ipstack.py +++ b/construct/protocols/ipstack.py @@ -4,14 +4,14 @@ first combine all the TCP frames into a stream. See utils.tcpip for some solutions """ +from binascii import unhexlify + from construct import Struct, Rename, HexDumpAdapter, Field, Switch, Pass from construct.protocols.layer2.ethernet import ethernet_header from construct.protocols.layer3.ipv4 import ipv4_header from construct.protocols.layer3.ipv6 import ipv6_header from construct.protocols.layer4.tcp import tcp_header from construct.protocols.layer4.udp import udp_header -from binascii import unhexlify -import six layer4_tcp = Struct("layer4_tcp", diff --git a/construct/protocols/layer2/arp.py b/construct/protocols/layer2/arp.py index 3e86b5307..dee404981 100644 --- a/construct/protocols/layer2/arp.py +++ b/construct/protocols/layer2/arp.py @@ -1,11 +1,11 @@ """ Ethernet (TCP/IP protocol stack) """ +from binascii import unhexlify + from construct import * -from ethernet import MacAddressAdapter from construct.protocols.layer3.ipv4 import IpAddressAdapter -from binascii import unhexlify -import six +from ethernet import MacAddressAdapter @@ -68,14 +68,14 @@ def ProtoAddress(name): if __name__ == "__main__": - cap1 = unhexlify(six.b("00010800060400010002e3426009c0a80204000000000000c0a80201")) + cap1 = unhexlify(b"00010800060400010002e3426009c0a80204000000000000c0a80201") obj = arp_header.parse(cap1) print (obj) print (repr(arp_header.build(obj))) print ("-" * 80) - cap2 = unhexlify(six.b("00010800060400020011508c283cc0a802010002e3426009c0a80204")) + cap2 = unhexlify(b"00010800060400020011508c283cc0a802010002e3426009c0a80204") obj = arp_header.parse(cap2) print (obj) print (repr(arp_header.build(obj))) diff --git a/construct/protocols/layer2/ethernet.py b/construct/protocols/layer2/ethernet.py index d8d4bdd9e..f1f4efa99 100644 --- a/construct/protocols/layer2/ethernet.py +++ b/construct/protocols/layer2/ethernet.py @@ -1,9 +1,9 @@ """ Ethernet (TCP/IP protocol stack) """ -from construct import * from binascii import hexlify, unhexlify -import six + +from construct import * class MacAddressAdapter(Adapter): @@ -31,7 +31,7 @@ def MacAddress(name): if __name__ == "__main__": - cap = unhexlify(six.b("0011508c283c0002e34260090800")) + cap = unhexlify(b"0011508c283c0002e34260090800") obj = ethernet_header.parse(cap) print (obj) print (repr(ethernet_header.build(obj))) diff --git a/construct/protocols/layer3/dhcpv4.py b/construct/protocols/layer3/dhcpv4.py index 2f6e2a21b..440186e14 100644 --- a/construct/protocols/layer3/dhcpv4.py +++ b/construct/protocols/layer3/dhcpv4.py @@ -4,10 +4,10 @@ http://www.networksorcery.com/enp/protocol/dhcp.htm http://www.networksorcery.com/enp/protocol/bootp/options.htm """ +from binascii import unhexlify + from construct import * from ipv4 import IpAddress -from binascii import unhexlify -import six dhcp_option = Struct("dhcp_option", @@ -167,7 +167,7 @@ Bytes("boot_filename", 128), # BOOTP/DHCP options # "The first four bytes contain the (decimal) values 99, 130, 83 and 99" - Const(Bytes("magic", 4), six.b("\x63\x82\x53\x63")), + Const(Bytes("magic", 4), b"\x63\x82\x53\x63"), Rename("options", OptionalGreedyRange(dhcp_option)), ) diff --git a/construct/protocols/layer3/dhcpv6.py b/construct/protocols/layer3/dhcpv6.py index ed4f573e3..cd24b1175 100644 --- a/construct/protocols/layer3/dhcpv6.py +++ b/construct/protocols/layer3/dhcpv6.py @@ -5,7 +5,6 @@ """ from construct import * from ipv6 import Ipv6Address -import six dhcp_option = Struct("dhcp_option", @@ -93,8 +92,8 @@ if __name__ == "__main__": - test1 = six.b("\x03\x11\x22\x33\x00\x17\x00\x03ABC\x00\x05\x00\x05HELLO") - test2 = six.b("\x0c\x040123456789abcdef0123456789abcdef\x00\x09\x00\x0bhello world\x00\x01\x00\x00") + test1 = b"\x03\x11\x22\x33\x00\x17\x00\x03ABC\x00\x05\x00\x05HELLO" + test2 = b"\x0c\x040123456789abcdef0123456789abcdef\x00\x09\x00\x0bhello world\x00\x01\x00\x00" print (dhcp_message.parse(test1)) print (dhcp_message.parse(test2)) diff --git a/construct/protocols/layer3/icmpv4.py b/construct/protocols/layer3/icmpv4.py index 2c0715e48..38756512c 100644 --- a/construct/protocols/layer3/icmpv4.py +++ b/construct/protocols/layer3/icmpv4.py @@ -1,10 +1,10 @@ """ Internet Control Message Protocol for IPv4 (TCP/IP protocol stack) """ +from binascii import unhexlify + from construct import * from ipv4 import IpAddress -from binascii import unhexlify -import six echo_payload = Struct("echo_payload", @@ -80,7 +80,7 @@ "63646566676869")) cap2 = unhexlify(six.b("0000385c02001b006162636465666768696a6b6c6d6e6f70717273747576776162" "63646566676869")) - cap3 = unhexlify(six.b("0301000000001122aabbccdd0102030405060708")) + cap3 = unhexlify(b"0301000000001122aabbccdd0102030405060708") print (icmp_header.parse(cap1)) print (icmp_header.parse(cap2)) diff --git a/construct/protocols/layer3/igmpv2.py b/construct/protocols/layer3/igmpv2.py index 41797eb8f..3e4d22f00 100644 --- a/construct/protocols/layer3/igmpv2.py +++ b/construct/protocols/layer3/igmpv2.py @@ -4,10 +4,10 @@ Who : jesse @ housejunkie . ca """ +from binascii import unhexlify + from construct import Byte, Enum,Struct, UBInt16 from construct.protocols.layer3.ipv4 import IpAddress -from binascii import unhexlify -import six igmp_type = Enum(Byte("igmp_type"), @@ -25,5 +25,5 @@ ) if __name__ == '__main__': - capture = unhexlify(six.b("1600FA01EFFFFFFD")) + capture = unhexlify(b"1600FA01EFFFFFFD") print (igmpv2_header.parse(capture)) diff --git a/construct/protocols/layer3/ipv4.py b/construct/protocols/layer3/ipv4.py index 82dfaa9d7..3e46efa28 100644 --- a/construct/protocols/layer3/ipv4.py +++ b/construct/protocols/layer3/ipv4.py @@ -1,14 +1,9 @@ """ Internet Protocol version 4 (TCP/IP protocol stack) """ -from construct import * -import six from binascii import unhexlify -try: - bytes -except NameError: - bytes = str +from construct import * class IpAddressAdapter(Adapter): @@ -70,7 +65,7 @@ def ProtocolEnum(code): if __name__ == "__main__": - cap = unhexlify(six.b("4500003ca0e3000080116185c0a80205d474a126")) + cap = unhexlify(b"4500003ca0e3000080116185c0a80205d474a126") obj = ipv4_header.parse(cap) print (obj) print (repr(ipv4_header.build(obj))) diff --git a/construct/protocols/layer3/ipv6.py b/construct/protocols/layer3/ipv6.py index 18a0955a3..deccac2f5 100644 --- a/construct/protocols/layer3/ipv6.py +++ b/construct/protocols/layer3/ipv6.py @@ -1,10 +1,10 @@ """ Internet Protocol version 6 (TCP/IP protocol stack) """ +from binascii import unhexlify + from construct import * from ipv4 import ProtocolEnum -from binascii import unhexlify -import six class Ipv6AddressAdapter(Adapter): diff --git a/construct/protocols/layer4/tcp.py b/construct/protocols/layer4/tcp.py index 44f1bd713..fe4fae5a3 100644 --- a/construct/protocols/layer4/tcp.py +++ b/construct/protocols/layer4/tcp.py @@ -1,9 +1,9 @@ """ Transmission Control Protocol (TCP/IP protocol stack) """ -from construct import * from binascii import unhexlify -import six + +from construct import * tcp_header = Struct("tcp_header", @@ -36,7 +36,7 @@ ) if __name__ == "__main__": - cap = unhexlify(six.b("0db5005062303fb21836e9e650184470c9bc0000")) + cap = unhexlify(b"0db5005062303fb21836e9e650184470c9bc0000") obj = tcp_header.parse(cap) print (obj) diff --git a/construct/protocols/layer4/udp.py b/construct/protocols/layer4/udp.py index 42a951e85..e243c29c2 100644 --- a/construct/protocols/layer4/udp.py +++ b/construct/protocols/layer4/udp.py @@ -1,10 +1,10 @@ """ User Datagram Protocol (TCP/IP protocol stack) """ -from construct import * -import six from binascii import unhexlify +from construct import * + udp_header = Struct("udp_header", Value("header_length", lambda ctx: 8), @@ -18,7 +18,7 @@ ) if __name__ == "__main__": - cap = unhexlify(six.b("0bcc003500280689")) + cap = unhexlify(b"0bcc003500280689") obj = udp_header.parse(cap) print (obj) print (repr(udp_header.build(obj))) diff --git a/tests/test_adaptors.py b/tests/test_adaptors.py index 7b86d1936..1068553b0 100644 --- a/tests/test_adaptors.py +++ b/tests/test_adaptors.py @@ -4,7 +4,7 @@ from construct import OneOf, NoneOf, HexDumpAdapter from construct import ValidationError from construct.protocols.layer3.ipv4 import IpAddress -import six + class TestHexDumpAdapter(unittest.TestCase): @@ -15,14 +15,14 @@ def test_trivial(self): pass def test_parse(self): - parsed = self.hda.parse(six.b('abcdef')) - self.assertEqual(parsed, six.b('abcdef')) + parsed = self.hda.parse(b"abcdef") + self.assertEqual(parsed, b"abcdef") def test_build(self): - self.assertEqual(self.hda.build(six.b("abcdef")), six.b("abcdef")) + self.assertEqual(self.hda.build(b"abcdef"), b"abcdef") def test_str(self): - pretty = str(self.hda.parse(six.b("abcdef"))).strip() + pretty = str(self.hda.parse(b"abcdef")).strip() offset, digits, ascii = [i.strip() for i in pretty.split(" ") if i] self.assertEqual(offset, "0000") @@ -38,10 +38,10 @@ def test_trivial(self): pass def test_parse(self): - self.assertEqual(self.n.parse(six.b("\x08")), 8) + self.assertEqual(self.n.parse(b"\x08"), 8) def test_parse_invalid(self): - self.assertRaises(ValidationError, self.n.parse, six.b("\x06")) + self.assertRaises(ValidationError, self.n.parse, b"\x06") class TestOneOf(unittest.TestCase): @@ -52,13 +52,13 @@ def test_trivial(self): pass def test_parse(self): - self.assertEqual(self.o.parse(six.b("\x05")), 5) + self.assertEqual(self.o.parse(b"\x05"), 5) def test_parse_invalid(self): - self.assertRaises(ValidationError, self.o.parse, six.b("\x08")) + self.assertRaises(ValidationError, self.o.parse, b"\x08") def test_build(self): - self.assertEqual(self.o.build(5), six.b("\x05")) + self.assertEqual(self.o.build(5), b"\x05") def test_build_invalid(self): self.assertRaises(ValidationError, self.o.build, 9) @@ -73,12 +73,11 @@ def test_trivial(self): pass def test_parse(self): - self.assertEqual(self.ipa.parse(six.b("\x7f\x80\x81\x82")), - "127.128.129.130") + self.assertEqual(self.ipa.parse(b"\x7f\x80\x81\x82"), "127.128.129.130") def test_build(self): - self.assertEqual(self.ipa.build("127.1.2.3"), - six.b("\x7f\x01\x02\x03")) + self.assertEqual(self.ipa.build("127.1.2.3"), b"\x7f\x01\x02\x03") def test_build_invalid(self): self.assertRaises(ValueError, self.ipa.build, "300.1.2.3") + diff --git a/tests/test_all.py b/tests/test_all.py index d6dc2e9f5..c6d852408 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -7,218 +7,215 @@ class ZlibCodec(object): encode = staticmethod(zlib.compress) decode = staticmethod(zlib.decompress) - -# some tests require doing bad things... import warnings -import six import traceback import unittest warnings.filterwarnings("ignore", category = DeprecationWarning) -# declarative to the bitter end! + all_tests = [ # # constructs # - [MetaArray(lambda ctx: 3, UBInt8("metaarray")).parse, six.b("\x01\x02\x03"), [1,2,3], None], - [MetaArray(lambda ctx: 3, UBInt8("metaarray")).parse, six.b("\x01\x02"), None, ArrayError], - [MetaArray(lambda ctx: 3, UBInt8("metaarray")).build, [1,2,3], six.b("\x01\x02\x03"), None], + [MetaArray(lambda ctx: 3, UBInt8("metaarray")).parse, b"\x01\x02\x03", [1,2,3], None], + [MetaArray(lambda ctx: 3, UBInt8("metaarray")).parse, b"\x01\x02", None, ArrayError], + [MetaArray(lambda ctx: 3, UBInt8("metaarray")).build, [1,2,3], b"\x01\x02\x03", None], [MetaArray(lambda ctx: 3, UBInt8("metaarray")).build, [1,2], None, ArrayError], - [Range(3, 5, UBInt8("range")).parse, six.b("\x01\x02\x03"), [1,2,3], None], - [Range(3, 5, UBInt8("range")).parse, six.b("\x01\x02\x03\x04"), [1,2,3,4], None], - [Range(3, 5, UBInt8("range")).parse, six.b("\x01\x02\x03\x04\x05"), [1,2,3,4,5], None], - [Range(3, 5, UBInt8("range")).parse, six.b("\x01\x02"), None, RangeError], - [Range(3, 5, UBInt8("range")).build, [1,2,3], six.b("\x01\x02\x03"), None], - [Range(3, 5, UBInt8("range")).build, [1,2,3,4], six.b("\x01\x02\x03\x04"), None], - [Range(3, 5, UBInt8("range")).build, [1,2,3,4,5], six.b("\x01\x02\x03\x04\x05"), None], + [Range(3, 5, UBInt8("range")).parse, b"\x01\x02\x03", [1,2,3], None], + [Range(3, 5, UBInt8("range")).parse, b"\x01\x02\x03\x04", [1,2,3,4], None], + [Range(3, 5, UBInt8("range")).parse, b"\x01\x02\x03\x04\x05", [1,2,3,4,5], None], + [Range(3, 5, UBInt8("range")).parse, b"\x01\x02", None, RangeError], + [Range(3, 5, UBInt8("range")).build, [1,2,3], b"\x01\x02\x03", None], + [Range(3, 5, UBInt8("range")).build, [1,2,3,4], b"\x01\x02\x03\x04", None], + [Range(3, 5, UBInt8("range")).build, [1,2,3,4,5], b"\x01\x02\x03\x04\x05", None], [Range(3, 5, UBInt8("range")).build, [1,2], None, RangeError], [Range(3, 5, UBInt8("range")).build, [1,2,3,4,5,6], None, RangeError], - [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).parse, six.b("\x02\x03\x09"), [2,3,9], None], - [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).parse, six.b("\x02\x03\x08"), None, ArrayError], - [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).build, [2,3,9], six.b("\x02\x03\x09"), None], + [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).parse, b"\x02\x03\x09", [2,3,9], None], + [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).parse, b"\x02\x03\x08", None, ArrayError], + [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).build, [2,3,9], b"\x02\x03\x09", None], [RepeatUntil(lambda obj, ctx: obj == 9, UBInt8("repeatuntil")).build, [2,3,8], None, ArrayError], - [Struct("struct", UBInt8("a"), UBInt16("b")).parse, six.b("\x01\x00\x02"), Container(a=1,b=2), None], - [Struct("struct", UBInt8("a"), UBInt16("b"), Struct("foo", UBInt8("c"), UBInt8("d"))).parse, six.b("\x01\x00\x02\x03\x04"), Container(a=1,b=2,foo=Container(c=3,d=4)), None], - [Struct("struct", UBInt8("a"), UBInt16("b"), Embedded(Struct("foo", UBInt8("c"), UBInt8("d")))).parse, six.b("\x01\x00\x02\x03\x04"), Container(a=1,b=2,c=3,d=4), None], - [Struct("struct", UBInt8("a"), UBInt16("b")).build, Container(a=1,b=2), six.b("\x01\x00\x02"), None], - [Struct("struct", UBInt8("a"), UBInt16("b"), Struct("foo", UBInt8("c"), UBInt8("d"))).build, Container(a=1,b=2,foo=Container(c=3,d=4)), six.b("\x01\x00\x02\x03\x04"), None], - [Struct("struct", UBInt8("a"), UBInt16("b"), Embedded(Struct("foo", UBInt8("c"), UBInt8("d")))).build, Container(a=1,b=2,c=3,d=4), six.b("\x01\x00\x02\x03\x04"), None], + [Struct("struct", UBInt8("a"), UBInt16("b")).parse, b"\x01\x00\x02", Container(a=1,b=2), None], + [Struct("struct", UBInt8("a"), UBInt16("b"), Struct("foo", UBInt8("c"), UBInt8("d"))).parse, b"\x01\x00\x02\x03\x04", Container(a=1,b=2,foo=Container(c=3,d=4)), None], + [Struct("struct", UBInt8("a"), UBInt16("b"), Embedded(Struct("foo", UBInt8("c"), UBInt8("d")))).parse, b"\x01\x00\x02\x03\x04", Container(a=1,b=2,c=3,d=4), None], + [Struct("struct", UBInt8("a"), UBInt16("b")).build, Container(a=1,b=2), b"\x01\x00\x02", None], + [Struct("struct", UBInt8("a"), UBInt16("b"), Struct("foo", UBInt8("c"), UBInt8("d"))).build, Container(a=1,b=2,foo=Container(c=3,d=4)), b"\x01\x00\x02\x03\x04", None], + [Struct("struct", UBInt8("a"), UBInt16("b"), Embedded(Struct("foo", UBInt8("c"), UBInt8("d")))).build, Container(a=1,b=2,c=3,d=4), b"\x01\x00\x02\x03\x04", None], - [Sequence("sequence", UBInt8("a"), UBInt16("b")).parse, six.b("\x01\x00\x02"), [1,2], None], - [Sequence("sequence", UBInt8("a"), UBInt16("b"), Sequence("foo", UBInt8("c"), UBInt8("d"))).parse, six.b("\x01\x00\x02\x03\x04"), [1,2,[3,4]], None], - [Sequence("sequence", UBInt8("a"), UBInt16("b"), Embedded(Sequence("foo", UBInt8("c"), UBInt8("d")))).parse, six.b("\x01\x00\x02\x03\x04"), [1,2,3,4], None], - [Sequence("sequence", UBInt8("a"), UBInt16("b")).build, [1,2], six.b("\x01\x00\x02"), None], - [Sequence("sequence", UBInt8("a"), UBInt16("b"), Sequence("foo", UBInt8("c"), UBInt8("d"))).build, [1,2,[3,4]], six.b("\x01\x00\x02\x03\x04"), None], - [Sequence("sequence", UBInt8("a"), UBInt16("b"), Embedded(Sequence("foo", UBInt8("c"), UBInt8("d")))).build, [1,2,3,4], six.b("\x01\x00\x02\x03\x04"), None], + [Sequence("sequence", UBInt8("a"), UBInt16("b")).parse, b"\x01\x00\x02", [1,2], None], + [Sequence("sequence", UBInt8("a"), UBInt16("b"), Sequence("foo", UBInt8("c"), UBInt8("d"))).parse, b"\x01\x00\x02\x03\x04", [1,2,[3,4]], None], + [Sequence("sequence", UBInt8("a"), UBInt16("b"), Embedded(Sequence("foo", UBInt8("c"), UBInt8("d")))).parse, b"\x01\x00\x02\x03\x04", [1,2,3,4], None], + [Sequence("sequence", UBInt8("a"), UBInt16("b")).build, [1,2], b"\x01\x00\x02", None], + [Sequence("sequence", UBInt8("a"), UBInt16("b"), Sequence("foo", UBInt8("c"), UBInt8("d"))).build, [1,2,[3,4]], b"\x01\x00\x02\x03\x04", None], + [Sequence("sequence", UBInt8("a"), UBInt16("b"), Embedded(Sequence("foo", UBInt8("c"), UBInt8("d")))).build, [1,2,3,4], b"\x01\x00\x02\x03\x04", None], - [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}).parse, six.b("\x00\x02"), 2, None], - [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}).parse, six.b("\x00\x02"), None, SwitchError], - [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}, default = UBInt8("x")).parse, six.b("\x00\x02"), 0, None], - [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}, include_key = True).parse, six.b("\x00\x02"), (5, 2), None], - [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}).build, 2, six.b("\x00\x02"), None], + [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}).parse, b"\x00\x02", 2, None], + [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}).parse, b"\x00\x02", None, SwitchError], + [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}, default = UBInt8("x")).parse, b"\x00\x02", 0, None], + [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}, include_key = True).parse, b"\x00\x02", (5, 2), None], + [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}).build, 2, b"\x00\x02", None], [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}).build, 9, None, SwitchError], - [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}, default = UBInt8("x")).build, 9, six.b("\x09"), None], - [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}, include_key = True).build, ((5, 2),), six.b("\x00\x02"), None], + [Switch("switch", lambda ctx: 6, {1:UBInt8("x"), 5:UBInt16("y")}, default = UBInt8("x")).build, 9, b"\x09", None], + [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}, include_key = True).build, ((5, 2),), b"\x00\x02", None], [Switch("switch", lambda ctx: 5, {1:UBInt8("x"), 5:UBInt16("y")}, include_key = True).build, ((89, 2),), None, SwitchError], - [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c")).parse, six.b("\x07"), 7, None], - [Select("select", UBInt32("a"), UBInt16("b")).parse, six.b("\x07"), None, SelectError], - [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c"), include_name = True).parse, six.b("\x07"), ("c", 7), None], - [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c")).build, 7, six.b("\x00\x00\x00\x07"), None], - [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c"), include_name = True).build, (("c", 7),), six.b("\x07"), None], + [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c")).parse, b"\x07", 7, None], + [Select("select", UBInt32("a"), UBInt16("b")).parse, b"\x07", None, SelectError], + [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c"), include_name = True).parse, b"\x07", ("c", 7), None], + [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c")).build, 7, b"\x00\x00\x00\x07", None], + [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c"), include_name = True).build, (("c", 7),), b"\x07", None], [Select("select", UBInt32("a"), UBInt16("b"), UBInt8("c"), include_name = True).build, (("d", 7),), None, SelectError], - [Peek(UBInt8("peek")).parse, six.b("\x01"), 1, None], - [Peek(UBInt8("peek")).parse, six.b(""), None, None], - [Peek(UBInt8("peek")).build, 1, six.b(""), None], - [Peek(UBInt8("peek"), perform_build = True).build, 1, six.b("\x01"), None], - [Struct("peek", Peek(UBInt8("a")), UBInt16("b")).parse, six.b("\x01\x02"), Container(a=1,b=0x102), None], - [Struct("peek", Peek(UBInt8("a")), UBInt16("b")).build, Container(a=1,b=0x102), six.b("\x01\x02"), None], + [Peek(UBInt8("peek")).parse, b"\x01", 1, None], + [Peek(UBInt8("peek")).parse, b"", None, None], + [Peek(UBInt8("peek")).build, 1, b"", None], + [Peek(UBInt8("peek"), perform_build = True).build, 1, b"\x01", None], + [Struct("peek", Peek(UBInt8("a")), UBInt16("b")).parse, b"\x01\x02", Container(a=1,b=0x102), None], + [Struct("peek", Peek(UBInt8("a")), UBInt16("b")).build, Container(a=1,b=0x102), b"\x01\x02", None], - [Value("value", lambda ctx: "moo").parse, six.b(""), "moo", None], - [Value("value", lambda ctx: "moo").build, None, six.b(""), None], + [Value("value", lambda ctx: "moo").parse, b"", "moo", None], + [Value("value", lambda ctx: "moo").build, None, b"", None], - [Anchor("anchor").parse, six.b(""), 0, None], - [Anchor("anchor").build, None, six.b(""), None], + [Anchor("anchor").parse, b"", 0, None], + [Anchor("anchor").build, None, b"", None], - [LazyBound("lazybound", lambda: UBInt8("foo")).parse, six.b("\x02"), 2, None], - [LazyBound("lazybound", lambda: UBInt8("foo")).build, 2, six.b("\x02"), None], + [LazyBound("lazybound", lambda: UBInt8("foo")).parse, b"\x02", 2, None], + [LazyBound("lazybound", lambda: UBInt8("foo")).build, 2, b"\x02", None], - [Pass.parse, six.b(""), None, None], - [Pass.build, None, six.b(""), None], + [Pass.parse, b"", None, None], + [Pass.build, None, b"", None], - [Terminator.parse, six.b(""), None, None], - [Terminator.parse, six.b("x"), None, TerminatorError], - [Terminator.build, None, six.b(""), None], + [Terminator.parse, b"", None, None], + [Terminator.parse, b"x", None, TerminatorError], + [Terminator.build, None, b"", None], - [Pointer(lambda ctx: 2, UBInt8("pointer")).parse, six.b("\x00\x00\x07"), 7, None], - [Pointer(lambda ctx: 2, UBInt8("pointer")).build, 7, six.b("\x00\x00\x07"), None], + [Pointer(lambda ctx: 2, UBInt8("pointer")).parse, b"\x00\x00\x07", 7, None], + [Pointer(lambda ctx: 2, UBInt8("pointer")).build, 7, b"\x00\x00\x07", None], - [OnDemand(UBInt8("ondemand")).parse(six.b("\x08")).read, (), 8, None], + [OnDemand(UBInt8("ondemand")).parse(b"\x08").read, (), 8, None], [Struct("ondemand", UBInt8("a"), OnDemand(UBInt8("b")), UBInt8("c")).parse, - six.b("\x07\x08\x09"), Container(a=7,b=LazyContainer(None, None, None, None),c=9), None], + b"\x07\x08\x09", Container(a=7,b=LazyContainer(None, None, None, None),c=9), None], [Struct("ondemand", UBInt8("a"), OnDemand(UBInt8("b"), advance_stream = False), UBInt8("c")).parse, - six.b("\x07\x09"), Container(a=7,b=LazyContainer(None, None, None, None),c=9), None], + b"\x07\x09", Container(a=7,b=LazyContainer(None, None, None, None),c=9), None], - [OnDemand(UBInt8("ondemand")).build, 8, six.b("\x08"), None], + [OnDemand(UBInt8("ondemand")).build, 8, b"\x08", None], [Struct("ondemand", UBInt8("a"), OnDemand(UBInt8("b")), UBInt8("c")).build, - Container(a=7,b=8,c=9), six.b("\x07\x08\x09"), None], + Container(a=7,b=8,c=9), b"\x07\x08\x09", None], [Struct("ondemand", UBInt8("a"), OnDemand(UBInt8("b"), force_build = False), UBInt8("c")).build, - Container(a=7,b=LazyContainer(None, None, None, None),c=9), six.b("\x07\x00\x09"), None], + Container(a=7,b=LazyContainer(None, None, None, None),c=9), b"\x07\x00\x09", None], [Struct("ondemand", UBInt8("a"), OnDemand(UBInt8("b"), force_build = False, advance_stream = False), UBInt8("c")).build, - Container(a=7,b=LazyContainer(None, None, None, None),c=9), six.b("\x07\x09"), None], + Container(a=7,b=LazyContainer(None, None, None, None),c=9), b"\x07\x09", None], - [Struct("reconfig", Reconfig("foo", UBInt8("bar"))).parse, six.b("\x01"), Container(foo=1), None], - [Struct("reconfig", Reconfig("foo", UBInt8("bar"))).build, Container(foo=1), six.b("\x01"), None], + [Struct("reconfig", Reconfig("foo", UBInt8("bar"))).parse, b"\x01", Container(foo=1), None], + [Struct("reconfig", Reconfig("foo", UBInt8("bar"))).build, Container(foo=1), b"\x01", None], [Buffered(UBInt8("buffered"), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), 7, None], + b"\x07", 7, None], [Buffered(GreedyRange(UBInt8("buffered")), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), None, SizeofError], + b"\x07", None, SizeofError], [Buffered(UBInt8("buffered"), lambda x:x, lambda x:x, lambda x:x).build, - 7, six.b("\x07"), None], + 7, b"\x07", None], [Buffered(GreedyRange(UBInt8("buffered")), lambda x:x, lambda x:x, lambda x:x).build, [7], None, SizeofError], [Restream(UBInt8("restream"), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), 7, None], + b"\x07", 7, None], [Restream(GreedyRange(UBInt8("restream")), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), [7], None], + b"\x07", [7], None], [Restream(UBInt8("restream"), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), 7, None], + b"\x07", 7, None], [Restream(GreedyRange(UBInt8("restream")), lambda x:x, lambda x:x, lambda x:x).parse, - six.b("\x07"), [7], None], + b"\x07", [7], None], # # adapters # - [BitIntegerAdapter(Field("bitintegeradapter", 8), 8).parse, six.b("\x01") * 8, 255, None], - [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, signed = True).parse, six.b("\x01") * 8, -1, None], + [BitIntegerAdapter(Field("bitintegeradapter", 8), 8).parse, b"\x01" * 8, 255, None], + [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, signed = True).parse, b"\x01" * 8, -1, None], [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, swapped = True, bytesize = 4).parse, - six.b("\x01") * 4 + six.b("\x00") * 4, 0x0f, None], - [BitIntegerAdapter(Field("bitintegeradapter", 8), 8).build, 255, six.b("\x01") * 8, None], - [BitIntegerAdapter(Field("bitintegeradapter", lambda c: 8), lambda c: 8).build, 255, six.b("\x01") * 8, None], + b"\x01" * 4 + b"\x00" * 4, 0x0f, None], + [BitIntegerAdapter(Field("bitintegeradapter", 8), 8).build, 255, b"\x01" * 8, None], + [BitIntegerAdapter(Field("bitintegeradapter", lambda c: 8), lambda c: 8).build, 255, b"\x01" * 8, None], [BitIntegerAdapter(Field("bitintegeradapter", 8), 8).build, -1, None, BitIntegerError], - [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, signed = True).build, -1, six.b("\x01") * 8, None], + [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, signed = True).build, -1, b"\x01" * 8, None], [BitIntegerAdapter(Field("bitintegeradapter", 8), 8, swapped = True, bytesize = 4).build, - 0x0f, six.b("\x01") * 4 + six.b("\x00") * 4, None], + 0x0f, b"\x01" * 4 + b"\x00" * 4, None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}).parse, - six.b("\x03"), "y", None], + b"\x03", "y", None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}).parse, - six.b("\x04"), None, MappingError], + b"\x04", None, MappingError], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}, decdefault="foo").parse, - six.b("\x04"), "foo", None], + b"\x04", "foo", None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}, decdefault=Pass).parse, - six.b("\x04"), 4, None], + b"\x04", 4, None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}).build, - "y", six.b("\x03"), None], + "y", b"\x03", None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}).build, "z", None, MappingError], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}, encdefault=17).build, - "foo", six.b("\x11"), None], + "foo", b"\x11", None], [MappingAdapter(UBInt8("mappingadapter"), {2:"x",3:"y"}, {"x":2,"y":3}, encdefault=Pass).build, - 4, six.b("\x04"), None], + 4, b"\x04", None], [FlagsAdapter(UBInt8("flagsadapter"), {"a":1,"b":2,"c":4,"d":8,"e":16,"f":32,"g":64,"h":128}).parse, - six.b("\x81"), Container(a=True, b=False,c=False,d=False,e=False,f=False,g=False,h=True), None], + b"\x81", Container(a=True, b=False,c=False,d=False,e=False,f=False,g=False,h=True), None], [FlagsAdapter(UBInt8("flagsadapter"), {"a":1,"b":2,"c":4,"d":8,"e":16,"f":32,"g":64,"h":128}).build, - Container(a=True, b=False,c=False,d=False,e=False,f=False,g=False,h=True), six.b("\x81"), None], + Container(a=True, b=False,c=False,d=False,e=False,f=False,g=False,h=True), b"\x81", None], - [IndexingAdapter(Array(3, UBInt8("indexingadapter")), 2).parse, six.b("\x11\x22\x33"), 0x33, None], + [IndexingAdapter(Array(3, UBInt8("indexingadapter")), 2).parse, b"\x11\x22\x33", 0x33, None], [IndexingAdapter(Array(3, UBInt8("indexingadapter")), 2)._encode, (0x33, {}), [None, None, 0x33], None], - [SlicingAdapter(Array(3, UBInt8("indexingadapter")), 1, 3).parse, six.b("\x11\x22\x33"), [0x22, 0x33], None], + [SlicingAdapter(Array(3, UBInt8("indexingadapter")), 1, 3).parse, b"\x11\x22\x33", [0x22, 0x33], None], [SlicingAdapter(Array(3, UBInt8("indexingadapter")), 1, 3)._encode, ([0x22, 0x33], {}), [None, 0x22, 0x33], None], - [PaddingAdapter(Field("paddingadapter", 4)).parse, six.b("abcd"), six.b("abcd"), None], - [PaddingAdapter(Field("paddingadapter", 4), strict = True).parse, six.b("abcd"), None, PaddingError], - [PaddingAdapter(Field("paddingadapter", 4), strict = True).parse, six.b("\x00\x00\x00\x00"), six.b("\x00\x00\x00\x00"), None], - [PaddingAdapter(Field("paddingadapter", 4)).build, six.b("abcd"), six.b("\x00\x00\x00\x00"), None], + [PaddingAdapter(Field("paddingadapter", 4)).parse, b"abcd", b"abcd", None], + [PaddingAdapter(Field("paddingadapter", 4), strict = True).parse, b"abcd", None, PaddingError], + [PaddingAdapter(Field("paddingadapter", 4), strict = True).parse, b"\x00\x00\x00\x00", b"\x00\x00\x00\x00", None], + [PaddingAdapter(Field("paddingadapter", 4)).build, b"abcd", b"\x00\x00\x00\x00", None], [LengthValueAdapter(Sequence("lengthvalueadapter", UBInt8("length"), Field("value", lambda ctx: ctx.length))).parse, - six.b("\x05abcde"), six.b("abcde"), None], + b"\x05abcde", b"abcde", None], [LengthValueAdapter(Sequence("lengthvalueadapter", UBInt8("length"), Field("value", lambda ctx: ctx.length))).build, - six.b("abcde"), six.b("\x05abcde"), None], + b"abcde", b"\x05abcde", None], [TunnelAdapter(PascalString("data", encoding = ZlibCodec), GreedyRange(UBInt16("elements"))).parse, - six.b("\rx\x9cc`f\x18\x16\x10\x00u\xf8\x01-"), [3] * 100, None], + b"\rx\x9cc`f\x18\x16\x10\x00u\xf8\x01-", [3] * 100, None], [TunnelAdapter(PascalString("data", encoding = ZlibCodec), GreedyRange(UBInt16("elements"))).build, - [3] * 100, six.b("\rx\x9cc`f\x18\x16\x10\x00u\xf8\x01-"), None], + [3] * 100, b"\rx\x9cc`f\x18\x16\x10\x00u\xf8\x01-", None], - [Const(Field("const", 2), six.b("MZ")).parse, six.b("MZ"), six.b("MZ"), None], - [Const(Field("const", 2), six.b("MZ")).parse, six.b("MS"), None, ConstError], - [Const(Field("const", 2), six.b("MZ")).build, six.b("MZ"), six.b("MZ"), None], - [Const(Field("const", 2), six.b("MZ")).build, six.b("MS"), None, ConstError], - [Const(Field("const", 2), six.b("MZ")).build, None, six.b("MZ"), None], + [Const(Field("const", 2), b"MZ").parse, b"MZ", b"MZ", None], + [Const(Field("const", 2), b"MZ").parse, b"MS", None, ConstError], + [Const(Field("const", 2), b"MZ").build, b"MZ", b"MZ", None], + [Const(Field("const", 2), b"MZ").build, b"MS", None, ConstError], + [Const(Field("const", 2), b"MZ").build, None, b"MZ", None], [ExprAdapter(UBInt8("expradapter"), encoder = lambda obj, ctx: obj // 7, decoder = lambda obj, ctx: obj * 7).parse, - six.b("\x06"), 42, None], + b"\x06", 42, None], [ExprAdapter(UBInt8("expradapter"), encoder = lambda obj, ctx: obj // 7, decoder = lambda obj, ctx: obj * 7).build, - 42, six.b("\x06"), None], + 42, b"\x06", None], # # macros # - [Aligned(UBInt8("aligned")).parse, six.b("\x01\x00\x00\x00"), 1, None], - [Aligned(UBInt8("aligned")).build, 1, six.b("\x01\x00\x00\x00"), None], + [Aligned(UBInt8("aligned")).parse, b"\x01\x00\x00\x00", 1, None], + [Aligned(UBInt8("aligned")).build, 1, b"\x01\x00\x00\x00", None], [Struct("aligned", Aligned(UBInt8("a")), UBInt8("b")).parse, - six.b("\x01\x00\x00\x00\x02"), Container(a=1,b=2), None], + b"\x01\x00\x00\x00\x02", Container(a=1,b=2), None], [Struct("aligned", Aligned(UBInt8("a")), UBInt8("b")).build, - Container(a=1,b=2), six.b("\x01\x00\x00\x00\x02"), None], + Container(a=1,b=2), b"\x01\x00\x00\x00\x02", None], - [Bitwise(Field("bitwise", 8)).parse, six.b("\xff"), six.b("\x01") * 8, None], - [Bitwise(Field("bitwise", lambda ctx: 8)).parse, six.b("\xff"), six.b("\x01") * 8, None], - [Bitwise(Field("bitwise", 8)).build, six.b("\x01") * 8, six.b("\xff"), None], - [Bitwise(Field("bitwise", lambda ctx: 8)).build, six.b("\x01") * 8, six.b("\xff"), None], + [Bitwise(Field("bitwise", 8)).parse, b"\xff", b"\x01" * 8, None], + [Bitwise(Field("bitwise", lambda ctx: 8)).parse, b"\xff", b"\x01" * 8, None], + [Bitwise(Field("bitwise", 8)).build, b"\x01" * 8, b"\xff", None], + [Bitwise(Field("bitwise", lambda ctx: 8)).build, b"\x01" * 8, b"\xff", None], [Union("union", UBInt32("a"), @@ -227,7 +224,7 @@ class ZlibCodec(object): Struct("d", UBInt8("a"), UBInt8("b"), UBInt8("c"), UBInt8("d")), Embedded(Struct("q", UBInt8("e"))), ).parse, - six.b("\x11\x22\x33\x44"), + b"\x11\x22\x33\x44", Container(a=0x11223344, b=Container(a=0x1122, b=0x3344), c=Container(a=0x12), @@ -248,37 +245,38 @@ class ZlibCodec(object): d=Container(a=0x11, b=0x22, c=0x33, d=0x44), e=0x11, ), - six.b("\x11\x22\x33\x44"), + b"\x11\x22\x33\x44", None], - [Enum(UBInt8("enum"),q=3,r=4,t=5).parse, six.b("\x04"), "r", None], - [Enum(UBInt8("enum"),q=3,r=4,t=5).parse, six.b("\x07"), None, MappingError], - [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ = "spam").parse, six.b("\x07"), "spam", None], - [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ =Pass).parse, six.b("\x07"), 7, None], - [Enum(UBInt8("enum"),q=3,r=4,t=5).build, "r", six.b("\x04"), None], + [Enum(UBInt8("enum"),q=3,r=4,t=5).parse, b"\x04", "r", None], + [Enum(UBInt8("enum"),q=3,r=4,t=5).parse, b"\x07", None, MappingError], + [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ = "spam").parse, b"\x07", "spam", None], + [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ =Pass).parse, b"\x07", 7, None], + [Enum(UBInt8("enum"),q=3,r=4,t=5).build, "r", b"\x04", None], [Enum(UBInt8("enum"),q=3,r=4,t=5).build, "spam", None, MappingError], - [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ = 9).build, "spam", six.b("\x09"), None], - [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ =Pass).build, 9, six.b("\x09"), None], + [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ = 9).build, "spam", b"\x09", None], + [Enum(UBInt8("enum"),q=3,r=4,t=5, _default_ =Pass).build, 9, b"\x09", None], - [PrefixedArray(UBInt8("array"), UBInt8("count")).parse, six.b("\x03\x01\x01\x01"), [1,1,1], None], - [PrefixedArray(UBInt8("array"), UBInt8("count")).parse, six.b("\x03\x01\x01"), None, ArrayError], + [PrefixedArray(UBInt8("array"), UBInt8("count")).parse, b"\x03\x01\x01\x01", [1,1,1], None], + [PrefixedArray(UBInt8("array"), UBInt8("count")).parse, b"\x03\x01\x01", None, ArrayError], [PrefixedArray(UBInt8("array"), UBInt8("count")).sizeof, [1,1,1], 4, None], - [PrefixedArray(UBInt8("array"), UBInt8("count")).build, [1,1,1], six.b("\x03\x01\x01\x01"), None], + [PrefixedArray(UBInt8("array"), UBInt8("count")).build, [1,1,1], b"\x03\x01\x01\x01", None], [IfThenElse("ifthenelse", lambda ctx: True, UBInt8("then"), UBInt16("else")).parse, - six.b("\x01"), 1, None], + b"\x01", 1, None], [IfThenElse("ifthenelse", lambda ctx: False, UBInt8("then"), UBInt16("else")).parse, - six.b("\x00\x01"), 1, None], + b"\x00\x01", 1, None], [IfThenElse("ifthenelse", lambda ctx: True, UBInt8("then"), UBInt16("else")).build, - 1, six.b("\x01"), None], + 1, b"\x01", None], [IfThenElse("ifthenelse", lambda ctx: False, UBInt8("then"), UBInt16("else")).build, - 1, six.b("\x00\x01"), None], + 1, b"\x00\x01", None], - [Magic(six.b("MZ")).parse, six.b("MZ"), six.b("MZ"), None], - [Magic(six.b("MZ")).parse, six.b("ELF"), None, ConstError], - [Magic(six.b("MZ")).build, None, six.b("MZ"), None], + [Magic(b"MZ").parse, b"MZ", b"MZ", None], + [Magic(b"MZ").parse, b"ELF", None, ConstError], + [Magic(b"MZ").build, None, b"MZ", None], ] + class TestAll(unittest.TestCase): def _run_tests(self, tests): errors = [] @@ -309,5 +307,3 @@ def test_all(self): if errors: self.fail("\n=========================\n".join(str(e) for e in errors)) -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_bit.py b/tests/test_bit.py index cd2cfb5f1..1539dde6f 100644 --- a/tests/test_bit.py +++ b/tests/test_bit.py @@ -2,7 +2,7 @@ from construct import BitField, BitStruct, Struct, Container from construct import Bit, Flag, Nibble, Padding -import six + class TestBitStruct(unittest.TestCase): @@ -14,7 +14,7 @@ def test_parse(self): Nibble("c"), BitField("d", 5), ) - self.assertEqual(struct.parse(six.b("\xe1\x1f")), + self.assertEqual(struct.parse(b"\xe1\x1f"), Container(a=7, b=False, c=8, d=31)) def test_parse_nested(self): @@ -28,5 +28,6 @@ def test_parse_nested(self): Bit("e"), ) ) - self.assertEqual(struct.parse(six.b("\xe1\x1f")), + self.assertEqual(struct.parse(b"\xe1\x1f"), Container(a=7, b=False, bar=Container(d=15, e=1), c=8)) + diff --git a/tests/test_mapping.py b/tests/test_mapping.py index 6458bbeeb..421477c28 100644 --- a/tests/test_mapping.py +++ b/tests/test_mapping.py @@ -1,31 +1,31 @@ import unittest from construct import Flag -import six + class TestFlag(unittest.TestCase): def test_parse(self): flag = Flag("flag") - self.assertTrue(flag.parse(six.b("\x01"))) + self.assertTrue(flag.parse(b"\x01")) def test_parse_flipped(self): flag = Flag("flag", truth=0, falsehood=1) - self.assertFalse(flag.parse(six.b("\x01"))) + self.assertFalse(flag.parse(b"\x01")) def test_parse_default(self): flag = Flag("flag") - self.assertFalse(flag.parse(six.b("\x02"))) + self.assertFalse(flag.parse(b"\x02")) def test_parse_default_true(self): flag = Flag("flag", default=True) - self.assertTrue(flag.parse(six.b("\x02"))) + self.assertTrue(flag.parse(b"\x02")) def test_build(self): flag = Flag("flag") - self.assertEqual(flag.build(True), six.b("\x01")) + self.assertEqual(flag.build(True), b"\x01") def test_build_flipped(self): flag = Flag("flag", truth=0, falsehood=1) - self.assertEqual(flag.build(True), six.b("\x00")) + self.assertEqual(flag.build(True), b"\x00") diff --git a/tests/test_overwrite.py b/tests/test_overwrite.py index d83ee6d97..70244b3f0 100644 --- a/tests/test_overwrite.py +++ b/tests/test_overwrite.py @@ -1,6 +1,6 @@ import unittest + from construct import Struct, Byte, Embedded, OverwriteError -import six class TestOverwrite(unittest.TestCase): @@ -10,7 +10,7 @@ def test_overwrite(self): Byte("a"), allow_overwrite = True ) - self.assertEqual(s.parse(six.b("\x01\x02")).a, 2) + self.assertEqual(s.parse(b"\x01\x02").a, 2) s = Struct("s", Byte("a"), @@ -19,7 +19,7 @@ def test_overwrite(self): allow_overwrite = True )), ) - self.assertEqual(s.parse(six.b("\x01\x02")).a, 2) + self.assertEqual(s.parse(b"\x01\x02").a, 2) s = Struct("s", Embedded(Struct("b", @@ -28,14 +28,14 @@ def test_overwrite(self): Byte("a"), allow_overwrite = True ) - self.assertEqual(s.parse(six.b("\x01\x02")).a, 2) + self.assertEqual(s.parse(b"\x01\x02").a, 2) def test_no_overwrite(self): s = Struct("s", Byte("a"), Byte("a"), ) - self.assertRaises(OverwriteError, s.parse, six.b("\x01\x02")) + self.assertRaises(OverwriteError, s.parse, b"\x01\x02") s = Struct("s", Byte("a"), @@ -44,7 +44,7 @@ def test_no_overwrite(self): )), allow_overwrite = True ) - self.assertRaises(OverwriteError, s.parse, six.b("\x01\x02")) + self.assertRaises(OverwriteError, s.parse, b"\x01\x02") s = Struct("s", Embedded(Struct("b", @@ -53,7 +53,5 @@ def test_no_overwrite(self): )), Byte("a"), ) - self.assertRaises(OverwriteError, s.parse, six.b("\x01\x02")) + self.assertRaises(OverwriteError, s.parse, b"\x01\x02") -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_repeaters.py b/tests/test_repeaters.py index 356d7d7f5..a997aa004 100644 --- a/tests/test_repeaters.py +++ b/tests/test_repeaters.py @@ -3,7 +3,6 @@ from construct import UBInt8 from construct import Range, Array, GreedyRange, OptionalGreedyRange from construct import ArrayError, RangeError -import six class TestRange(unittest.TestCase): @@ -15,16 +14,16 @@ def test_trivial(self): pass def test_parse(self): - self.assertEqual(self.c.parse(six.b("\x01\x02\x03")), [1, 2, 3]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04\x05\x06")), + self.assertEqual(self.c.parse(b"\x01\x02\x03"), [1, 2, 3]) + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04\x05\x06"), [1, 2, 3, 4, 5, 6]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04\x05\x06\x07")), + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04\x05\x06\x07"), [1, 2, 3, 4, 5, 6, 7]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04\x05\x06\x07\x08\x09")), + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09"), [1, 2, 3, 4, 5, 6, 7]) def test_build(self): - self.assertEqual(self.c.build([1, 2, 3, 4]), six.b("\x01\x02\x03\x04")) + self.assertEqual(self.c.build([1, 2, 3, 4]), b"\x01\x02\x03\x04") def test_build_undersized(self): self.assertRaises(RangeError, self.c.build, [1, 2]) @@ -41,12 +40,12 @@ def test_trivial(self): pass def test_parse(self): - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04")), [1, 2, 3, 4]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04\x05\x06")), + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04"), [1, 2, 3, 4]) + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04\x05\x06"), [1, 2, 3, 4]) def test_build(self): - self.assertEqual(self.c.build([5, 6, 7, 8]), six.b("\x05\x06\x07\x08")) + self.assertEqual(self.c.build([5, 6, 7, 8]), b"\x05\x06\x07\x08") def test_build_oversized(self): self.assertRaises(ArrayError, self.c.build, [5, 6, 7, 8, 9]) @@ -63,19 +62,19 @@ def test_trivial(self): pass def test_empty_parse(self): - self.assertRaises(RangeError, self.c.parse, six.b("")) + self.assertRaises(RangeError, self.c.parse, b"") def test_parse(self): - self.assertEqual(self.c.parse(six.b("\x01")), [1]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03")), [1, 2, 3]) - self.assertEqual(self.c.parse(six.b("\x01\x02\x03\x04\x05\x06")), + self.assertEqual(self.c.parse(b"\x01"), [1]) + self.assertEqual(self.c.parse(b"\x01\x02\x03"), [1, 2, 3]) + self.assertEqual(self.c.parse(b"\x01\x02\x03\x04\x05\x06"), [1, 2, 3, 4, 5, 6]) def test_empty_build(self): self.assertRaises(RangeError, self.c.build, []) def test_build(self): - self.assertEqual(self.c.build([1, 2]), six.b("\x01\x02")) + self.assertEqual(self.c.build([1, 2]), b"\x01\x02") class TestOptionalGreedyRange(unittest.TestCase): @@ -87,14 +86,14 @@ def test_trivial(self): pass def test_empty_parse(self): - self.assertEqual(self.c.parse(six.b("")), []) + self.assertEqual(self.c.parse(b""), []) def test_parse(self): - self.assertEqual(self.c.parse(six.b("\x01\x02")), [1, 2]) + self.assertEqual(self.c.parse(b"\x01\x02"), [1, 2]) def test_empty_build(self): - self.assertEqual(self.c.build([]), six.b("")) + self.assertEqual(self.c.build([]), b"") def test_build(self): - self.assertEqual(self.c.build([1, 2]), six.b("\x01\x02")) + self.assertEqual(self.c.build([1, 2]), b"\x01\x02") diff --git a/tests/test_sizeof.py b/tests/test_sizeof.py index 14097823d..da646d3a3 100644 --- a/tests/test_sizeof.py +++ b/tests/test_sizeof.py @@ -1,6 +1,5 @@ import unittest from construct import Struct, UBInt8, Bytes, Container -import six def foo(ctx): print("!! %r" % (ctx,)) @@ -15,12 +14,9 @@ def test(self): Bytes("data", foo), ) ) - obj = pstring.parse(six.b("\x03\x02helloXXX")) + obj = pstring.parse(b"\x03\x02helloXXX") print(repr(obj)) - self.assertEqual(obj, Container(length = 3, inner = Container(inner_length = 2, data = six.b("hello")))) + self.assertEqual(obj, Container(length = 3, inner = Container(inner_length = 2, data = b"hello"))) size = pstring._sizeof(Container(inner_length = 2, _ = Container(length = 3))) self.assertEqual(size, 7) - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_strings.py b/tests/test_strings.py index 4f0c7f4d2..31fd7daeb 100644 --- a/tests/test_strings.py +++ b/tests/test_strings.py @@ -1,102 +1,95 @@ import unittest import six + from construct import String, PascalString, CString, UBInt16, GreedyString class TestString(unittest.TestCase): def test_parse(self): s = String("foo", 5) - self.assertEqual(s.parse(six.b("hello")), six.b("hello")) + self.assertEqual(s.parse(b"hello"), b"hello") def test_parse_utf8(self): s = String("foo", 12, encoding="utf8") - self.assertEqual(s.parse(six.b("hello joh\xd4\x83n")), six.u("hello joh\u0503n")) + self.assertEqual(s.parse(b"hello joh\xd4\x83n"), six.u("hello joh\u0503n")) def test_parse_padded(self): - s = String("foo", 10, padchar=six.b("X"), paddir="right") - self.assertEqual(s.parse(six.b("helloXXXXX")), six.b("hello")) + s = String("foo", 10, padchar=b"X", paddir="right") + self.assertEqual(s.parse(b"helloXXXXX"), b"hello") def test_parse_padded_left(self): - s = String("foo", 10, padchar=six.b("X"), paddir="left") - self.assertEqual(s.parse(six.b("XXXXXhello")), six.b("hello")) + s = String("foo", 10, padchar=b"X", paddir="left") + self.assertEqual(s.parse(b"XXXXXhello"), b"hello") def test_parse_padded_center(self): - s = String("foo", 10, padchar=six.b("X"), paddir="center") - self.assertEqual(s.parse(six.b("XXhelloXXX")), six.b("hello")) + s = String("foo", 10, padchar=b"X", paddir="center") + self.assertEqual(s.parse(b"XXhelloXXX"), b"hello") def test_build(self): s = String("foo", 5) - self.assertEqual(s.build(six.b("hello")), six.b("hello")) + self.assertEqual(s.build(b"hello"), b"hello") def test_build_utf8(self): s = String("foo", 12, encoding="utf8") - self.assertEqual(s.build(six.u("hello joh\u0503n")), six.b("hello joh\xd4\x83n")) + self.assertEqual(s.build(six.u("hello joh\u0503n")), b"hello joh\xd4\x83n") def test_build_padded(self): s = String("foo", 10, padchar="X", paddir="right", encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("helloXXXXX")) + self.assertEqual(s.build(six.u("hello")), b"helloXXXXX") def test_build_padded_left(self): s = String("foo", 10, padchar="X", paddir="left", encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("XXXXXhello")) + self.assertEqual(s.build(six.u("hello")), b"XXXXXhello") def test_build_padded_center(self): s = String("foo", 10, padchar="X", paddir="center", encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("XXhelloXXX")) + self.assertEqual(s.build(six.u("hello")), b"XXhelloXXX") class TestPascalString(unittest.TestCase): def test_parse(self): s = PascalString("foo", encoding="utf8") - self.assertEqual(s.parse(six.b("\x05hello")), six.u("hello")) + self.assertEqual(s.parse(b"\x05hello"), six.u("hello")) def test_build(self): s = PascalString("foo", encoding="utf8") - self.assertEqual(s.build(six.u("hello world")), six.b("\x0bhello world")) + self.assertEqual(s.build(six.u("hello world")), b"\x0bhello world") def test_parse_custom_length_field(self): s = PascalString("foo", length_field=UBInt16("length"), encoding="utf8") - self.assertEqual(s.parse(six.b("\x00\x05hello")), six.u("hello")) + self.assertEqual(s.parse(b"\x00\x05hello"), six.u("hello")) def test_build_custom_length_field(self): s = PascalString("foo", length_field=UBInt16("length"), encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("\x00\x05hello")) + self.assertEqual(s.build(six.u("hello")), b"\x00\x05hello") class TestCString(unittest.TestCase): def test_parse(self): s = CString("foo", encoding="utf8") - self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello")) + self.assertEqual(s.parse(b"hello\x00"), six.u("hello")) def test_build(self): s = CString("foo", encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("hello\x00")) + self.assertEqual(s.build(six.u("hello")), b"hello\x00") def test_parse_terminator(self): - s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") - self.assertEqual(s.parse(six.b("helloX")), six.u("hello")) - self.assertEqual(s.parse(six.b("helloY")), six.u("hello")) - self.assertEqual(s.parse(six.b("helloZ")), six.u("hello")) + s = CString("foo", terminators=b"XYZ", encoding="utf8") + self.assertEqual(s.parse(b"helloX"), six.u("hello")) + self.assertEqual(s.parse(b"helloY"), six.u("hello")) + self.assertEqual(s.parse(b"helloZ"), six.u("hello")) def test_build_terminator(self): - s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("helloX")) + s = CString("foo", terminators=b"XYZ", encoding="utf8") + self.assertEqual(s.build(six.u("hello")), b"helloX") class TestGreedyString(unittest.TestCase): def test_parse(self): s = GreedyString("foo", encoding="utf8") - self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello\x00")) + self.assertEqual(s.parse(b"hello\x00"), six.u("hello\x00")) def test_build(self): s = GreedyString("foo", encoding="utf8") - self.assertEqual(s.build(six.u("hello")), six.b("hello")) - - -if __name__ == "__main__": - #unittest.main() - s = CString("foo", encoding="utf8") - s.build(six.u("hello")) - - + self.assertEqual(s.build(six.u("hello")), b"hello")