Skip to content
Myr

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

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

authored by Matt Haggard · committed by Matt Haggard · parent b78f261 · 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
504 unmodified lines
505 def current(self):506 """Returns the current item."""507 return self.items[self.pos]508509 def __next__(self):509 def next(self):510 """Goes one item ahead and returns it."""511 rv = self.current512 self.pos = (self.pos + 1) % len(self.items)513 return rv514515 __next__ = next516517518class Joiner(object):519 """A joining helper for templates."""520521 def __init__(self, sep=u', '):
12 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