Mercurial > hg
comparison mercurial/templatefilters.py @ 32128:c3342c177211
py3: replace str with bytes in isinstance()
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 20 Apr 2017 19:57:16 +0530 |
parents | 964e7427a691 |
children | ae0ebe93ac70 |
comparison
equal
deleted
inserted
replaced
32127:964e7427a691 | 32128:c3342c177211 |
---|---|
229 return 'false' | 229 return 'false' |
230 elif obj is True: | 230 elif obj is True: |
231 return 'true' | 231 return 'true' |
232 elif isinstance(obj, (int, long, float)): | 232 elif isinstance(obj, (int, long, float)): |
233 return pycompat.bytestr(obj) | 233 return pycompat.bytestr(obj) |
234 elif isinstance(obj, str): | 234 elif isinstance(obj, bytes): |
235 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid) | 235 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid) |
236 elif util.safehasattr(obj, 'keys'): | 236 elif util.safehasattr(obj, 'keys'): |
237 out = ['%s: %s' % (json(k), json(v)) | 237 out = ['%s: %s' % (json(k), json(v)) |
238 for k, v in sorted(obj.iteritems())] | 238 for k, v in sorted(obj.iteritems())] |
239 return '{' + ', '.join(out) + '}' | 239 return '{' + ', '.join(out) + '}' |
353 def stringify(thing): | 353 def stringify(thing): |
354 """Any type. Turns the value into text by converting values into | 354 """Any type. Turns the value into text by converting values into |
355 text and concatenating them. | 355 text and concatenating them. |
356 """ | 356 """ |
357 thing = templatekw.unwraphybrid(thing) | 357 thing = templatekw.unwraphybrid(thing) |
358 if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): | 358 if util.safehasattr(thing, '__iter__') and not isinstance(thing, bytes): |
359 return "".join([stringify(t) for t in thing if t is not None]) | 359 return "".join([stringify(t) for t in thing if t is not None]) |
360 if thing is None: | 360 if thing is None: |
361 return "" | 361 return "" |
362 return pycompat.bytestr(thing) | 362 return pycompat.bytestr(thing) |
363 | 363 |