changeset 37278:671a01cd50b5

templater: extract private function to evaluate generator to byte string
author Yuya Nishihara <yuya@tcha.org>
date Fri, 23 Mar 2018 21:40:16 +0900
parents 9e8128e84326
children 26f6fc179e62
files mercurial/templateutil.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templateutil.py	Sun Mar 18 23:14:21 2018 +0900
+++ b/mercurial/templateutil.py	Fri Mar 23 21:40:16 2018 +0900
@@ -313,6 +313,12 @@
         else:
             return None
 
+def _unthunk(context, mapping, thing):
+    """Evaluate a lazy byte string into value"""
+    if not isinstance(thing, types.GeneratorType):
+        return thing
+    return stringify(context, mapping, thing)
+
 def evalrawexp(context, mapping, arg):
     """Evaluate given argument as a bare template object which may require
     further processing (such as folding generator of strings)"""
@@ -330,9 +336,7 @@
     thing = unwrapvalue(context, mapping, thing)
     # evalrawexp() may return string, generator of strings or arbitrary object
     # such as date tuple, but filter does not want generator.
-    if isinstance(thing, types.GeneratorType):
-        thing = stringify(context, mapping, thing)
-    return thing
+    return _unthunk(context, mapping, thing)
 
 def evalboolean(context, mapping, arg):
     """Evaluate given argument as boolean, but also takes boolean literals"""