Mercurial > genshi > mirror
changeset 804:6bf73f6aa2b6 stable-0.5.x
Ported [1005] to 0.5.x branch.
author | cmlenz |
---|---|
date | Thu, 05 Mar 2009 10:06:45 +0000 |
parents | aa296d1c0a3d |
children | ddb93c60cb8d |
files | ChangeLog genshi/template/eval.py genshi/template/tests/eval.py |
diffstat | 3 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ attribute values when inside an `i18n:msg` block (ticket #250). * Fix problem with the transformation filter dropping events after the selection (ticket #290). + * `for` loops in template code blocks no longer establish their own locals + scope, meaning you can now access variables assigned in the loop outside + of the loop, just as you can in regular Python code (ticket #259). Version 0.5.1
--- a/genshi/template/eval.py +++ b/genshi/template/eval.py @@ -759,13 +759,6 @@ finally: self.locals.pop() - def visitFor(self, node): - self.locals.append(set()) - try: - return ASTTransformer.visitFor(self, node) - finally: - self.locals.pop() - def visitFunction(self, node): if len(self.locals) > 1: self.locals[-1].add(node.name)
--- a/genshi/template/tests/eval.py +++ b/genshi/template/tests/eval.py @@ -581,6 +581,18 @@ suite.execute(data) self.assertEqual([0, 1, 4], data['x']) + def test_for_in_def(self): + suite = Suite("""def loop(): + for i in range(10): + if i == 5: + break + return i +""") + data = {} + suite.execute(data) + assert 'loop' in data + self.assertEqual(5, data['loop']()) + def test_if(self): suite = Suite("""if foo == 42: x = True