Show More
@@ -527,33 +527,6 b' def expandaliases(tree, aliases):' | |||||
527 |
|
527 | |||
528 | # template engine |
|
528 | # template engine | |
529 |
|
529 | |||
530 | def _flatten(thing): |
|
|||
531 | '''yield a single stream from a possibly nested set of iterators''' |
|
|||
532 | thing = templateutil.unwraphybrid(thing) |
|
|||
533 | if isinstance(thing, bytes): |
|
|||
534 | yield thing |
|
|||
535 | elif isinstance(thing, str): |
|
|||
536 | # We can only hit this on Python 3, and it's here to guard |
|
|||
537 | # against infinite recursion. |
|
|||
538 | raise error.ProgrammingError('Mercurial IO including templates is done' |
|
|||
539 | ' with bytes, not strings, got %r' % thing) |
|
|||
540 | elif thing is None: |
|
|||
541 | pass |
|
|||
542 | elif not util.safehasattr(thing, '__iter__'): |
|
|||
543 | yield pycompat.bytestr(thing) |
|
|||
544 | else: |
|
|||
545 | for i in thing: |
|
|||
546 | i = templateutil.unwraphybrid(i) |
|
|||
547 | if isinstance(i, bytes): |
|
|||
548 | yield i |
|
|||
549 | elif i is None: |
|
|||
550 | pass |
|
|||
551 | elif not util.safehasattr(i, '__iter__'): |
|
|||
552 | yield pycompat.bytestr(i) |
|
|||
553 | else: |
|
|||
554 | for j in _flatten(i): |
|
|||
555 | yield j |
|
|||
556 |
|
||||
557 | def unquotestring(s): |
|
530 | def unquotestring(s): | |
558 | '''unwrap quotes if any; otherwise returns unmodified string''' |
|
531 | '''unwrap quotes if any; otherwise returns unmodified string''' | |
559 | if len(s) < 2 or s[0] not in "'\"" or s[0] != s[-1]: |
|
532 | if len(s) < 2 or s[0] not in "'\"" or s[0] != s[-1]: | |
@@ -706,7 +679,7 b' class engine(object):' | |||||
706 | if extramapping: |
|
679 | if extramapping: | |
707 | extramapping.update(mapping) |
|
680 | extramapping.update(mapping) | |
708 | mapping = extramapping |
|
681 | mapping = extramapping | |
709 |
return |
|
682 | return templateutil.flatten(func(self, mapping, data)) | |
710 |
|
683 | |||
711 | engines = {'default': engine} |
|
684 | engines = {'default': engine} | |
712 |
|
685 |
@@ -234,6 +234,33 b' def _showcompatlist(context, mapping, na' | |||||
234 | if context.preload(endname): |
|
234 | if context.preload(endname): | |
235 | yield context.process(endname, mapping) |
|
235 | yield context.process(endname, mapping) | |
236 |
|
236 | |||
|
237 | def flatten(thing): | |||
|
238 | """Yield a single stream from a possibly nested set of iterators""" | |||
|
239 | thing = unwraphybrid(thing) | |||
|
240 | if isinstance(thing, bytes): | |||
|
241 | yield thing | |||
|
242 | elif isinstance(thing, str): | |||
|
243 | # We can only hit this on Python 3, and it's here to guard | |||
|
244 | # against infinite recursion. | |||
|
245 | raise error.ProgrammingError('Mercurial IO including templates is done' | |||
|
246 | ' with bytes, not strings, got %r' % thing) | |||
|
247 | elif thing is None: | |||
|
248 | pass | |||
|
249 | elif not util.safehasattr(thing, '__iter__'): | |||
|
250 | yield pycompat.bytestr(thing) | |||
|
251 | else: | |||
|
252 | for i in thing: | |||
|
253 | i = unwraphybrid(i) | |||
|
254 | if isinstance(i, bytes): | |||
|
255 | yield i | |||
|
256 | elif i is None: | |||
|
257 | pass | |||
|
258 | elif not util.safehasattr(i, '__iter__'): | |||
|
259 | yield pycompat.bytestr(i) | |||
|
260 | else: | |||
|
261 | for j in flatten(i): | |||
|
262 | yield j | |||
|
263 | ||||
237 | def stringify(thing): |
|
264 | def stringify(thing): | |
238 | """Turn values into bytes by converting into text and concatenating them""" |
|
265 | """Turn values into bytes by converting into text and concatenating them""" | |
239 | thing = unwraphybrid(thing) |
|
266 | thing = unwraphybrid(thing) |
General Comments 0
You need to be logged in to leave comments.
Login now