Skip to content

Commit

Permalink
Removed six from remaining modules, only six.u remains
Browse files Browse the repository at this point in the history
  • Loading branch information
arekbulski committed Aug 25, 2016
1 parent 3f911aa commit efd6171
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 288 deletions.
3 changes: 2 additions & 1 deletion 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):
Expand Down
5 changes: 3 additions & 2 deletions construct/formats/data/snoop.py
Expand Up @@ -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 """
Expand Down
3 changes: 1 addition & 2 deletions construct/formats/executable/elf32.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions construct/formats/executable/pe32.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions construct/formats/filesystem/fat16.py
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions construct/formats/filesystem/mbr.py
Expand Up @@ -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",
Expand Down Expand Up @@ -46,7 +46,7 @@
UBInt32("size"), # in sectors
)
),
Const(Bytes("signature", 2), six.b("\x55\xAA")),
Const(Bytes("signature", 2), b"\x55\xAA"),
)


Expand Down
5 changes: 2 additions & 3 deletions construct/formats/graphics/gif.py
Expand Up @@ -19,7 +19,6 @@
Comment Extension
"""
from construct import *
import six


data_sub_block = Struct("data_sub_block",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions 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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions construct/protocols/ipstack.py
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions 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



Expand Down Expand Up @@ -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)))
Expand Down
6 changes: 3 additions & 3 deletions 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):
Expand Down Expand Up @@ -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)))
Expand Down
6 changes: 3 additions & 3 deletions construct/protocols/layer3/dhcpv4.py
Expand Up @@ -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",
Expand Down Expand Up @@ -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)),
)

Expand Down
5 changes: 2 additions & 3 deletions construct/protocols/layer3/dhcpv6.py
Expand Up @@ -5,7 +5,6 @@
"""
from construct import *
from ipv6 import Ipv6Address
import six


dhcp_option = Struct("dhcp_option",
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions 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",
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions construct/protocols/layer3/igmpv2.py
Expand Up @@ -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"),
Expand All @@ -25,5 +25,5 @@
)

if __name__ == '__main__':
capture = unhexlify(six.b("1600FA01EFFFFFFD"))
capture = unhexlify(b"1600FA01EFFFFFFD")
print (igmpv2_header.parse(capture))
9 changes: 2 additions & 7 deletions 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):
Expand Down Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions 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):
Expand Down
6 changes: 3 additions & 3 deletions 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",
Expand Down Expand Up @@ -36,7 +36,7 @@
)

if __name__ == "__main__":
cap = unhexlify(six.b("0db5005062303fb21836e9e650184470c9bc0000"))
cap = unhexlify(b"0db5005062303fb21836e9e650184470c9bc0000")

obj = tcp_header.parse(cap)
print (obj)
Expand Down
6 changes: 3 additions & 3 deletions 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),
Expand All @@ -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)))
Expand Down

0 comments on commit efd6171

Please sign in to comment.