Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 37158:e09d2183e226
templateutil: reimplement stringify() using flatten()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Mar 2018 20:04:20 +0900 |
parents | 888507ec655e |
children | 53e6b7e05553 |
comparison
equal
deleted
inserted
replaced
37157:888507ec655e | 37158:e09d2183e226 |
---|---|
261 for j in flatten(i): | 261 for j in flatten(i): |
262 yield j | 262 yield j |
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 |
281 if nothing found reliably""" | 272 if nothing found reliably""" |
282 while True: | 273 while True: |