Commit 42562716 authored by Andreas Jung's avatar Andreas Jung

write() auto-converts to unicode instead of throwing an exception

parent 4a2c432b
......@@ -285,8 +285,11 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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)
......
......@@ -112,12 +112,6 @@ class ZopePageTemplateFileTests(ZopeTestCase):
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']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment