Skip to content
Myr

[svn] checked in changes regarding variable length iteration

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 0abe2c0 · Browse files · 3 files+22 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

3 files+22 added−1 removed

  • tests:+10 added−0 removed
  • other:+12 added−1 removed

3 files+22 added−1 removed

modified:jinja/datastructure.py+8 added-1 removed
324 unmodified lines
325 recursive for loop.326 """327 if seq in (Undefined, None):328 seq = ()329 length = 0330 else:331 try:332 length = len(seq)333 except TypeError:334 seq = list(seq)335 length = len(seq)336 self._stack.append({337 'index': -1,338 'seq': seq,332 'length': len(seq)339 'length': length340 })341 return self342343 def pop(self):
258 unmodified lines
modified:tests/test_forloop.py+10 added
15 unmodified lines
16 loop.even }}|{{ loop.odd }}|{{ loop.length }}###{% endfor %}'''17CYCLING = '''{% for item in seq %}{% cycle '<1>', '<2>' %}{% endfor %}\18{% for item in seq %}{% cycle through %}{% endfor %}'''19SCOPE = '''{% for item in seq %}{% endfor %}{{ item }}'''20VARLEN = '''{% for item in iter %}{{ item }}{% endfor %}'''212223def test_simple(env):24 tmpl = env.from_string(SIMPLE)
38 unmodified lines
63def test_scope(env):64 tmpl = env.from_string(SCOPE)65 output = tmpl.render(seq=range(10))66 assert not output676869def test_varlen(env):70 def inner():71 for item in range(5):72 yield item73 tmpl = env.from_string(VARLEN)74 output = tmpl.render(iter=inner())75 assert output == '01234'
modified:CHANGES+4 added
97 unmodified lines
98 ``{% block name %}data{% endblock %}``. Note that the second argument can99 be an expression. As soon as you specify an expression as second argument100 the closing tag has to be omitted.101102- It's now possible to iterate over iterators additionally to sequences.103 If the iterator is inifite it will crash however, so makes sure you don't104 pass something like that to a template!105106107Version 1.0108-----------109(released Mar 23, 2007)110
1 unmodified line