From f8b9f983ad02d0af1fa7979d700cf7dbd3dbe3b1 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Oct 2017 14:28:15 +0200 Subject: [PATCH] improved over.types.ndict.__repr__ --- over/misc.py | 12 ++++++------ over/types.py | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/over/misc.py b/over/misc.py index a953cc2..803d34a 100644 --- a/over/misc.py +++ b/over/misc.py @@ -114,7 +114,7 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show """ Writes a hex dump of `data` to `output`. - The output text is indented with spaces and contains `offset` bytes per line. + The output text is indented with spaces and contains `width` bytes per line. If `show_header` is True, a single line with byte numbers preceeds all output. If `show_offsets` is True, each line is prefixed with the address of the first byte of that line. If `show_ascii` is True, each line is suffixed with its ASCII representation. Unprintable characters @@ -145,11 +145,11 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show if show_offsets: line.append("offset"[:offset_figures].ljust(offset_figures + 2)) - for i in range(offset): + for i in range(width): line.append("%2x" %(i)) if show_ascii: - line.append(" *{0}*".format("ASCII".center(offset, "-"))) + line.append(" *{0}*".format("ASCII".center(width, "-"))) output_io.write(" ".join(line) + "\n") @@ -163,7 +163,7 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show hex_bytes = [] ascii_bytes = [] - for local_i, i in enumerate(range(ptr, ptr+offset)): + for local_i, i in enumerate(range(ptr, ptr+width)): if i < len(data): c = data[i] hex_bytes.append("%02x" %(c)) @@ -173,7 +173,7 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show else: ascii_bytes.append(".") elif i == len(data): - hex_bytes.extend([" "] * (offset - local_i)) + hex_bytes.extend([" "] * (width - local_i)) if use_colors: output_io.write(text.render("")) output_io.write(" ".join(hex_bytes)) @@ -186,7 +186,7 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show output_io.write("\n") - ptr += offset + ptr += width if not output: output_io.seek(0) diff --git a/over/types.py b/over/types.py index db19466..19c18d9 100644 --- a/over/types.py +++ b/over/types.py @@ -26,7 +26,9 @@ class ndict: object.__setattr__(self, "d", OrderedDict(*args, **kwargs)) def __repr__(self): - return "|" + repr(self.d) + atoms = ["(%s, %s)" %(repr(k), repr(v)) for k, v in self.items()] + + return "ndict([" + ", ".join(atoms) + "])" def __iter__(self): return self.d.__iter__()