Skip to content

Commit

Permalink
Merge pull request #43 from joachimmetz/master
Browse files Browse the repository at this point in the history
Replaced most calls to parent classes by super.
  • Loading branch information
arekbulski committed Aug 22, 2016
2 parents fe43aaf + a292b54 commit 4106be2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
30 changes: 15 additions & 15 deletions construct/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BitIntegerAdapter(Adapter):
__slots__ = ["width", "swapped", "signed", "bytesize"]
def __init__(self, subcon, width, swapped = False, signed = False,
bytesize = 8):
Adapter.__init__(self, subcon)
super(BitIntegerAdapter, self).__init__(subcon)
self.width = width
self.swapped = swapped
self.signed = signed
Expand Down Expand Up @@ -80,7 +80,7 @@ class MappingAdapter(Adapter):
__slots__ = ["encoding", "decoding", "encdefault", "decdefault"]
def __init__(self, subcon, decoding, encoding,
decdefault = NotImplemented, encdefault = NotImplemented):
Adapter.__init__(self, subcon)
super(MappingAdapter, self).__init__(subcon)
self.decoding = decoding
self.encoding = encoding
self.decdefault = decdefault
Expand Down Expand Up @@ -116,7 +116,7 @@ class FlagsAdapter(Adapter):
"""
__slots__ = ["flags"]
def __init__(self, subcon, flags):
Adapter.__init__(self, subcon)
super(FlagsAdapter, self).__init__(subcon)
self.flags = flags
def _encode(self, obj, context):
flags = 0
Expand All @@ -141,7 +141,7 @@ class StringAdapter(Adapter):
"""
__slots__ = ["encoding"]
def __init__(self, subcon, encoding = None):
Adapter.__init__(self, subcon)
super(StringAdapter, self).__init__(subcon)
self.encoding = encoding
def _encode(self, obj, context):
if self.encoding:
Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(self, subcon, padchar = six.b("\x00"), paddir = "right", trimdir =
raise ValueError("paddir must be 'right', 'left' or 'center'", paddir)
if trimdir not in ("right", "left"):
raise ValueError("trimdir must be 'right' or 'left'", trimdir)
Adapter.__init__(self, subcon)
super(PaddedStringAdapter, self).__init__(subcon)
self.padchar = padchar
self.paddir = paddir
self.trimdir = trimdir
Expand Down Expand Up @@ -230,7 +230,7 @@ class CStringAdapter(StringAdapter):
"""
__slots__ = ["terminators"]
def __init__(self, subcon, terminators = six.b("\x00"), encoding = None):
StringAdapter.__init__(self, subcon, encoding = encoding)
super(CStringAdapter, self).__init__(subcon, encoding = encoding)
self.terminators = terminators
def _encode(self, obj, context):
return StringAdapter._encode(self, obj, context) + self.terminators[0:1]
Expand Down Expand Up @@ -262,7 +262,7 @@ class TunnelAdapter(Adapter):
"""
__slots__ = ["inner_subcon"]
def __init__(self, subcon, inner_subcon):
Adapter.__init__(self, subcon)
super(TunnelAdapter, self).__init__(subcon)
self.inner_subcon = inner_subcon
def _decode(self, obj, context):
return self.inner_subcon._parse(BytesIO(obj), context)
Expand Down Expand Up @@ -290,7 +290,7 @@ class ExprAdapter(Adapter):
"""
__slots__ = ["_encode", "_decode"]
def __init__(self, subcon, encoder, decoder):
Adapter.__init__(self, subcon)
super(ExprAdapter, self).__init__(subcon)
self._encode = encoder
self._decode = decoder

Expand All @@ -300,7 +300,7 @@ class HexDumpAdapter(Adapter):
"""
__slots__ = ["linesize"]
def __init__(self, subcon, linesize = 16):
Adapter.__init__(self, subcon)
super(HexDumpAdapter, self).__init__(subcon)
self.linesize = linesize
def _encode(self, obj, context):
return obj
Expand All @@ -321,7 +321,7 @@ class ConstAdapter(Adapter):
"""
__slots__ = ["value"]
def __init__(self, subcon, value):
Adapter.__init__(self, subcon)
super(ConstAdapter, self).__init__(subcon)
self.value = value
def _encode(self, obj, context):
if obj is None or obj == self.value:
Expand All @@ -344,7 +344,7 @@ class SlicingAdapter(Adapter):
"""
__slots__ = ["start", "stop", "step"]
def __init__(self, subcon, start, stop = None):
Adapter.__init__(self, subcon)
super(SlicingAdapter, self).__init__(subcon)
self.start = start
self.stop = stop
def _encode(self, obj, context):
Expand All @@ -363,7 +363,7 @@ class IndexingAdapter(Adapter):
"""
__slots__ = ["index"]
def __init__(self, subcon, index):
Adapter.__init__(self, subcon)
super(IndexingAdapter, self).__init__(subcon)
if type(index) is not int:
raise TypeError("index must be an integer", type(index))
self.index = index
Expand All @@ -383,7 +383,7 @@ class PaddingAdapter(Adapter):
"""
__slots__ = ["pattern", "strict"]
def __init__(self, subcon, pattern = six.b("\x00"), strict = False):
Adapter.__init__(self, subcon)
super(PaddingAdapter, self).__init__(subcon)
self.pattern = pattern
self.strict = strict
def _encode(self, obj, context):
Expand Down Expand Up @@ -441,7 +441,7 @@ class OneOf(Validator):
"""
__slots__ = ["valids"]
def __init__(self, subcon, valids):
Validator.__init__(self, subcon)
super(OneOf, self).__init__(subcon)
self.valids = valids
def _validate(self, obj, context):
return obj in self.valids
Expand All @@ -464,7 +464,7 @@ class NoneOf(Validator):
"""
__slots__ = ["invalids"]
def __init__(self, subcon, invalids):
Validator.__init__(self, subcon)
super(NoneOf, self).__init__(subcon)
self.invalids = invalids
def _validate(self, obj, context):
return obj not in self.invalids
52 changes: 26 additions & 26 deletions construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Subconstruct(Construct):

__slots__ = ["subcon"]
def __init__(self, subcon):
Construct.__init__(self, subcon.name, subcon.conflags)
super(Subconstruct, self).__init__(subcon.name, subcon.conflags)
self.subcon = subcon
def _parse(self, stream, context):
return self.subcon._parse(stream, context)
Expand Down Expand Up @@ -322,7 +322,7 @@ class StaticField(Construct):

__slots__ = ["length"]
def __init__(self, name, length):
Construct.__init__(self, name)
super(StaticField, self).__init__(name)
self.length = length
def _parse(self, stream, context):
return _read_stream(stream, self.length)
Expand Down Expand Up @@ -350,14 +350,14 @@ def __init__(self, name, endianity, format):
if len(format) != 1:
raise ValueError("must specify one and only one format char")
self.packer = Packer(endianity + format)
StaticField.__init__(self, name, self.packer.size)
super(FormatField, self).__init__(name, self.packer.size)
def __getstate__(self):
attrs = StaticField.__getstate__(self)
attrs = super(FormatField, self).__getstate__()
attrs["packer"] = attrs["packer"].format
return attrs
def __setstate__(self, attrs):
attrs["packer"] = Packer(attrs["packer"])
return StaticField.__setstate__(self, attrs)
return super(FormatField, self).__setstate__(attrs)
def _parse(self, stream, context):
try:
return self.packer.unpack(_read_stream(stream, self.length))[0]
Expand Down Expand Up @@ -391,7 +391,7 @@ class MetaField(Construct):

__slots__ = ["lengthfunc"]
def __init__(self, name, lengthfunc):
Construct.__init__(self, name)
super(MetaField, self).__init__(name)
self.lengthfunc = lengthfunc
self._set_flag(self.FLAG_DYNAMIC)
def _parse(self, stream, context):
Expand Down Expand Up @@ -424,7 +424,7 @@ class MetaArray(Subconstruct):
"""
__slots__ = ["countfunc"]
def __init__(self, countfunc, subcon):
Subconstruct.__init__(self, subcon)
super(MetaArray, self).__init__(subcon)
self.countfunc = countfunc
self._clear_flag(self.FLAG_COPY_CONTEXT)
self._set_flag(self.FLAG_DYNAMIC)
Expand Down Expand Up @@ -507,7 +507,7 @@ class Range(Subconstruct):

__slots__ = ["mincount", "maxcout"]
def __init__(self, mincount, maxcout, subcon):
Subconstruct.__init__(self, subcon)
super(Range, self).__init__(subcon)
self.mincount = mincount
self.maxcout = maxcout
self._clear_flag(self.FLAG_COPY_CONTEXT)
Expand Down Expand Up @@ -576,7 +576,7 @@ class RepeatUntil(Subconstruct):
"""
__slots__ = ["predicate"]
def __init__(self, predicate, subcon):
Subconstruct.__init__(self, subcon)
super(RepeatUntil, self).__init__(subcon)
self.predicate = predicate
self._clear_flag(self.FLAG_COPY_CONTEXT)
self._set_flag(self.FLAG_DYNAMIC)
Expand Down Expand Up @@ -650,7 +650,7 @@ def __init__(self, name, *subcons, **kw):
self.allow_overwrite = kw.pop("allow_overwrite", False)
if kw:
raise TypeError("the only keyword argument accepted is 'nested'", kw)
Construct.__init__(self, name)
super(Struct, self).__init__(name)
self.subcons = subcons
self._inherit_flags(*subcons)
self._clear_flag(self.FLAG_EMBED)
Expand Down Expand Up @@ -777,7 +777,7 @@ class Union(Construct):
"""
__slots__ = ["parser", "builder"]
def __init__(self, name, master, *subcons, **kw):
Construct.__init__(self, name)
super(Union, self).__init__(name)
args = [Peek(sc) for sc in subcons]
args.append(MetaField(None, lambda ctx: master._sizeof(ctx)))
self.parser = Struct(name, Peek(master, perform_build = True), *args)
Expand Down Expand Up @@ -838,7 +838,7 @@ def _sizeof(self, context):

def __init__(self, name, keyfunc, cases, default = NoDefault,
include_key = False):
Construct.__init__(self, name)
super(Switch, self).__init__(name)
self._inherit_flags(*cases.values())
self.keyfunc = keyfunc
self.cases = cases
Expand Down Expand Up @@ -892,7 +892,7 @@ def __init__(self, name, *subcons, **kw):
if kw:
raise TypeError("the only keyword argument accepted "
"is 'include_name'", kw)
Construct.__init__(self, name)
super(Select, self).__init__(name)
self.subcons = subcons
self.include_name = include_name
self._inherit_flags(*subcons)
Expand Down Expand Up @@ -965,7 +965,7 @@ class Pointer(Subconstruct):
"""
__slots__ = ["offsetfunc"]
def __init__(self, offsetfunc, subcon):
Subconstruct.__init__(self, subcon)
super(Pointer, self).__init__(subcon)
self.offsetfunc = offsetfunc
def _parse(self, stream, context):
newpos = self.offsetfunc(context)
Expand Down Expand Up @@ -1001,7 +1001,7 @@ class Peek(Subconstruct):
"""
__slots__ = ["perform_build"]
def __init__(self, subcon, perform_build = False):
Subconstruct.__init__(self, subcon)
super(Peek, self).__init__(subcon)
self.perform_build = perform_build
def _parse(self, stream, context):
pos = stream.tell()
Expand Down Expand Up @@ -1043,7 +1043,7 @@ class OnDemand(Subconstruct):
"""
__slots__ = ["advance_stream", "force_build"]
def __init__(self, subcon, advance_stream = True, force_build = True):
Subconstruct.__init__(self, subcon)
super(OnDemand, self).__init__(subcon)
self.advance_stream = advance_stream
self.force_build = force_build
def _parse(self, stream, context):
Expand Down Expand Up @@ -1086,7 +1086,7 @@ class Buffered(Subconstruct):
"""
__slots__ = ["encoder", "decoder", "resizer"]
def __init__(self, subcon, decoder, encoder, resizer):
Subconstruct.__init__(self, subcon)
super(Buffered, self).__init__(subcon)
self.encoder = encoder
self.decoder = decoder
self.resizer = resizer
Expand Down Expand Up @@ -1136,7 +1136,7 @@ class Restream(Subconstruct):
"""
__slots__ = ["stream_reader", "stream_writer", "resizer"]
def __init__(self, subcon, stream_reader, stream_writer, resizer):
Subconstruct.__init__(self, subcon)
super(Restream, self).__init__(subcon)
self.stream_reader = stream_reader
self.stream_writer = stream_writer
self.resizer = resizer
Expand Down Expand Up @@ -1172,8 +1172,8 @@ class Reconfig(Subconstruct):
"""
__slots__ = []
def __init__(self, name, subcon, setflags = 0, clearflags = 0):
Construct.__init__(self, name, subcon.conflags)
self.subcon = subcon
subcon.name = name
super(Reconfig, self).__init__(subcon)
self._set_flag(setflags)
self._clear_flag(clearflags)

Expand Down Expand Up @@ -1222,7 +1222,7 @@ class Value(Construct):
"""
__slots__ = ["func"]
def __init__(self, name, func):
Construct.__init__(self, name)
super(Value, self).__init__(name)
self.func = func
self._set_flag(self.FLAG_DYNAMIC)
def _parse(self, stream, context):
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def _sizeof(self, context):
# """
# __slots__ = ["factoryfunc"]
# def __init__(self, name, factoryfunc):
# Construct.__init__(self, name, self.FLAG_COPY_CONTEXT)
# super(Dynamic, self).__init__(name, self.FLAG_COPY_CONTEXT)
# self.factoryfunc = factoryfunc
# self._set_flag(self.FLAG_DYNAMIC)
# def _parse(self, stream, context):
Expand All @@ -1284,7 +1284,7 @@ class LazyBound(Construct):
"""
__slots__ = ["bindfunc", "bound"]
def __init__(self, name, bindfunc):
Construct.__init__(self, name)
super(LazyBound, self).__init__(name)
self.bound = None
self.bindfunc = bindfunc
def _parse(self, stream, context):
Expand Down Expand Up @@ -1383,14 +1383,14 @@ class ULInt24(StaticField):
__slots__ = ["packer"]
def __init__(self, name):
self.packer = Packer("<BH")
StaticField.__init__(self, name, self.packer.size)
super(ULInt24, self).__init__(name, self.packer.size)
def __getstate__(self):
attrs = StaticField.__getstate__(self)
attrs = super(ULInt24, self).__getstate__()
attrs["packer"] = attrs["packer"].format
return attrs
def __setstate__(self, attrs):
attrs["packer"] = Packer(attrs["packer"])
return StaticField.__setstate__(self, attrs)
return super(ULInt24, self).__setstate__(attrs)
def _parse(self, stream, context):
try:
vals = self.packer.unpack(_read_stream(stream, self.length))
Expand Down
2 changes: 1 addition & 1 deletion construct/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Probe(Construct):
def __init__(self, name = None, show_stream = True,
show_context = True, show_stack = True,
stream_lookahead = 100):
Construct.__init__(self, None)
super(Probe, self).__init__(None)
if name is None:
Probe.counter += 1
name = "<unnamed %d>" % (Probe.counter,)
Expand Down
2 changes: 1 addition & 1 deletion construct/formats/executable/pe32.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NamedSequence(Adapter):
__slots__ = ["mapping", "rev_mapping"]
prefix = "unnamed_"
def __init__(self, subcon, mapping):
Adapter.__init__(self, subcon)
super(NamedSequence, self).__init__(subcon)
self.mapping = mapping
self.rev_mapping = dict((v, k) for k, v in mapping.items())
def _encode(self, obj, context):
Expand Down
4 changes: 2 additions & 2 deletions construct/formats/filesystem/fat16.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __str__(self):

class Directory(File):
def __init__(self, dirEntry, fs, children=None):
File.__init__(self, dirEntry, fs)
super(Directory, self).__init__(dirEntry, fs)
self.children = children
if not self.children:
self.children = File.fromDirEntries(\
Expand All @@ -151,7 +151,7 @@ class FatFs(Directory):
def __init__(self, stream):
self.stream = stream
self.pdr = PreDataRegion("pdr").parse_stream(stream)
Directory.__init__(self, dirEntry = None,
super(FatFs, self).__init__(dirEntry = None,
fs = self, children = File.fromDirEntries(
self.pdr.rootdirs, self))

Expand Down

0 comments on commit 4106be2

Please sign in to comment.