# HG changeset patch
# User cmlenz
# Date 1158926843 0
# Node ID 3a19878f3ab789234251d14a1e4b91c0faaf355e
# Parent 3fc7db1cbb2f78a0c18af7dfe361e5bb9a14951d
Ported [321:323] to 0.3.x stable branch.
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Version 0.3.1
+http://svn.edgewall.org/repos/genshi/tags/0.3.1/
+(?, from branches/stable/0.3.x)
+
+ * Includes and user-defined filters were not getting the correct context data
+ when used inside a match template (ticket #56).
+ * XPath patterns using the union operator (`|`) were returning only partial
+ results in some cases.
+
+
Version 0.3
http://svn.edgewall.org/repos/genshi/tags/0.3.0/
(Sep 17 2006, from branches/stable/0.3.x)
diff --git a/genshi/path.py b/genshi/path.py
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -157,6 +157,7 @@
paths = [(p, len(p), [0], [], [0] * len(p)) for p in self.paths]
def _test(kind, data, pos, namespaces, variables):
+ retval = None
for steps, size, cursors, cutoff, counter in paths:
# Manage the stack that tells us "where we are" in the stream
@@ -166,7 +167,8 @@
continue
elif kind is START:
cursors.append(cursors and cursors[-1] or 0)
- elif not cursors:
+
+ if retval or not cursors:
continue
cursor = cursors[-1]
depth = len(cursors)
@@ -176,7 +178,7 @@
ctxtnode = not ignore_context and kind is START \
and depth == 2
- matched = retval = None
+ matched = None
while 1:
# Fetch the next location step
axis, nodetest, predicates = steps[cursor]
@@ -262,8 +264,7 @@
break
cursors[-1] = cursor
- if retval:
- return retval
+ return retval
return _test
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("""