[Checkins] SVN: z3c.pt/trunk/ UTF-8 encode dynamic attribute insertions.

Chris McDonough chrism at plope.com
Mon Aug 18 03:55:13 EDT 2008


Log message for revision 89957:
  UTF-8 encode dynamic attribute insertions.
  

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/clauses.py
  U   z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-18 07:55:03 UTC (rev 89956)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-18 07:55:13 UTC (rev 89957)
@@ -4,6 +4,8 @@
 Version 1.0dev
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- UTF-8 encode Unicode attribute literals. [chrism]
+
 - Substantially reduced compiler overhead for lxml CDATA
   workaround. [malthe]
 

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-18 07:55:03 UTC (rev 89956)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-18 07:55:13 UTC (rev 89957)
@@ -537,7 +537,7 @@
                 stream.write("if isinstance(%s, unicode):" % temp)
                 stream.indent()
                 stream.write("_write(' %s=\"')" % attribute)
-                stream.write("_esc = %s" % temp)
+                stream.write("_esc = %s.encode('utf-8')" % temp)
                 stream.escape("_esc")
                 stream.write("_write(_esc)")
                 stream.write("_write('\"')")

Modified: z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py	2008-08-18 07:55:03 UTC (rev 89956)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py	2008-08-18 07:55:13 UTC (rev 89957)
@@ -33,6 +33,35 @@
         t = PageTemplate(body)
         self.assertEqual(norm(t.render(foo=u'foo')), norm(expected))
 
+class TestUnicodeAttributeLiteral(unittest.TestCase, PlacelessSetup):
+    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">
+        <div id="${foo}"/>
+        </html>
+        """
+        expected = """\
+        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+        <html>
+        <div id="\xc2\xa9"/>
+        </html>"""
+        t = PageTemplate(body)
+        c = unicode('\xc2\xa9', 'utf-8')
+        self.assertEqual(norm(t.render(foo=c)), norm(expected))
+
 def norm(s):
     return s.replace(' ', '').replace('\n', '')
 



More information about the Checkins mailing list