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

login
register
mail settings
Submitter Gregory Szorc
Date Dec. 31, 2014, 10:45 p.m.
Message ID <18172660090c5794d147.1420065931@gps-mbp.local>
Download mbox | patch
Permalink /patch/7286/
State Accepted
Commit ae5447de4c1100661fdff69397f70358394da512
Headers show

Comments

Gregory Szorc - Dec. 31, 2014, 10:45 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.

Patch

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):