mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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.
This commit is contained in:
parent
495eefece3
commit
5bca44776e
@ -221,7 +221,7 @@ def indent(text, prefix):
|
||||
def json(obj):
|
||||
if obj is None or obj is False or obj is True:
|
||||
return {None: 'null', False: 'false', True: 'true'}[obj]
|
||||
elif isinstance(obj, int) or isinstance(obj, float):
|
||||
elif isinstance(obj, (int, long, float)):
|
||||
return str(obj)
|
||||
elif isinstance(obj, str):
|
||||
return '"%s"' % encoding.jsonescape(obj, paranoid=True)
|
||||
|
Loading…
Reference in New Issue
Block a user