##// END OF EJS Templates
templateutil: reimplement stringify() using flatten()
Yuya Nishihara -
r37175:e09d2183 default
parent child Browse files
Show More
@@ -263,18 +263,9 b' def flatten(thing):'
263
263
264 def stringify(thing):
264 def stringify(thing):
265 """Turn values into bytes by converting into text and concatenating them"""
265 """Turn values into bytes by converting into text and concatenating them"""
266 thing = unwraphybrid(thing)
266 if isinstance(thing, bytes):
267 if util.safehasattr(thing, '__iter__') and not isinstance(thing, bytes):
267 return thing # retain localstr to be round-tripped
268 if isinstance(thing, str):
268 return b''.join(flatten(thing))
269 # This is only reachable on Python 3 (otherwise
270 # isinstance(thing, bytes) would have been true), and is
271 # here to prevent infinite recursion bugs on Python 3.
272 raise error.ProgrammingError(
273 'stringify got unexpected unicode string: %r' % thing)
274 return "".join([stringify(t) for t in thing if t is not None])
275 if thing is None:
276 return ""
277 return pycompat.bytestr(thing)
278
269
279 def findsymbolicname(arg):
270 def findsymbolicname(arg):
280 """Find symbolic name for the given compiled expression; returns None
271 """Find symbolic name for the given compiled expression; returns None
General Comments 0
You need to be logged in to leave comments. Login now