##// END OF EJS Templates
templater: inline unwraphybrid()...
Yuya Nishihara -
r38289:630c6280 default
parent child Browse files
Show More
@@ -31,8 +31,7 b' class wrapped(object):'
31 """Object requiring extra conversion prior to displaying or processing
31 """Object requiring extra conversion prior to displaying or processing
32 as value
32 as value
33
33
34 Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain the inner
34 Use unwrapvalue() or unwrapastype() to obtain the inner object.
35 object.
36 """
35 """
37
36
38 __metaclass__ = abc.ABCMeta
37 __metaclass__ = abc.ABCMeta
@@ -434,13 +433,6 b' def hybridlist(data, name, fmt=None, gen'
434 prefmt = pycompat.bytestr
433 prefmt = pycompat.bytestr
435 return hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
434 return hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
436
435
437 def unwraphybrid(context, mapping, thing):
438 """Return an object which can be stringified possibly by using a legacy
439 template"""
440 if not isinstance(thing, wrapped):
441 return thing
442 return thing.show(context, mapping)
443
444 def compatdict(context, mapping, name, data, key='key', value='value',
436 def compatdict(context, mapping, name, data, key='key', value='value',
445 fmt=None, plural=None, separator=' '):
437 fmt=None, plural=None, separator=' '):
446 """Wrap data like hybriddict(), but also supports old-style list template
438 """Wrap data like hybriddict(), but also supports old-style list template
@@ -534,7 +526,8 b' def _showcompatlist(context, mapping, na'
534
526
535 def flatten(context, mapping, thing):
527 def flatten(context, mapping, thing):
536 """Yield a single stream from a possibly nested set of iterators"""
528 """Yield a single stream from a possibly nested set of iterators"""
537 thing = unwraphybrid(context, mapping, thing)
529 if isinstance(thing, wrapped):
530 thing = thing.show(context, mapping)
538 if isinstance(thing, bytes):
531 if isinstance(thing, bytes):
539 yield thing
532 yield thing
540 elif isinstance(thing, str):
533 elif isinstance(thing, str):
@@ -548,7 +541,8 b' def flatten(context, mapping, thing):'
548 yield pycompat.bytestr(thing)
541 yield pycompat.bytestr(thing)
549 else:
542 else:
550 for i in thing:
543 for i in thing:
551 i = unwraphybrid(context, mapping, i)
544 if isinstance(i, wrapped):
545 i = i.show(context, mapping)
552 if isinstance(i, bytes):
546 if isinstance(i, bytes):
553 yield i
547 yield i
554 elif i is None:
548 elif i is None:
General Comments 0
You need to be logged in to leave comments. Login now