Skip to content
Snippets Groups Projects
Commit f7194c92 authored by Augie Fackler's avatar Augie Fackler
Browse files

stringutil: make b prefixes on string output optional

I need this to preserve some behavior in hook.py.

Differential Revision: https://phab.mercurial-scm.org/D3359
parent 73d0a3dd
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,6 @@
pycompat,
)
def pprint(o):
def pprint(o, bprefix=True):
"""Pretty print an object."""
if isinstance(o, bytes):
......@@ -27,8 +27,10 @@
"""Pretty print an object."""
if isinstance(o, bytes):
return "b'%s'" % escapestr(o)
if bprefix:
return "b'%s'" % escapestr(o)
return "'%s'" % escapestr(o)
elif isinstance(o, bytearray):
# codecs.escape_encode() can't handle bytearray, so escapestr fails
# without coercion.
return "bytearray['%s']" % escapestr(bytes(o))
elif isinstance(o, list):
......@@ -30,8 +32,8 @@
elif isinstance(o, bytearray):
# codecs.escape_encode() can't handle bytearray, so escapestr fails
# without coercion.
return "bytearray['%s']" % escapestr(bytes(o))
elif isinstance(o, list):
return '[%s]' % (b', '.join(pprint(a) for a in o))
return '[%s]' % (b', '.join(pprint(a, bprefix=bprefix) for a in o))
elif isinstance(o, dict):
return '{%s}' % (b', '.join(
......@@ -36,6 +38,8 @@
elif isinstance(o, dict):
return '{%s}' % (b', '.join(
'%s: %s' % (pprint(k), pprint(v)) for k, v in sorted(o.items())))
'%s: %s' % (pprint(k, bprefix=bprefix),
pprint(v, bprefix=bprefix))
for k, v in sorted(o.items())))
elif isinstance(o, bool):
return b'True' if o else b'False'
elif isinstance(o, int):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment