Patchwork D3359: stringutil: make b prefixes on string output optional

login
register
mail settings
Submitter phabricator
Date April 16, 2018, 11:22 p.m.
Message ID <161785c0054bc795546306bb3d9fae7a@localhost.localdomain>
Download mbox | patch
Permalink /patch/31142/
State Not Applicable
Headers show

Comments

phabricator - April 16, 2018, 11:22 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf7194c925003: stringutil: make b prefixes on string output optional (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3359?vs=8273&id=8353

REVISION DETAIL
  https://phab.mercurial-scm.org/D3359

AFFECTED FILES
  mercurial/utils/stringutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -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):