27 lines
819 B
Python
27 lines
819 B
Python
#
|
|
# 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)
|