Commit da359ae5 authored by Fred Drake's avatar Fred Drake

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).
parent 8a7ef464
...@@ -17,7 +17,7 @@ Page Template-specific implementation of TALES, with handlers ...@@ -17,7 +17,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, string literals, and paths. for Python expressions, string literals, and paths.
""" """
__version__='$Revision: 1.31 $'[11:-2] __version__='$Revision: 1.32 $'[11:-2]
import re, sys import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \ from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
...@@ -59,7 +59,6 @@ if sys.modules.has_key('Zope'): ...@@ -59,7 +59,6 @@ if sys.modules.has_key('Zope'):
else: else:
from ZPythonExpr import PythonExpr, _SecureModuleImporter, \ from ZPythonExpr import PythonExpr, _SecureModuleImporter, \
call_with_ns call_with_ns
SecureModuleImporter = _SecureModuleImporter()
else: else:
from PythonExpr import getSecurityManager, PythonExpr from PythonExpr import getSecurityManager, PythonExpr
try: try:
...@@ -71,7 +70,16 @@ else: ...@@ -71,7 +70,16 @@ else:
return f(None, ns) return f(None, ns)
else: else:
return f(ns) 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, Undefs = (Undefined, AttributeError, KeyError,
TypeError, IndexError, Unauthorized) TypeError, IndexError, Unauthorized)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment