# HG changeset patch # User cmlenz # Date 1191830698 0 # Node ID 0413c8817a3c605a68de04c407ea2a4b4d7a2c43 # Parent 523a706d171ef301f32d129122c640252d34ceda Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch! diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,7 @@ set to "xml" (the default), the include is processed as before, but when set to "text", the included template is parsed as a text template using the new syntax (ticket #101). + * Python code blocks inside match templates are now executed (ticket #155). Version 0.4.4 diff --git a/genshi/template/markup.py b/genshi/template/markup.py --- a/genshi/template/markup.py +++ b/genshi/template/markup.py @@ -292,9 +292,9 @@ remaining = match_templates if 'match_once' not in hints: remaining = remaining[:idx] + remaining[idx + 1:] - for event in self._match(self._eval(self._flatten(template, - ctxt), - ctxt), ctxt, remaining): + for event in self._match(self._exec( + self._eval(self._flatten(template, ctxt), + ctxt), ctxt), ctxt, remaining): yield event ctxt.pop() diff --git a/genshi/template/tests/markup.py b/genshi/template/tests/markup.py --- a/genshi/template/tests/markup.py +++ b/genshi/template/tests/markup.py @@ -596,6 +596,21 @@ """) tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True) + def test_exec_in_match(self): + xml = (""" + + + ${title} + +

moot text

+ """) + tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True) + self.assertEqual(""" + + wakka wakka wakka + + """, tmpl.generate().render()) + def suite(): suite = unittest.TestSuite()