proxyclient: utils.py: allow to specify print function to chexdump

Signed-off-by: Sven Peter <sven@svenpeter.dev>
This commit is contained in:
Sven Peter 2021-12-13 16:31:49 +01:00 committed by Hector Martin
parent 0a4d2ca222
commit 6445cf61ba

View file

@ -29,17 +29,17 @@ def _ascii(s):
s2 += chr(c)
return s2
def chexdump(s, st=0, abbreviate=True, indent=""):
def chexdump(s, st=0, abbreviate=True, indent="", print_fn=print):
last = None
skip = False
for i in range(0,len(s),16):
val = s[i:i+16]
if val == last and abbreviate:
if not skip:
print(indent+"%08x *" % (i + st))
print_fn(indent+"%08x *" % (i + st))
skip = True
else:
print(indent+"%08x %s %s |%s|" % (
print_fn(indent+"%08x %s %s |%s|" % (
i + st,
hexdump(val[:8], ' ').ljust(23),
hexdump(val[8:], ' ').ljust(23),