Commit 1a64533d authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: RestrictedPython: Fix `Unauthorized: Using import with a level...

py3: RestrictedPython: Fix `Unauthorized: Using import with a level specification isn't supported by AccessControl.`
parent 7444277a
...@@ -451,8 +451,12 @@ for alias, real in six.iteritems(MNAME_MAP): ...@@ -451,8 +451,12 @@ for alias, real in six.iteritems(MNAME_MAP):
allow_module(real) allow_module(real)
del alias, real del alias, real
orig_guarded_import = safe_builtins['__import__'] orig_guarded_import = safe_builtins['__import__']
try:
from AccessControl.ZopeGuards import import_default_level # zope4py3
except ImportError:
import_default_level = -1
def guarded_import(mname, globals=None, locals=None, fromlist=None, def guarded_import(mname, globals=None, locals=None, fromlist=None,
level=-1): level=import_default_level):
for fromname in fromlist or (): for fromname in fromlist or ():
if fromname[:1] == '_': if fromname[:1] == '_':
raise Unauthorized(fromname) raise Unauthorized(fromname)
......
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