- Added `urlencode` filter that automatically quotes values for
URL safe usage with utf-8 as only supported encoding. If applications
want to change this encoding they can override the filter.
+- Accessing `last` on the loop context no longer causes the iterator
+ to be consumed into a list.
Version 2.6
-----------
#: the identity function. Useful for certain things in the environment
identity = lambda x: x
+_last_iteration = object()
+
def markup_join(seq):
"""Concatenation that escapes if necessary and converts to unicode."""
class LoopContext(object):
"""A loop context for dynamic iteration."""
- End = object()
def __init__(self, iterable, recurse=None):
self._iterator = iter(iterable)
return args[self.index0 % len(args)]
first = property(lambda x: x.index0 == 0)
- last = property(lambda x: x._after is LoopContext.End)
+ last = property(lambda x: x._after is _last_iteration)
index = property(lambda x: x.index0 + 1)
revindex = property(lambda x: x.length - x.index0)
revindex0 = property(lambda x: x.length - x.index)
try:
return next(self._iterator)
except StopIteration:
- return self.End
+ return _last_iteration
@internalcode
def loop(self, iterable):
def next(self):
ctx = self.context
ctx.index0 += 1
- if ctx._after is LoopContext.End:
- raise StopIteration
+ if ctx._after is _last_iteration:
+ raise StopIteration()
next_elem = ctx._after
ctx._after = ctx._safe_next()
return next_elem, ctx