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

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


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

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

-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-12-29 12:07:11 UTC (rev 71672)
+++ Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-12-29 12:12:47 UTC (rev 71673)
@@ -108,7 +108,6 @@
         self.expand = 0                                                               
         self.ZBindings_edit(self._default_bindings)
         self.output_encoding = output_encoding
-
         # default content
         if not text:
             text = open(self._default_content_fn).read()
@@ -286,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/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2006-12-29 12:07:11 UTC (rev 71672)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2006-12-29 12:12:47 UTC (rev 71673)
@@ -112,12 +112,7 @@
         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