[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/documenttemplate/ Merge r69903 from trunk.

Yusei Tahara yusei at domen.cx
Tue Sep 12 11:26:10 EDT 2006


Log message for revision 70129:
  Merge r69903 from trunk.
  Fixed UnicodeEncodeError when uses non-ascii unicode string in template.
  

Changed:
  U   Zope3/branches/3.3/src/zope/documenttemplate/pdocumenttemplate.py
  U   Zope3/branches/3.3/src/zope/documenttemplate/tests/testdt_var.py

-=-
Modified: Zope3/branches/3.3/src/zope/documenttemplate/pdocumenttemplate.py
===================================================================
--- Zope3/branches/3.3/src/zope/documenttemplate/pdocumenttemplate.py	2006-09-12 14:46:11 UTC (rev 70128)
+++ Zope3/branches/3.3/src/zope/documenttemplate/pdocumenttemplate.py	2006-09-12 15:26:09 UTC (rev 70129)
@@ -18,6 +18,7 @@
 from types import StringTypes, TupleType, ClassType
 ClassTypes = [ClassType]
 
+from zope.documenttemplate.ustr import ustr
 
 def safe_callable(ob):
     # Works with ExtensionClasses and Acquisition.
@@ -280,7 +281,7 @@
                     section = md[section]
                 else:
                     section = section(md)
-                section = str(section)
+                section = ustr(section)
             else:
                 # if
                 cache = {}

Modified: Zope3/branches/3.3/src/zope/documenttemplate/tests/testdt_var.py
===================================================================
--- Zope3/branches/3.3/src/zope/documenttemplate/tests/testdt_var.py	2006-09-12 14:46:11 UTC (rev 70128)
+++ Zope3/branches/3.3/src/zope/documenttemplate/tests/testdt_var.py	2006-09-12 15:26:09 UTC (rev 70129)
@@ -126,6 +126,29 @@
         self.assertEqual(res2, expected2)
 
 
+    def testNonAsciiUnicode(self):
+
+        html = self.doc_class(
+            u"""
+            English  : Hello world!
+            Japanese : <dtml-var japanese>
+            Chinese  : <dtml-var chinese>
+            Korea    : <dtml-var korean>
+            """)
+
+        expected = (
+            u"""
+            English  : Hello world!
+            Japanese : \u3053\u3093\u306b\u3061\u306f \u4e16\u754c!
+            Chinese  : \u4f60\u597d\uff0c\u4e16\u754c\uff01
+            Korea    : \uc548\ub155, \uc138\uc0c1!
+            """)
+
+        self.assertEqual(html(japanese=u'\u3053\u3093\u306b\u3061\u306f \u4e16\u754c!',
+                              chinese=u'\u4f60\u597d\uff0c\u4e16\u754c\uff01',
+                              korean=u'\uc548\ub155, \uc138\uc0c1!'),
+                         expected)
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestDT_Var))



More information about the Zope3-Checkins mailing list