[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.31.10.2

Fred L. Drake, Jr. fdrake@acm.org
Tue, 12 Mar 2002 13:34:48 -0500


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv27073

Modified Files:
      Tag: Zope-2_5-branch
	Expressions.py 
Log Message:
Products.PageTemplates.Expressions did not export the SecureModuleImporter
in all cases; provide a version that is not magical if we are not in Zope.
(Ported from the trunk; tested with Python 2.1.2.


=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.31.10.1 => 1.31.10.2 ===
         from ZPythonExpr import PythonExpr, _SecureModuleImporter, \
              call_with_ns
-    SecureModuleImporter = _SecureModuleImporter()
+
 else:
     from PythonExpr import getSecurityManager, PythonExpr
     try:
@@ -71,7 +71,16 @@
             return f(None, ns)
         else:
             return f(ns)
-    
+
+    class _SecureModuleImporter:
+        """Simple version of the importer for use with trusted code."""
+        __allow_access_to_unprotected_subobjects__ = 1
+        def __getitem__(self, module):
+            __import__(module)
+            return sys.modules[module]
+
+SecureModuleImporter = _SecureModuleImporter()
+
 Undefs = (Undefined, AttributeError, KeyError,
           TypeError, IndexError, Unauthorized)