[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.32
Fred L. Drake, Jr.
fdrake@acm.org
Thu, 28 Feb 2002 15:05:59 -0500
Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv7225
Modified Files:
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.
Tested with Python 2.1.1 and 2.2.1 (CVS).
=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.31 => 1.32 ===
from ZPythonExpr import PythonExpr, _SecureModuleImporter, \
call_with_ns
- SecureModuleImporter = _SecureModuleImporter()
else:
from PythonExpr import getSecurityManager, PythonExpr
try:
@@ -71,7 +70,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)