[Checkins] SVN: z3c.pt/trunk/src/z3c/pt/ Fix edge case bug where both a numeric entity and a literal set of unicode bytes was inserted into the same document. See also http://groups.google.com/group/z3c_pt/browse_thread/thread/aea963d25a1778d0?hl=en
Chris McDonough
chrism at plope.com
Tue Aug 12 02:22:29 EDT 2008
Log message for revision 89696:
Fix edge case bug where both a numeric entity and a literal set of unicode bytes was inserted into the same document. See also http://groups.google.com/group/z3c_pt/browse_thread/thread/aea963d25a1778d0?hl=en
Changed:
U z3c.pt/trunk/src/z3c/pt/clauses.py
U z3c.pt/trunk/src/z3c/pt/expressions.py
U z3c.pt/trunk/src/z3c/pt/template.py
A z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
-=-
Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py 2008-08-12 06:22:04 UTC (rev 89695)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py 2008-08-12 06:22:28 UTC (rev 89696)
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from cgi import escape
from z3c.pt import types
@@ -16,7 +14,7 @@
>>> bad_float = types.value("float('abc')")
>>> abc = types.value("'abc'")
>>> ghi = types.value("'ghi'")
- >>> utf8_encoded = types.value("'La Peña'")
+ >>> utf8_encoded = types.value("'La Pe\xc3\xb1a'")
>>> exclamation = types.value("'!'")
Simple value assignment:
@@ -69,7 +67,7 @@
>>> assign = Assign(types.join((utf8_encoded, exclamation)))
>>> assign.begin(stream, 'b')
>>> exec stream.getvalue()
- >>> b == 'La Peña!'
+ >>> b == 'La Pe\xc3\xb1a!'
True
>>> assign.end(stream)
@@ -78,7 +76,7 @@
>>> assign = Assign(types.join((utf8_encoded, u"!")))
>>> assign.begin(stream, 'b')
>>> exec stream.getvalue()
- >>> b == 'La Peña!'
+ >>> b == 'La Pe\xc3\xb1a!'
True
>>> assign.end(stream)
@@ -448,12 +446,12 @@
Unicode:
>>> _out = StringIO(); _write = _out.write; stream = CodeIO()
- >>> tag = Tag('div', dict(alt=pyexp(repr('La Peña'))))
+ >>> tag = Tag('div', dict(alt=pyexp(repr('La Pe\xc3\xb1a'))))
>>> tag.begin(stream)
>>> stream.out('Hello Universe!')
>>> tag.end(stream)
>>> exec stream.getvalue()
- >>> _out.getvalue() == '<div alt="La Peña">Hello Universe!</div>'
+ >>> _out.getvalue() == '<div alt="La Pe\xc3\xb1a">Hello Universe!</div>'
True
"""
@@ -691,8 +689,11 @@
>>> write.begin(stream)
>>> write.end(stream)
>>> exec stream.getvalue()
- >>> _out.getvalue() == unicode('La Pe\xc3\xb1a', 'utf-8')
+ >>> val = _out.getvalue()
+ >>> val == 'La Pe\xc3\xb1a'
True
+ >>> type(val) == str
+ True
"""
value = assign = None
@@ -723,6 +724,10 @@
stream.indent()
stream.write("_urf = str(_urf)")
stream.outdent()
+ stream.write("else:")
+ stream.indent()
+ stream.write("_urf = _urf.encode('utf-8')")
+ stream.outdent()
else:
stream.write("_urf = str(_urf)")
if self.structure:
@@ -771,8 +776,11 @@
>>> write.begin(stream)
>>> write.end(stream)
>>> exec stream.getvalue()
- >>> _out.getvalue() == unicode('La Pe\xc3\xb1a', 'utf-8')
+ >>> val = _out.getvalue()
+ >>> val == 'La Pe\xc3\xb1a'
True
+ >>> type(val) == str
+ True
Invalid:
Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py 2008-08-12 06:22:04 UTC (rev 89695)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py 2008-08-12 06:22:28 UTC (rev 89696)
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
import zope.interface
import zope.component
import zope.security
@@ -527,7 +525,7 @@
>>> split("abc${def | ghi}")
('abc', parts(value('def '), value('ghi')))
- >>> print split("abc${La Peña}")
+ >>> print split("abc${La Pe\xc3\xb1a}")
('abc', value('La Pe\\xc3\\xb1a'))
"""
Modified: z3c.pt/trunk/src/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.py 2008-08-12 06:22:04 UTC (rev 89695)
+++ z3c.pt/trunk/src/z3c/pt/template.py 2008-08-12 06:22:28 UTC (rev 89696)
@@ -163,8 +163,8 @@
self._source = source
# write source to disk
- filename = "%s.source" % self.filename
- if DEBUG_MODE:
+ if self.filename and DEBUG_MODE:
+ filename = "%s.source" % self.filename
fs = open(filename, 'w')
fs.write(source)
fs.close()
Added: z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py 2008-08-12 06:22:28 UTC (rev 89696)
@@ -0,0 +1,41 @@
+import unittest
+
+from zope.component.testing import PlacelessSetup
+
+class TestNumericEntityPlusUnicodeParameterInsertedLiterally(unittest.TestCase,
+ PlacelessSetup):
+ # See also
+ # http://groups.google.com/group/z3c_pt/browse_thread/thread/aea963d25a1778d0?hl=en
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+
+ def tearDown(self):
+ PlacelessSetup.tearDown(self)
+
+ def test_it(self):
+ import z3c.pt
+ from zope.configuration import xmlconfig
+ xmlconfig.file('configure.zcml', z3c.pt)
+ from z3c.pt.pagetemplate import PageTemplate
+ body = """\
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ ${foo} ©
+ </html>
+ """
+ expected = """\
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ <html>
+ foo \xc2\xa9
+ </html>"""
+ t = PageTemplate(body)
+ self.assertEqual(norm(t.render(foo=u'foo')), norm(expected))
+
+def norm(s):
+ return s.replace(' ', '').replace('\n', '')
+
+def test_suite():
+ import sys
+ return unittest.findTestCases(sys.modules[__name__])
Property changes on: z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list