# HG changeset patch
# User hodgestar
# Date 1307839295 0
# Node ID f15334b65cf8472b48eba4fa4465f537037b5924
# Parent 8d0f693081b5f3c7ae2def216539920e80392722
Don't cache (TEXT, Markup) events in serializers. This is not needed and since Markup instances compare equal to the same non-Markup string this can lead to incorrect cached output being retrieved. Fixes #429. This is patch t429-fix.2.patch from that ticket. It includes an additional unrelated test to check that the WhitespaceFilter actually removes ignorable whitespace.
diff --git a/genshi/output.py b/genshi/output.py
--- a/genshi/output.py
+++ b/genshi/output.py
@@ -239,6 +239,9 @@
for filter_ in self.filters:
stream = filter_(stream)
for kind, data, pos in stream:
+ if kind is TEXT and isinstance(data, Markup):
+ yield data
+ continue
cached = _get((kind, data))
if cached is not None:
yield cached
@@ -345,6 +348,9 @@
for filter_ in self.filters:
stream = filter_(stream)
for kind, data, pos in stream:
+ if kind is TEXT and isinstance(data, Markup):
+ yield data
+ continue
cached = _get((kind, data))
if cached is not None:
yield cached
@@ -467,6 +473,9 @@
for filter_ in self.filters:
stream = filter_(stream)
for kind, data, _ in stream:
+ if kind is TEXT and isinstance(data, Markup):
+ yield data
+ continue
output = _get((kind, data))
if output is not None:
yield output
@@ -658,6 +667,9 @@
_gen_prefix = _gen_prefix().next
for kind, data, pos in stream:
+ if kind is TEXT and isinstance(data, Markup):
+ yield kind, data, pos
+ continue
output = _get((kind, data))
if output is not None:
yield kind, output, pos
diff --git a/genshi/tests/output.py b/genshi/tests/output.py
--- a/genshi/tests/output.py
+++ b/genshi/tests/output.py
@@ -15,7 +15,7 @@
import unittest
import sys
-from genshi.core import Attrs, Stream, QName
+from genshi.core import Attrs, Markup, QName, Stream
from genshi.input import HTML, XML
from genshi.output import DocType, XMLSerializer, XHTMLSerializer, \
HTMLSerializer, EmptyTagFilter
@@ -361,6 +361,23 @@
encoding=None)
self.assertEqual('\n', output)
+ def test_ignorable_space(self):
+ text = ' Mess \n\n\n with me! '
+ output = XML(text).render(XMLSerializer, encoding=None)
+ self.assertEqual(' Mess\n with me! ', output)
+
+ def test_cache_markup(self):
+ loc = (None, -1, -1)
+ stream = Stream([(Stream.START, (QName('foo'), Attrs()), loc),
+ (Stream.TEXT, u'…', loc),
+ (Stream.END, QName('foo'), loc),
+ (Stream.START, (QName('bar'), Attrs()), loc),
+ (Stream.TEXT, Markup('…'), loc),
+ (Stream.END, QName('bar'), loc)])
+ output = stream.render(XMLSerializer, encoding=None,
+ strip_whitespace=False)
+ self.assertEqual('……', output)
+
class HTMLSerializerTestCase(unittest.TestCase):