From 7f371e7e6293db55a43fa2ec97f498eb8b156c2c Mon Sep 17 00:00:00 2001 From: noah morrison Date: Fri, 16 Jan 2015 10:52:47 -0500 Subject: [PATCH] Tokens needs to be a generator, not a list. At first I thought they were pretty much the same thing. But generators pick up from where they left off, while lists don't. This fixes the edge-case infinite loop that was happening last commit. from the python repl Lists >>> data = [1,2,3,4,5] >>> for i in data: ... print(i) ... if i == 2: ... for ii in data: ... print('>', ii) ... if ii == 4: ... break ... 1 2 > 1 > 2 > 3 > 4 3 4 5 Generators >>> data = [1,2,3,4,5] >>> gen = (d for d in data) >>> for i in gen: ... print(i) ... if i == 2: ... for ii in gen: ... print('>', ii) ... if ii == 4: ... break ... 1 2 > 3 > 4 5 --- chevron/renderer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chevron/renderer.py b/chevron/renderer.py index ac2da27..9f03736 100644 --- a/chevron/renderer.py +++ b/chevron/renderer.py @@ -144,7 +144,8 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache', # If the template is a list if type(template) is list: # Then we don't need to tokenize it - tokens = template + # But it does need to be a generator + tokens = (token for token in template) else: # Otherwise make a generator tokens = tokenize(template, def_ldel, def_rdel) -- 2.47.3