##// END OF EJS Templates
templater: remove __iter__() from _hybrid, resolve it explicitly...
Yuya Nishihara -
r31880:a0f2d83f default
parent child Browse files
Show More
@@ -350,6 +350,7 b' def stringify(thing):'
350 350 """Any type. Turns the value into text by converting values into
351 351 text and concatenating them.
352 352 """
353 thing = templatekw.unwraphybrid(thing)
353 354 if util.safehasattr(thing, '__iter__') and not isinstance(thing, str):
354 355 return "".join([stringify(t) for t in thing if t is not None])
355 356 if thing is None:
@@ -35,8 +35,6 b' class _hybrid(object):'
35 35 self.values = values
36 36 self._makemap = makemap
37 37 self.joinfmt = joinfmt
38 def __iter__(self):
39 return self.gen
40 38 def itermaps(self):
41 39 makemap = self._makemap
42 40 for x in self.values:
@@ -50,6 +48,13 b' class _hybrid(object):'
50 48 raise AttributeError(name)
51 49 return getattr(self.values, name)
52 50
51 def unwraphybrid(thing):
52 """Return an object which can be stringified possibly by using a legacy
53 template"""
54 if not util.safehasattr(thing, 'gen'):
55 return thing
56 return thing.gen
57
53 58 def showlist(name, values, plural=None, element=None, separator=' ', **args):
54 59 if not element:
55 60 element = name
@@ -1020,6 +1020,7 b' stringify = templatefilters.stringify'
1020 1020
1021 1021 def _flatten(thing):
1022 1022 '''yield a single stream from a possibly nested set of iterators'''
1023 thing = templatekw.unwraphybrid(thing)
1023 1024 if isinstance(thing, str):
1024 1025 yield thing
1025 1026 elif thing is None:
@@ -1028,6 +1029,7 b' def _flatten(thing):'
1028 1029 yield str(thing)
1029 1030 else:
1030 1031 for i in thing:
1032 i = templatekw.unwraphybrid(i)
1031 1033 if isinstance(i, str):
1032 1034 yield i
1033 1035 elif i is None:
General Comments 0
You need to be logged in to leave comments. Login now