# HG changeset patch
# User cmlenz
# Date 1158856089 0
# Node ID da3a27589559640c5552298ea5dd5d9ab664c2a7
# Parent 693a228bf1c75c7ba75b43df6fe5d2ccb641bf00
Fix for #56: an include inside a matched element wasn't seeing the correct context data frames.
diff --git a/genshi/template.py b/genshi/template.py
--- a/genshi/template.py
+++ b/genshi/template.py
@@ -13,6 +13,7 @@
"""Implementation of the template engine."""
+from itertools import chain
try:
from collections import deque
except ImportError:
@@ -849,7 +850,7 @@
stream = filter_(iter(stream), ctxt)
return Stream(stream)
- def _eval(self, stream, ctxt=None):
+ def _eval(self, stream, ctxt):
"""Internal stream filter that evaluates any expressions in `START` and
`TEXT` events.
"""
@@ -905,7 +906,7 @@
else:
yield kind, data, pos
- def _flatten(self, stream, ctxt=None):
+ def _flatten(self, stream, ctxt):
"""Internal stream filter that expands `SUB` events in the stream."""
for kind, data, pos in stream:
if kind is SUB:
@@ -1049,7 +1050,7 @@
return stream
- def _match(self, stream, ctxt=None, match_templates=None):
+ def _match(self, stream, ctxt, match_templates=None):
"""Internal stream filter that applies any defined match templates
to the stream.
"""
@@ -1092,8 +1093,12 @@
# Consume and store all events until an end event
# corresponding to this start event is encountered
- content = [(kind, data, pos)]
- content += list(self._match(_strip(stream), ctxt)) + tail
+ content = chain([(kind, data, pos)],
+ self._match(_strip(stream), ctxt),
+ tail)
+ for filter_ in self.filters[3:]:
+ content = filter_(content, ctxt)
+ content = list(content)
kind, data, pos = tail[0]
for test in [mt[0] for mt in match_templates]:
diff --git a/genshi/tests/filters.py b/genshi/tests/filters.py
--- a/genshi/tests/filters.py
+++ b/genshi/tests/filters.py
@@ -12,11 +12,15 @@
# history and logs, available at http://genshi.edgewall.org/log/.
import doctest
+import os
+import shutil
+import tempfile
import unittest
from genshi.core import Stream
from genshi.input import HTML, ParseError
from genshi.filters import HTMLSanitizer
+from genshi.template import TemplateLoader
class HTMLSanitizerTestCase(unittest.TestCase):
@@ -116,9 +120,44 @@
self.assertEquals(u'', unicode(html | HTMLSanitizer()))
+class IncludeFilterTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.dirname = tempfile.mkdtemp(suffix='markup_test')
+
+ def tearDown(self):
+ shutil.rmtree(self.dirname)
+
+ def test_select_inluded_elements(self):
+ file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
+ try:
+ file1.write("""