Avoid code duplication: Use SecureModuleImporter from ZRPythonExpr.py (made available

as an instance by Expressions.py). Minor style cleanup in ZRPythonExpr.py.
parent 28c7644c
......@@ -43,7 +43,8 @@ class PythonExpr(PythonExpr):
return eval(self._code, vars, {})
class _SecureModuleImporter:
__allow_access_to_unprotected_subobjects__ = 1
__allow_access_to_unprotected_subobjects__ = True
def __getitem__(self, module):
mod = safe_builtins['__import__'](module)
path = module.split('.')
......
......@@ -39,6 +39,7 @@ from zope.pagetemplate.pagetemplate import PageTemplate
from zope.pagetemplate.pagetemplatefile import sniff_type
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter
# regular expression to extract the encoding from the XML preamble
......@@ -48,16 +49,6 @@ preferred_encodings = ['utf-8', 'iso-8859-15']
if os.environ.has_key('ZPT_PREFERRED_ENCODING'):
preferred_encodings.insert(0, os.environ['ZPT_PREFERRED_ENCODING'])
class SecureModuleImporter:
__allow_access_to_unprotected_subobjects__ = 1
def __getitem__(self, module):
mod = safe_builtins['__import__'](module)
path = module.split('.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
class Src(Acquisition.Explicit):
""" I am scary code """
......@@ -259,7 +250,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
'options': {},
'root': root,
'request': getattr(root, 'REQUEST', None),
'modules': SecureModuleImporter(),
'modules': SecureModuleImporter,
}
return c
......
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