changeset 37158:e09d2183e226

templateutil: reimplement stringify() using flatten()
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Mar 2018 20:04:20 +0900
parents 888507ec655e
children b56b79185aad
files mercurial/templateutil.py
diffstat 1 files changed, 3 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templateutil.py	Sat Mar 17 20:00:54 2018 +0900
+++ b/mercurial/templateutil.py	Sat Mar 17 20:04:20 2018 +0900
@@ -263,18 +263,9 @@
 
 def stringify(thing):
     """Turn values into bytes by converting into text and concatenating them"""
-    thing = unwraphybrid(thing)
-    if util.safehasattr(thing, '__iter__') and not isinstance(thing, bytes):
-        if isinstance(thing, str):
-            # This is only reachable on Python 3 (otherwise
-            # isinstance(thing, bytes) would have been true), and is
-            # here to prevent infinite recursion bugs on Python 3.
-            raise error.ProgrammingError(
-                'stringify got unexpected unicode string: %r' % thing)
-        return "".join([stringify(t) for t in thing if t is not None])
-    if thing is None:
-        return ""
-    return pycompat.bytestr(thing)
+    if isinstance(thing, bytes):
+        return thing  # retain localstr to be round-tripped
+    return b''.join(flatten(thing))
 
 def findsymbolicname(arg):
     """Find symbolic name for the given compiled expression; returns None