mirror of
https://github.com/iKarith/cppo-ng.git
synced 2025-02-14 21:30:50 +00:00
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:
parent
6a91b5eb27
commit
96c63a90d8
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user