Comments
Patch
@@ -350,6 +350,7 @@ def stringify(thing):
"""Any type. Turns the value into text by converting values into
text and concatenating them.
"""
+ thing = templatekw.unwraphybrid(thing)
if util.safehasattr(thing, '__iter__') and not isinstance(thing, str):
return "".join([stringify(t) for t in thing if t is not None])
if thing is None:
@@ -35,8 +35,6 @@ class _hybrid(object):
self.values = values
self._makemap = makemap
self.joinfmt = joinfmt
- def __iter__(self):
- return self.gen
def itermaps(self):
makemap = self._makemap
for x in self.values:
@@ -50,6 +48,13 @@ class _hybrid(object):
raise AttributeError(name)
return getattr(self.values, name)
+def unwraphybrid(thing):
+ """Return an object which can be stringified possibly by using a legacy
+ template"""
+ if not util.safehasattr(thing, 'gen'):
+ return thing
+ return thing.gen
+
def showlist(name, values, plural=None, element=None, separator=' ', **args):
if not element:
element = name
@@ -1018,6 +1018,7 @@ stringify = templatefilters.stringify
def _flatten(thing):
'''yield a single stream from a possibly nested set of iterators'''
+ thing = templatekw.unwraphybrid(thing)
if isinstance(thing, str):
yield thing
elif thing is None:
@@ -1026,6 +1027,7 @@ def _flatten(thing):
yield str(thing)
else:
for i in thing:
+ i = templatekw.unwraphybrid(i)
if isinstance(i, str):
yield i
elif i is None: