##// END OF EJS Templates
stringutil: make b prefixes on string output optional...
Augie Fackler -
r37768:f7194c92 default
parent child Browse files
Show More
@@ -23,19 +23,23 b' from .. import ('
23 pycompat,
23 pycompat,
24 )
24 )
25
25
26 def pprint(o):
26 def pprint(o, bprefix=True):
27 """Pretty print an object."""
27 """Pretty print an object."""
28 if isinstance(o, bytes):
28 if isinstance(o, bytes):
29 return "b'%s'" % escapestr(o)
29 if bprefix:
30 return "b'%s'" % escapestr(o)
31 return "'%s'" % escapestr(o)
30 elif isinstance(o, bytearray):
32 elif isinstance(o, bytearray):
31 # codecs.escape_encode() can't handle bytearray, so escapestr fails
33 # codecs.escape_encode() can't handle bytearray, so escapestr fails
32 # without coercion.
34 # without coercion.
33 return "bytearray['%s']" % escapestr(bytes(o))
35 return "bytearray['%s']" % escapestr(bytes(o))
34 elif isinstance(o, list):
36 elif isinstance(o, list):
35 return '[%s]' % (b', '.join(pprint(a) for a in o))
37 return '[%s]' % (b', '.join(pprint(a, bprefix=bprefix) for a in o))
36 elif isinstance(o, dict):
38 elif isinstance(o, dict):
37 return '{%s}' % (b', '.join(
39 return '{%s}' % (b', '.join(
38 '%s: %s' % (pprint(k), pprint(v)) for k, v in sorted(o.items())))
40 '%s: %s' % (pprint(k, bprefix=bprefix),
41 pprint(v, bprefix=bprefix))
42 for k, v in sorted(o.items())))
39 elif isinstance(o, bool):
43 elif isinstance(o, bool):
40 return b'True' if o else b'False'
44 return b'True' if o else b'False'
41 elif isinstance(o, int):
45 elif isinstance(o, int):
General Comments 0
You need to be logged in to leave comments. Login now