Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions kaitaistruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import struct
from io import open, BytesIO, SEEK_CUR, SEEK_END # noqa
from reprlib import Repr, recursive_repr

PY2 = sys.version_info[0] == 2

Expand All @@ -23,6 +24,17 @@
# pylint: disable=invalid-name,missing-docstring,too-many-public-methods
# pylint: disable=useless-object-inheritance,super-with-arguments,consider-using-f-string

reprer = Repr()
reprer.maxother = sys.maxsize * 2 + 1

@recursive_repr()
def repr_generator_for_all_props(self):
"""Generator to use in own __repr__ functions."""
return (
"".join(( str(k), "=", reprer.repr(getattr(self, k)) ))
for k in dir(self)
if k[0] != "_" and not hasattr(KaitaiStruct, k) and not isinstance(getattr(self, k), type)
)

class KaitaiStruct(object):
def __init__(self, stream):
Expand All @@ -34,6 +46,16 @@ def __enter__(self):
def __exit__(self, *args, **kwargs):
self.close()

def __repr__(self):
return "".join(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are too much line-breaks for my gusto.

(
self.__class__.__name__,
"(",
", ".join( repr_generator_for_all_props(self) ),
")"
)
)

def close(self):
self._io.close()

Expand Down