Add some pretty formating helper functions
This commit is contained in:
parent
45f088fa2b
commit
51a4d35823
1 changed files with 27 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
||||||
|
#
|
||||||
|
# Pretty formating helpers
|
||||||
|
#
|
||||||
|
def pretty_format_value(value, encoding='utf8'):
|
||||||
|
if isinstance(value, dict):
|
||||||
|
return pretty_format_dict(value)
|
||||||
|
if isinstance(value, list):
|
||||||
|
return ",".join([pretty_format_value(x) for x in value])
|
||||||
|
elif isinstance(value, bytes):
|
||||||
|
return "'%s'" % value.decode(encoding, errors='replace')
|
||||||
|
elif isinstance(value, str):
|
||||||
|
return "'%s'" % value
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def pretty_format_dict(attrs):
|
||||||
|
result = []
|
||||||
|
for attr in sorted(attrs.keys()):
|
||||||
|
result.append(" - %s : %s" % (attr, pretty_format_value(attrs[attr])))
|
||||||
|
return "\n".join(result)
|
||||||
|
|
||||||
|
|
||||||
|
def pretty_format_list(row):
|
||||||
|
result = []
|
||||||
|
for idx, values in enumerate(row):
|
||||||
|
result.append(" - #%s : %s" % (idx, pretty_format_value(values)))
|
||||||
|
return "\n".join(result)
|
Loading…
Reference in a new issue