Commit 6bd639c7 authored by Evan Simpson's avatar Evan Simpson

Eliminate redundant security registration in PythonExprs.

parent e0751ca5
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
"""Generic Python Expression Handler """Generic Python Expression Handler
""" """
__version__='$Revision: 1.1 $'[11:-2] __version__='$Revision: 1.2 $'[11:-2]
from string import strip, split, join, replace, lstrip from string import strip, split, join, replace, lstrip
...@@ -130,6 +130,7 @@ class PythonExpr: ...@@ -130,6 +130,7 @@ class PythonExpr:
return names return names
def __call__(self, econtext): def __call__(self, econtext):
__traceback_info__ = self.expr
f = self._f f = self._f
f.func_globals.update(self._bind_used_names(econtext)) f.func_globals.update(self._bind_used_names(econtext))
return f() return f()
......
...@@ -89,7 +89,7 @@ Handler for Python expressions, using the pre-Python 2.1 restriction ...@@ -89,7 +89,7 @@ Handler for Python expressions, using the pre-Python 2.1 restriction
machinery from PythonScripts. machinery from PythonScripts.
""" """
__version__='$Revision: 1.1 $'[11:-2] __version__='$Revision: 1.2 $'[11:-2]
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from Products.PythonScripts.Guarded import _marker, \ from Products.PythonScripts.Guarded import _marker, \
...@@ -110,20 +110,6 @@ class PythonExpr(PythonExpr): ...@@ -110,20 +110,6 @@ class PythonExpr(PythonExpr):
self._f = UntupleFunction(blk.t, guards, __builtins__=safebin) self._f = UntupleFunction(blk.t, guards, __builtins__=safebin)
self._get_used_names() self._get_used_names()
def __call__(self, econtext):
f = self._f
f.func_globals.update(self._bind_used_names(econtext))
# Execute the function in a new security context.
template = econtext.contexts['template']
security = getSecurityManager()
security.addContext(template)
try:
__traceback_info__ = self.expr
return f()
finally:
security.removeContext(template)
class _SecureModuleImporter: class _SecureModuleImporter:
__allow_access_to_unprotected_subobjects__ = 1 __allow_access_to_unprotected_subobjects__ = 1
def __getitem__(self, module): def __getitem__(self, module):
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
Handler for Python expressions that uses the RestrictedPython package. Handler for Python expressions that uses the RestrictedPython package.
""" """
__version__='$Revision: 1.1 $'[11:-2] __version__='$Revision: 1.2 $'[11:-2]
from AccessControl import full_read_guard, full_write_guard, \ from AccessControl import full_read_guard, full_write_guard, \
safe_builtins, getSecurityManager safe_builtins, getSecurityManager
...@@ -112,19 +112,11 @@ class PythonExpr(PythonExpr): ...@@ -112,19 +112,11 @@ class PythonExpr(PythonExpr):
self._code = code self._code = code
def __call__(self, econtext): def __call__(self, econtext):
__traceback_info__ = self.expr
code = self._code code = self._code
g = self._bind_used_names(econtext) g = self._bind_used_names(econtext)
g.update(self._globals) g.update(self._globals)
return eval(code, g, {})
# Execute the function in a new security context.
template = econtext.contexts['template']
security = getSecurityManager()
security.addContext(template)
try:
__traceback_info__ = self.expr
return eval(code, g, {})
finally:
security.removeContext(template)
class _SecureModuleImporter: class _SecureModuleImporter:
__allow_access_to_unprotected_subobjects__ = 1 __allow_access_to_unprotected_subobjects__ = 1
......
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