Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 31728:35eb8f112c88
templatefilter: add support for 'long' to json()
When disabling the '#requires serve' check in test-hgwebdir.t and running it on
Windows, several 500 errors popped up when querying '?style=json', with the
following in the error log:
File "...\\mercurial\\templater.py", line 393, in runfilter
"keyword '%s'") % (filt.func_name, dt))
Abort: template filter 'json' is not compatible with keyword 'lastchange'
The swallowed exception at that point was:
File "...\\mercurial\\templatefilters.py", line 242, in json
raise TypeError('cannot encode type %s' % obj.__class__.__name__)
TypeError: cannot encode type long
This corresponds to 'lastchange' being populated by hgweb.common.get_stat(),
which uses os.stat().st_mtime. os.stat_float_times() is being disabled in util,
so the type for the times is 'long' on Windows, and 'int' on Linux.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 01 Apr 2017 00:21:17 -0400 |
parents | 53865692a354 |
children | fd687ec5a643 |
comparison
equal
deleted
inserted
replaced
31727:6be6e4becaaf | 31728:35eb8f112c88 |
---|---|
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 or obj is False or obj is True: |
223 return {None: 'null', False: 'false', True: 'true'}[obj] | 223 return {None: 'null', False: 'false', True: 'true'}[obj] |
224 elif isinstance(obj, int) or isinstance(obj, float): | 224 elif isinstance(obj, (int, long, float)): |
225 return str(obj) | 225 return str(obj) |
226 elif isinstance(obj, str): | 226 elif isinstance(obj, str): |
227 return '"%s"' % encoding.jsonescape(obj, paranoid=True) | 227 return '"%s"' % encoding.jsonescape(obj, paranoid=True) |
228 elif util.safehasattr(obj, 'keys'): | 228 elif util.safehasattr(obj, 'keys'): |
229 out = [] | 229 out = [] |