comparison mercurial/templatefilters.py @ 38066:f5a1aa8c6987

json: reject unicode on py2 as well This makes it consistent with the behavior on py3. Differential Revision: https://phab.mercurial-scm.org/D3536
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 11 May 2018 10:36:28 -0700
parents a25513263075
children 56dd15178190
comparison
equal deleted inserted replaced
38065:c3fd9a0f8277 38066:f5a1aa8c6987
247 return 'true' 247 return 'true'
248 elif isinstance(obj, (int, long, float)): 248 elif isinstance(obj, (int, long, float)):
249 return pycompat.bytestr(obj) 249 return pycompat.bytestr(obj)
250 elif isinstance(obj, bytes): 250 elif isinstance(obj, bytes):
251 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid) 251 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
252 elif isinstance(obj, str): 252 elif isinstance(obj, type(u'')):
253 # This branch is unreachable on Python 2, because bytes == str
254 # and we'll return in the next-earlier block in the elif
255 # ladder. On Python 3, this helps us catch bugs before they
256 # hurt someone.
257 raise error.ProgrammingError( 253 raise error.ProgrammingError(
258 'Mercurial only does output with bytes on Python 3: %r' % obj) 254 'Mercurial only does output with bytes: %r' % obj)
259 elif util.safehasattr(obj, 'keys'): 255 elif util.safehasattr(obj, 'keys'):
260 out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid), 256 out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid),
261 json(v, paranoid)) 257 json(v, paranoid))
262 for k, v in sorted(obj.iteritems())] 258 for k, v in sorted(obj.iteritems())]
263 return '{' + ', '.join(out) + '}' 259 return '{' + ', '.join(out) + '}'