over.misc.hexdump now accepts anything as long as it's convertible to bytes

This commit is contained in:
Martin 2017-10-05 16:36:09 +02:00
parent e699be5c6d
commit 73132dad6f

View file

@ -130,8 +130,10 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show
output_io = io.StringIO() if not output else output output_io = io.StringIO() if not output else output
if type(data) is not bytes: try:
raise ValueError("data must be bytes") data = bytes(data)
except:
raise ValueError("data must be bytes or similar")
offset_figures = math.ceil(math.log2(len(data)) / 8) * 2 if data else 2 offset_figures = math.ceil(math.log2(len(data)) / 8) * 2 if data else 2
format_str = "%%0%dx " %(offset_figures) format_str = "%%0%dx " %(offset_figures)