[Zope-Checkins] SVN: Zope/branches/2.10/ Workaround for Python expressions encoded as unicode string.

Andreas Jung andreas at andreas-jung.com
Wed Feb 21 06:00:38 EST 2007


Log message for revision 72742:
    Workaround for Python expressions encoded as unicode string.
    See http://mail.zope.org/pipermail/zope/2007-February/170537.html
  

Changed:
  U   Zope/branches/2.10/doc/CHANGES.txt
  U   Zope/branches/2.10/lib/python/Products/PageTemplates/ZRPythonExpr.py

-=-
Modified: Zope/branches/2.10/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.10/doc/CHANGES.txt	2007-02-21 10:52:26 UTC (rev 72741)
+++ Zope/branches/2.10/doc/CHANGES.txt	2007-02-21 11:00:37 UTC (rev 72742)
@@ -11,6 +11,9 @@
       - Undeprecated 'zLOG', which will remain a backward-compatibility
         shim for the Python logging module.
 
+      - PageTemplate/ZRPythonExpr.py: expressions represented as unicode string
+        caused UnicodeDecodeErrors. 
+
   Zope 2.10.2 (2007/01/26)
 
     Bugs fixed

Modified: Zope/branches/2.10/lib/python/Products/PageTemplates/ZRPythonExpr.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/PageTemplates/ZRPythonExpr.py	2007-02-21 10:52:26 UTC (rev 72741)
+++ Zope/branches/2.10/lib/python/Products/PageTemplates/ZRPythonExpr.py	2007-02-21 11:00:37 UTC (rev 72742)
@@ -29,7 +29,13 @@
 
     def __init__(self, name, expr, engine):
         self.text = text = expr.strip().replace('\n', ' ')
-        code, err, warn, use = compile_restricted_eval(text, str(self))
+
+        # Unicode expression are not handled properly by RestrictedPython
+        # We convert the expression to UTF-8 (ajung)
+        if isinstance(text, unicode):
+            text = text.encode('utf-8')
+        code, err, warn, use = compile_restricted_eval(text, 
+                                                       self.__class__.__name__)
         if err:
             raise engine.getCompilerError()('Python expression error:\n%s' %
                                             '\n'.join(err))            



More information about the Zope-Checkins mailing list