[PATCH 1 of 6 json-style] templatefilters.json: call functions

Gregory Szorc gregory.szorc at gmail.com
Wed Dec 31 22:45:31 UTC 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1420053737 28800
#      Wed Dec 31 11:22:17 2014 -0800
# Node ID 18172660090c5794d147cdd95ee4e8c42adeb954
# Parent  6721199ac78a355e35d2994ea32188add4e5290b
templatefilters.json: call functions

The "changeset" template from hgweb is using a lambda in the
"diffsummary" key. In preparation for enabling JSON output from hgweb,
teach the json filter how to call functions.

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -207,8 +207,10 @@ def json(obj):
         out = []
         for i in obj:
             out.append(json(i))
         return '[' + ', '.join(out) + ']'
+    elif util.safehasattr(obj, '__call__'):
+        return json(obj())
     else:
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)
 
 def _uescape(c):


More information about the Mercurial-devel mailing list