[PATCH 7 of 8] templater: extract private function to evaluate generator to byte string
Yuya Nishihara
yuya at tcha.org
Sun Apr 1 02:46:04 UTC 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521808816 -32400
# Fri Mar 23 21:40:16 2018 +0900
# Node ID 5d5ecd0c1e91676bc1ac6a481679cad21fb0e108
# Parent d7a44391a574f6526d4d14925abe1dce048a83e3
templater: extract private function to evaluate generator to byte string
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -308,6 +308,12 @@ def findsymbolicname(arg):
else:
return None
+def _unthunk(context, thing):
+ """Evaluate a lazy byte string into value"""
+ if not isinstance(thing, types.GeneratorType):
+ return thing
+ return stringify(context, 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)"""
@@ -325,9 +331,7 @@ def _unwrapvalue(context, thing):
thing = unwrapvalue(context, 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, thing)
- return thing
+ return _unthunk(context, thing)
def evalboolean(context, mapping, arg):
"""Evaluate given argument as boolean, but also takes boolean literals"""
More information about the Mercurial-devel
mailing list