[Checkins] SVN: Zope/branches/2.10/lib/python/Products/PageTemplates/ - fix for collector #2339 (unicode decode error when using the 'structure'

Andreas Jung andreas at andreas-jung.com
Sun Aug 12 06:44:35 EDT 2007


Log message for revision 78766:
  - fix for collector #2339 (unicode decode error when using the 'structure'
    directive
  - ZopeContext: added evaluateStructure() method in order to catch 
    UnicodeDecodeErrors and handle them properly using the unicode conflict
    resolver
  
  

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

-=-
Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py	2007-08-12 10:33:25 UTC (rev 78765)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py	2007-08-12 10:44:35 UTC (rev 78766)
@@ -217,12 +217,20 @@
             return value
         return bool(value)
 
+    def evaluateStructure(self, expr):
+        text = super(ZopeContext, self).evaluateStructure(expr)
+        return self._handleText(text, expr)
+
     def evaluateText(self, expr):
         """ customized version in order to get rid of unicode
             errors for all and ever
         """
         text = self.evaluate(expr)
+        return self._handleText(text, expr)
 
+
+    def _handleText(self, text, expr):
+
         if text is self.getDefault() or text is None:
             # XXX: should be unicode???
             return text

Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2007-08-12 10:33:25 UTC (rev 78765)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2007-08-12 10:44:35 UTC (rev 78766)
@@ -121,7 +121,17 @@
         result = zpt.pt_render()
         self.assertEqual(result.startswith(unicode('<div>üöä</div>', 'iso-8859-15')), False)
 
+    def testStructureWithAccentedChars(self):
+        manage_addPageTemplate(self.app, 'test', 
+                               text='<div tal:content="structure python: %s" />' % "'üöä'",
+                               encoding='iso-8859-15')
+        zpt = self.app['test']
+        self.app.REQUEST.set('HTTP_ACCEPT_CHARSET', 'iso-8859-15,utf-8')
+        self.app.REQUEST.set('data', unicode('üöä', 'iso-8859-15').encode('utf-8'))
+        result = zpt.pt_render()
+        self.assertEqual(result.startswith(unicode('<div>üöä</div>', 'iso-8859-15')), True)
 
+
 class ZopePageTemplateFileTests(ZopeTestCase):
 
     def testPT_RenderWithAscii(self):



More information about the Checkins mailing list