[Zope-Checkins] SVN: Zope/trunk/ - Collector #2339: ZPT: fixed
unicode issue when using the 'structure' directive
Andreas Jung
andreas at andreas-jung.com
Sun Aug 12 06:55:46 EDT 2007
Log message for revision 78767:
- Collector #2339: ZPT: fixed unicode issue when using the 'structure' directive
- ZopeContext: added evaluateStructure() and refactored _handleText() in order
to deal with unicode issues when using the 'structure' directive
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/Products/PageTemplates/Expressions.py
U Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2007-08-12 10:44:35 UTC (rev 78766)
+++ Zope/trunk/doc/CHANGES.txt 2007-08-12 10:55:45 UTC (rev 78767)
@@ -135,6 +135,9 @@
Bugs Fixed
+ - Collector #2338: ZPT: fixed unicode issue when using the 'structure'
+ directive
+
- Collector #2332: SessionDataManger: don't swallow ConflictErrors
- ZopePageTemplate's pt_edit did not recognize content type arguments
Modified: Zope/trunk/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/Expressions.py 2007-08-12 10:44:35 UTC (rev 78766)
+++ Zope/trunk/lib/python/Products/PageTemplates/Expressions.py 2007-08-12 10:55:45 UTC (rev 78767)
@@ -192,12 +192,24 @@
return value
return bool(value)
+ def evaluateStructure(self, expr):
+ """ customized version in order to get rid of unicode
+ errors for all and ever
+ """
+ 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):
+
+ text = self.evaluate(expr)
+
if text is self.getDefault() or text is None:
# XXX: should be unicode???
return text
Modified: Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2007-08-12 10:44:35 UTC (rev 78766)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2007-08-12 10:55:45 UTC (rev 78767)
@@ -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 Zope-Checkins
mailing list