Implement repr() and str() for ByteBuffer

I'm not sure using a hexdump makes sense for str() here, but I don't know what
else does yet.  I also know that I want a buffer to be hexdumpable, although I
think I'd prefer something that allows a hexdump not to require a huge amount
of memory.  Until we start processing HFS, I don't need to dwell on that too
much.  Let's get it working first.
This commit is contained in:
T. Joseph Carter 2017-07-16 11:37:52 -07:00
parent 6a91b5eb27
commit 96c63a90d8
1 changed files with 17 additions and 0 deletions

View File

@ -18,6 +18,7 @@
from typing import Optional, Union
from .buffertype import BufferType
from ..util import gen_hexdump
class ByteBuffer(BufferType):
"""ByteBuffer(bytes_or_int[, changed[, locked]]) -> ByteBuffer
@ -116,3 +117,19 @@ class ByteBuffer(BufferType):
@locked.setter
def locked(self, value: bool) -> None:
self._locked = value
def __repr__(self):
"""Return repr(self)
This will be a very long string for any buffer of non-trivial length
"""
return 'ByteBuffer({_buf}, {_changed}, {_locked})'.format_map(
vars(self))
def __str__(self):
"""Return str(self)
This will be a very long string containing newlines for any buffer of
non-trivial length
"""
return '\n'.join(gen_hexdump(self._buf))