##// END OF EJS Templates
stringutil: support more types with pprint()...
Gregory Szorc -
r37637:68132a95 default
parent child Browse files
Show More
@@ -25,8 +25,12 b' from .. import ('
25
25
26 def pprint(o):
26 def pprint(o):
27 """Pretty print an object."""
27 """Pretty print an object."""
28 if isinstance(o, (bytes, bytearray)):
28 if isinstance(o, bytes):
29 return "b'%s'" % escapestr(o)
29 return "b'%s'" % escapestr(o)
30 elif isinstance(o, bytearray):
31 # codecs.escape_encode() can't handle bytearray, so escapestr fails
32 # without coercion.
33 return "bytearray['%s']" % escapestr(bytes(o))
30 elif isinstance(o, list):
34 elif isinstance(o, list):
31 return '[%s]' % (b', '.join(pprint(a) for a in o))
35 return '[%s]' % (b', '.join(pprint(a) for a in o))
32 elif isinstance(o, dict):
36 elif isinstance(o, dict):
@@ -34,6 +38,10 b' def pprint(o):'
34 '%s: %s' % (pprint(k), pprint(v)) for k, v in sorted(o.items())))
38 '%s: %s' % (pprint(k), pprint(v)) for k, v in sorted(o.items())))
35 elif isinstance(o, bool):
39 elif isinstance(o, bool):
36 return b'True' if o else b'False'
40 return b'True' if o else b'False'
41 elif isinstance(o, int):
42 return '%d' % o
43 elif isinstance(o, float):
44 return '%f' % o
37 else:
45 else:
38 raise error.ProgrammingError('do not know how to format %r' % o)
46 raise error.ProgrammingError('do not know how to format %r' % o)
39
47
General Comments 0
You need to be logged in to leave comments. Login now