# HG changeset patch # User Yuya Nishihara <y...@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""" _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel