From ed6156c3c647c4559aa15e1be161a6918861ddbc Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Tue, 18 Jul 2017 10:15:47 -0700 Subject: [PATCH] Hexdump, better __str__ for ByteBuffer We broke str(ByteBuffer) with the util.py commit, but having that return a possibly megabytes-long string was stupid anyway. It now returns a string just indicating that it's not really a printable thing rather than the still probably extremely long repr(). Added a hexdump function to call util.hexdump cleanly. This is really only here for debugging. I can imagine a lot of things you could do to account for possibilities later on, but YAGNI applies (including that if you do need it, you can add it then.) --- blocksfree/buffer/bytebuffer.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/blocksfree/buffer/bytebuffer.py b/blocksfree/buffer/bytebuffer.py index 88f1501..68e5dfe 100644 --- a/blocksfree/buffer/bytebuffer.py +++ b/blocksfree/buffer/bytebuffer.py @@ -126,10 +126,14 @@ class ByteBuffer(BufferType): return 'ByteBuffer({_buf}, {_changed}, {_locked})'.format_map( vars(self)) - def __str__(self): - """Return str(self) + def __str__(self) -> str: + """Implement str(self)""" + return ''.format(len(self._buf)) - This will be a very long string containing newlines for any buffer of - non-trivial length + def hexdump(self, *args: List, **kwargs: Dict) -> None: + """Performas a canonical hexdump of self. + + Args: + Any for blocksfree.util.hexdump, see that function for details. """ - return '\n'.join(gen_hexdump(self._buf)) + util.hexdump(self._buf, *args, **kwargs)