comparison mercurial/templatefilters.py @ 37230:63144f33c8bb

templatefilters: raise ProgrammingError if unencodable type passed to json() This shouldn't happen for any template data types (though I know it does because of some templater bugs.) Let's clarify it is a bug.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 18 Mar 2018 16:53:08 +0900
parents 05db42732fce
children a25513263075
comparison
equal deleted inserted replaced
37229:05db42732fce 37230:63144f33c8bb
261 for k, v in sorted(obj.iteritems())] 261 for k, v in sorted(obj.iteritems())]
262 return '{' + ', '.join(out) + '}' 262 return '{' + ', '.join(out) + '}'
263 elif util.safehasattr(obj, '__iter__'): 263 elif util.safehasattr(obj, '__iter__'):
264 out = [json(i, paranoid) for i in obj] 264 out = [json(i, paranoid) for i in obj]
265 return '[' + ', '.join(out) + ']' 265 return '[' + ', '.join(out) + ']'
266 else: 266 raise error.ProgrammingError('cannot encode %r' % obj)
267 raise TypeError('cannot encode type %s' % obj.__class__.__name__)
268 267
269 @templatefilter('lower', intype=bytes) 268 @templatefilter('lower', intype=bytes)
270 def lower(text): 269 def lower(text):
271 """Any text. Converts the text to lowercase.""" 270 """Any text. Converts the text to lowercase."""
272 return encoding.lower(text) 271 return encoding.lower(text)