Log message for revision 71756:
  merged UnicodeEncodingConflictResolver
  

Changed:
  U   Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py
  U   Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py
  A   Zope/branches/2.10/lib/python/Products/PageTemplates/configure.zcml
  A   Zope/branches/2.10/lib/python/Products/PageTemplates/interfaces.py
  A   
Zope/branches/2.10/lib/python/Products/PageTemplates/unicodeconflictresolver.py

-=-
Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py 
2007-01-07 11:13:59 UTC (rev 71755)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/Expressions.py 
2007-01-07 11:30:05 UTC (rev 71756)
@@ -17,6 +17,10 @@
 
 $Id$
 """
+
+import logging
+
+from zope.component import getUtility
 from zope.interface import implements
 from zope.tales.tales import Context, Iterator
 from zope.tales.expressions import PathExpr, StringExpr, NotExpr
@@ -31,13 +35,17 @@
 from MultiMapping import MultiMapping
 from Acquisition import aq_base
 from zExceptions import NotFound, Unauthorized
+
 from Products.Five.browser.providerexpression import Z2ProviderExpression
 from Products.PageTemplates import ZRPythonExpr
 from Products.PageTemplates.DeferExpr import LazyExpr
 from Products.PageTemplates.GlobalTranslationService import 
getGlobalTranslationService
+from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
 
 SecureModuleImporter = ZRPythonExpr._SecureModuleImporter()
 
+LOG = logging.getLogger('Expressions')
+
 # BBB 2005/05/01 -- remove after 12 months
 import zope.deprecation
 from zope.deprecation import deprecate
@@ -173,6 +181,44 @@
             domain, msgid, mapping=mapping,
             context=context, default=default)
 
+
+    def evaluateText(self, expr):
+        """ customized version in order to get rid of unicode
+            errors for all and ever
+        """
+
+        text = self.evaluate(expr)
+
+        if text is self.getDefault() or text is None:
+            # XXX: should be unicode???
+            return text
+
+        if isinstance(text, unicode):
+            # we love unicode, nothing to do
+            return text
+
+        elif isinstance(text, str):
+            # bahh...non-unicode string..we need to convert it to unicode
+            resolver = getUtility(IUnicodeEncodingConflictResolver)
+
+            try:
+                return resolver.resolve(self.contexts['context'], text, expr)
+            except UnicodeDecodeError,e:
+                LOG.error("""UnicodeDecodeError detected for expression 
"%s"\n"""
+                          """Resolver class: %s\n"""
+                          """Exception text: %s\n"""
+                          """Template: %s\n"""
+                          """Rendered text: %r"""  % \
+                          (expr, resolver.__class__, e, 
+                            self.contexts['template'].absolute_url(1), text))
+                raise 
+        else:
+
+            # This is a weird culprit ...calling unicode() on non-string
+            # objects
+            return unicode(text)
+
+
 class ZopeEngine(zope.app.pagetemplate.engine.ZopeEngine):
 
     _create_context = ZopeContext

Modified: 
Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py    
2007-01-07 11:13:59 UTC (rev 71755)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/ZopePageTemplate.py    
2007-01-07 11:30:05 UTC (rev 71756)
@@ -40,7 +40,8 @@
 from Products.PageTemplates.PageTemplateFile import guess_type
 from Products.PageTemplates.Expressions import SecureModuleImporter
 
-from Products.PageTemplates.utils import encodingFromXMLPreamble, 
charsetFromMetaEquiv, convertToUnicode
+from Products.PageTemplates.utils import encodingFromXMLPreamble, \
+         charsetFromMetaEquiv, convertToUnicode
             
 
 preferred_encodings = ['utf-8', 'iso-8859-15']
@@ -103,7 +104,8 @@
     security.declareProtected(view_management_screens,
                               'read', 'ZScriptHTML_tryForm')
 
-    def __init__(self, id, text=None, content_type='text/html', strict=True, 
output_encoding='utf-8'):
+    def __init__(self, id, text=None, content_type='text/html', strict=True, 
+                 output_encoding='utf-8'):
         self.id = id
         self.expand = 0                                                        
       
         self.ZBindings_edit(self._default_bindings)
@@ -139,16 +141,13 @@
             charset = charsetFromMetaEquiv(text)
 
             if is_unicode:
-
                 if charset:
                     encoding = None
                     output_encoding = charset
                 else:
                     encoding = None
                     output_encoding = 'iso-8859-15'
-
             else:
-
                 if charset:
                     encoding = charset
                     output_encoding = charset
@@ -287,7 +286,9 @@
     def write(self, text):
 
         if not isinstance(text, unicode):
-            text, encoding = convertToUnicode(text, self.content_type, 
preferred_encodings)
+            text, encoding = convertToUnicode(text, 
+                                              self.content_type,
+                                              preferred_encodings)
             self.output_encoding = encoding
 
         self.ZCacheable_invalidate()

Copied: Zope/branches/2.10/lib/python/Products/PageTemplates/configure.zcml 
(from rev 71755, Zope/trunk/lib/python/Products/PageTemplates/configure.zcml)

Copied: Zope/branches/2.10/lib/python/Products/PageTemplates/interfaces.py 
(from rev 71755, Zope/trunk/lib/python/Products/PageTemplates/interfaces.py)

Copied: 
Zope/branches/2.10/lib/python/Products/PageTemplates/unicodeconflictresolver.py 
(from rev 71755, 
Zope/trunk/lib/python/Products/PageTemplates/unicodeconflictresolver.py)

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to