# HG changeset patch # User cmlenz # Date 1153414526 0 # Node ID a71a58df6bf5a12f7f97478c3985c873fafe9814 # Parent c835e81c50af5ff363d7b24f20b8e6b9e9d1e529 Some subtle fixes to generation and sanitization. diff --git a/markup/builder.py b/markup/builder.py --- a/markup/builder.py +++ b/markup/builder.py @@ -70,7 +70,9 @@ for event in child.generate(): yield event else: - yield Stream.TEXT, unicode(child), (-1, -1) + if not isinstance(child, basestring): + child = unicode(child) + yield Stream.TEXT, child, (-1, -1) return Stream(_generate()) diff --git a/markup/core.py b/markup/core.py --- a/markup/core.py +++ b/markup/core.py @@ -334,7 +334,7 @@ from markup.filters import HTMLSanitizer from markup.input import HTMLParser text = StringIO(self.stripentities(keepxmlentities=True)) - return Stream(HTMLSanitizer()(HTMLParser(text))) + return Markup(Stream(HTMLSanitizer()(HTMLParser(text)))) escape = Markup.escape diff --git a/markup/tests/core.py b/markup/tests/core.py --- a/markup/tests/core.py +++ b/markup/tests/core.py @@ -123,9 +123,9 @@ markup = Markup('') self.assertEquals('', str(markup.sanitize())) markup = Markup('alert("foo")') - self.assertRaises(ParseError, markup.sanitize().render) + self.assertRaises(ParseError, markup.sanitize) markup = Markup('') - self.assertRaises(ParseError, markup.sanitize().render) + self.assertRaises(ParseError, markup.sanitize) def test_sanitize_remove_onclick_attr(self): markup = Markup('
') @@ -156,7 +156,7 @@ self.assertEquals('', str(markup.sanitize())) # Grave accents (not parsed) markup = Markup('') - self.assertRaises(ParseError, markup.sanitize().render) + self.assertRaises(ParseError, markup.sanitize) # Protocol encoded using UTF-8 numeric entities markup = Markup('')