util: cut off long data by default
This commit is contained in:
parent
6b972ac877
commit
ac8d019ad7
|
@ -38,8 +38,13 @@ def indent(s: str, count: int, start: bool = False) -> str:
|
|||
lines[i] = ' ' * count + lines[i]
|
||||
return '\n'.join(lines)
|
||||
|
||||
def format_bytes(bs: bytes) -> str:
|
||||
return '[' + ' '.join(hex(b)[2:].zfill(2) for b in bs) + ']'
|
||||
def format_bytes(bs: bytes, cutoff=256) -> str:
|
||||
if len(bs) > 256:
|
||||
trailer = ' ...'
|
||||
bs = bs[:cutoff]
|
||||
else:
|
||||
trailer = ''
|
||||
return '[' + ' '.join(hex(b)[2:].zfill(2) for b in bs) + trailer + ']'
|
||||
|
||||
def format_value(value: Any, formatter: Callable[[Any], str], indentation: int = 0) -> str:
|
||||
""" Format containers to use the given formatter function instead of always repr(). """
|
||||
|
|
Loading…
Reference in New Issue