Mercurial > hg-stable
changeset 37750:f7194c925003
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
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 13 Apr 2018 23:57:57 -0400 |
parents | 73d0a3dd7e53 |
children | 483de34f23b1 |
files | mercurial/utils/stringutil.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/utils/stringutil.py Fri Apr 13 23:55:37 2018 -0400 +++ b/mercurial/utils/stringutil.py Fri Apr 13 23:57:57 2018 -0400 @@ -23,19 +23,23 @@ pycompat, ) -def pprint(o): +def pprint(o, bprefix=True): """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): - 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( - '%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):