Merge pull request #5 from npetroni/binary-format-hint

added Bin() to format_hints: print the value as a Python binary number
This commit is contained in:
ikelos
2017-04-20 14:15:19 +01:00
committed by GitHub
2 changed files with 5 additions and 1 deletions
@@ -5,6 +5,9 @@ These hints allow a plugin to indicate how they'd like a particular column's dat
Text renderers should attempt to honour all hints provided in this module where possible
"""
class Bin(int):
"""A class to indicate that the integer value should be represented as a binary value"""
class Hex(int):
"""A class to indicate that the integer value should be represented as a hexidecimal value"""
+2 -1
View File
@@ -25,7 +25,8 @@ def hex_bytes_as_text(value):
class QuickTextRenderer(interfaces.renderers.Renderer):
type_renderers = {format_hints.Hex: lambda x: "{:x}".format(x),
type_renderers = {format_hints.Bin: lambda x: "{:b}".format(x),
format_hints.Hex: lambda x: "{:x}".format(x),
format_hints.HexBytes: hex_bytes_as_text,
bytes: lambda x: x.decode("utf-8"),
'default': lambda x: "{}".format(x)}