Skip to content
Myr

Merge pull request #92 from jasonkotenko/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix loop.last memory issue

authored by Armin Ronacher · committed by Armin Ronacher · parents 5145401, 776567c · Browse files · 1 file+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−2 removed

  • other:+14 added−2 removed

1 file+14 added−2 removed

modified:jinja2/runtime.py+14 added-2 removed
264 unmodified lines
265266267class LoopContext(object):268 """A loop context for dynamic iteration."""269 End = object()270271 def __init__(self, iterable, recurse=None):272 self._iterator = iter(iterable)273 self._recurse = recurse274 self._after = self._safe_next()275 self.index0 = -1276277 # try to get the length of the iterable early. This must be done278 # here because there are some broken iterators around where there
10 unmodified lines
289 raise TypeError('no items for cycling given')290 return args[self.index0 % len(args)]291292 first = property(lambda x: x.index0 == 0)291 last = property(lambda x: x.index0 + 1 == x.length)293 last = property(lambda x: x._after is LoopContext.End)294 index = property(lambda x: x.index0 + 1)295 revindex = property(lambda x: x.length - x.index0)296 revindex0 = property(lambda x: x.length - x.index)297
2 unmodified lines
300301 def __iter__(self):302 return LoopContextIterator(self)303304 def _safe_next(self):305 try:306 return next(self._iterator)307 except StopIteration:308 return self.End309310 @internalcode311 def loop(self, iterable):312 if self._recurse is None:313 raise TypeError('Tried to call non recursive loop. Maybe you '
37 unmodified lines
351352 def next(self):353 ctx = self.context354 ctx.index0 += 1347 return next(ctx._iterator), ctx355 if ctx._after is LoopContext.End:356 raise StopIteration357 next_elem = ctx._after358 ctx._after = ctx._safe_next()359 return next_elem, ctx360361362class Macro(object):363 """Wraps a macro function."""
197 unmodified lines