Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 31780:8d9eafe01111
templatefilters: unroll handling of None/False/True
It doesn't make sense to use a dict here.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 02 Apr 2017 11:51:25 +0900 |
parents | fd687ec5a643 |
children | 47925b63be70 |
comparison
equal
deleted
inserted
replaced
31779:fd687ec5a643 | 31780:8d9eafe01111 |
---|---|
217 yield '\n' | 217 yield '\n' |
218 return "".join(indenter()) | 218 return "".join(indenter()) |
219 | 219 |
220 @templatefilter('json') | 220 @templatefilter('json') |
221 def json(obj): | 221 def json(obj): |
222 if obj is None or obj is False or obj is True: | 222 if obj is None: |
223 return {None: 'null', False: 'false', True: 'true'}[obj] | 223 return 'null' |
224 elif obj is False: | |
225 return 'false' | |
226 elif obj is True: | |
227 return 'true' | |
224 elif isinstance(obj, (int, long, float)): | 228 elif isinstance(obj, (int, long, float)): |
225 return str(obj) | 229 return str(obj) |
226 elif isinstance(obj, str): | 230 elif isinstance(obj, str): |
227 return '"%s"' % encoding.jsonescape(obj, paranoid=True) | 231 return '"%s"' % encoding.jsonescape(obj, paranoid=True) |
228 elif util.safehasattr(obj, 'keys'): | 232 elif util.safehasattr(obj, 'keys'): |