changeset 26124:604a7c941103

templater: extract helper that evaluates filter or function argument It will be used to get a date tuple from an argument. Perhaps some of "stringify(args[n][0], ...)" can be replaced by this function.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 01 Sep 2015 18:57:50 +0900
parents bdac264e5ed4
children c990afab2243
files mercurial/templater.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Fri Aug 28 16:59:31 2015 -0500
+++ b/mercurial/templater.py	Tue Sep 01 18:57:50 2015 +0900
@@ -215,6 +215,15 @@
         return context._load(exp[1])
     raise error.ParseError(_("expected template specifier"))
 
+def evalfuncarg(context, mapping, arg):
+    func, data = arg
+    # func() may return string, generator of strings or arbitrary object such
+    # as date tuple, but filter does not want generator.
+    thing = func(context, mapping, data)
+    if isinstance(thing, types.GeneratorType):
+        thing = stringify(thing)
+    return thing
+
 def runinteger(context, mapping, data):
     return int(data)
 
@@ -259,11 +268,7 @@
 
 def runfilter(context, mapping, data):
     func, data, filt = data
-    # func() may return string, generator of strings or arbitrary object such
-    # as date tuple, but filter does not want generator.
-    thing = func(context, mapping, data)
-    if isinstance(thing, types.GeneratorType):
-        thing = stringify(thing)
+    thing = evalfuncarg(context, mapping, (func, data))
     try:
         return filt(thing)
     except (ValueError, AttributeError, TypeError):