[Zope-Checkins] SVN: Zope/branches/2.10/lib/python/Products/PageTemplates/ write() auto-converts to unicode instead of throwing an exception

Andreas Jung andreas at andreas-jung.com
Fri Dec 29 07:07:11 EST 2006


Log message for revision 71672:
  write() auto-converts to unicode instead of throwing an exception
  

Changed:
  U   Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py
  U   Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py

-=-
Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-12-29 11:55:56 UTC (rev 71671)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-12-29 12:07:11 UTC (rev 71672)
@@ -285,8 +285,11 @@
         return c
 
     def write(self, text):
+
         if not isinstance(text, unicode):
-            raise TypeError("'text' parameter must be unicode")
+            text, encoding = convertToUnicode(text, self.content_type, preferred_encodings)
+            self.output_encoding = encoding
+
         self.ZCacheable_invalidate()
         ZopePageTemplate.inheritedAttribute('write')(self, text)
 

Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2006-12-29 11:55:56 UTC (rev 71671)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2006-12-29 12:07:11 UTC (rev 71672)
@@ -112,12 +112,6 @@
         self.assertEqual(zpt.read(), s)
         self.assertEqual(isinstance(zpt.read(), unicode), True)
 
-    def testWriteWontAcceptsNonUnicode(self):
-        manage_addPageTemplate(self.app, 'test', '', encoding='utf-8')
-        zpt = self.app['test']
-        self.assertRaises(TypeError, zpt.write, 'this is not unicode')
-
-
     def _createZPT(self):
         manage_addPageTemplate(self.app, 'test', text=utf8_str, encoding='utf-8')
         zpt = self.app['test']



More information about the Zope-Checkins mailing list