[Zope-Checkins] SVN: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py provide a way to create a "trusted" expression engine in which Python expressions

Philipp von Weitershausen philikon at philikon.de
Tue May 9 06:22:05 EDT 2006


Log message for revision 68059:
  provide a way to create a "trusted" expression engine in which Python expressions
  aren't evaluated by RestrictedPython. Five needs this.
  

Changed:
  U   Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py

-=-
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py	2006-05-09 09:28:27 UTC (rev 68058)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py	2006-05-09 10:22:04 UTC (rev 68059)
@@ -21,16 +21,18 @@
 from zope.tales.expressions import PathExpr, StringExpr, NotExpr
 from zope.tales.expressions import DeferExpr, SubPathExpr
 from zope.tales.expressions import SimpleModuleImporter
+from zope.tales.pythonexpr import PythonExpr
 from zope.traversing.adapters import traversePathElement
 from zope.contentprovider.tales import TALESProviderExpression
 
 from zExceptions import NotFound, Unauthorized
 from OFS.interfaces import ITraversable
+from Products.PageTemplates import ZRPythonExpr
 from Products.PageTemplates.DeferExpr import LazyExpr
 from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService
-from Products.PageTemplates.ZRPythonExpr import PythonExpr, _SecureModuleImporter
-SecureModuleImporter = _SecureModuleImporter()
 
+SecureModuleImporter = ZRPythonExpr._SecureModuleImporter()
+
 # BBB 2005/05/01 -- remove after 12 months
 import zope.deprecation
 zope.deprecation.deprecated(
@@ -97,14 +99,14 @@
                 kwcontexts = contexts
         return ZopeContext(self, kwcontexts)
 
-def Engine():
+def createZopeEngine():
     e = ZopeEngine()
     #TODO wire in PathIterator.Iterator after fixing it
     # e.iteratorFactory = Iterator
     for pt in ZopePathExpr._default_type_names:
         e.registerType(pt, ZopePathExpr)
     e.registerType('string', StringExpr)
-    e.registerType('python', PythonExpr)
+    e.registerType('python', ZRPythonExpr.PythonExpr)
     e.registerType('not', NotExpr)
     e.registerType('defer', DeferExpr)
     e.registerType('lazy', LazyExpr)
@@ -112,7 +114,13 @@
     e.registerBaseName('modules', SecureModuleImporter)
     return e
 
-Engine = Engine()
+def createTrustedZopeEngine():
+    # same as createZopeEngine, but use non-restricted Python
+    # expression evaluator
+    e = createZopeEngine()
+    e.types['python'] = PythonExpr
+    return e
 
+_engine = createZopeEngine()
 def getEngine():
-    return Engine
+    return _engine



More information about the Zope-Checkins mailing list