Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 23707:ae5447de4c11
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 31 Dec 2014 11:22:17 -0800 |
parents | 13e3f07d74a3 |
children | a9f826c3eaf9 |
comparison
equal
deleted
inserted
replaced
23706:3314664606e6 | 23707:ae5447de4c11 |
---|---|
206 elif util.safehasattr(obj, '__iter__'): | 206 elif util.safehasattr(obj, '__iter__'): |
207 out = [] | 207 out = [] |
208 for i in obj: | 208 for i in obj: |
209 out.append(json(i)) | 209 out.append(json(i)) |
210 return '[' + ', '.join(out) + ']' | 210 return '[' + ', '.join(out) + ']' |
211 elif util.safehasattr(obj, '__call__'): | |
212 return json(obj()) | |
211 else: | 213 else: |
212 raise TypeError('cannot encode type %s' % obj.__class__.__name__) | 214 raise TypeError('cannot encode type %s' % obj.__class__.__name__) |
213 | 215 |
214 def _uescape(c): | 216 def _uescape(c): |
215 if ord(c) < 0x80: | 217 if ord(c) < 0x80: |