Skip to content
Myr

Merge pull request #525 from iffy/fix-cycle-next

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

Give Cycler a next() method so that it works in python2 and 3

authored by Armin Ronacher · committed by GitHub · parents 45b59b5, 77781b9 · Browse files · 2 files+14 added−1 removed
This commit

State

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

Diff stats

2 files+14 added−1 removed

  • tests:+11 added−0 removed
  • other:+3 added−1 removed

2 files+14 added−1 removed

modified:jinja2/utils.py+3 added-1 removed
502 unmodified lines
503 def current(self):504 """Returns the current item."""505 return self.items[self.pos]506507 def __next__(self):507 def next(self):508 """Goes one item ahead and returns it."""509 rv = self.current510 self.pos = (self.pos + 1) % len(self.items)511 return rv512513 __next__ = next514515516class Joiner(object):517 """A joining helper for templates."""518519 def __init__(self, sep=u', '):
20 unmodified lines
modified:tests/test_api.py+11 added
57 unmodified lines
58 assert c.current == 259 c.reset()60 assert c.current == 16162 def test_cycler_nextmethod(self, env):63 items = 1, 2, 364 c = Cycler(*items)65 for item in items + items:66 assert c.current == item67 assert c.next() == item68 c.next()69 assert c.current == 270 c.reset()71 assert c.current == 1 7273 def test_expressions(self, env):74 expr = env.compile_expression("foo")75 assert expr() is None76 assert expr(foo=42) == 42
262 unmodified lines