Commit 7529ff29 authored by Hanno Schlichting's avatar Hanno Schlichting

Correct the default value of the __import__ level argument to be -1

parent ad9c1bdb
......@@ -16,7 +16,7 @@ Features Added
++++++++++++++
- LP #659968: Added support for level argument to the ``__import__`` function
as introduced in Python 2.5. Currently only level=0 is supported.
as introduced in Python 2.5. Currently only level=-1 is supported.
2.12.12 (2010-10-02)
......
......@@ -268,7 +268,7 @@ def guarded_zip(*seqs):
safe_builtins['zip'] = guarded_zip
def guarded_import(mname, globals=None, locals=None, fromlist=None,
level=0):
level=-1):
if fromlist is None:
fromlist = ()
if '*' in fromlist:
......@@ -278,7 +278,7 @@ def guarded_import(mname, globals=None, locals=None, fromlist=None,
if locals is None:
locals = {}
# Refs https://bugs.launchpad.net/zope2/+bug/659968
if level != 0:
if level != -1:
raise Unauthorized("Using import with a level specification isn't "
"supported by AccessControl: %s" % mname)
......
......@@ -32,13 +32,13 @@ class ModuleSecurityTests(unittest.TestCase):
if module in sys.modules:
del sys.modules[module]
def assertUnauth(self, module, fromlist, level=0):
def assertUnauth(self, module, fromlist, level=-1):
from zExceptions import Unauthorized
from AccessControl.ZopeGuards import guarded_import
self.assertRaises(Unauthorized, guarded_import, module,
fromlist=fromlist, level=level)
def assertAuth(self, module, fromlist, level=0):
def assertAuth(self, module, fromlist, level=-1):
from AccessControl.ZopeGuards import guarded_import
guarded_import(module, fromlist=fromlist, level=level)
......@@ -77,7 +77,7 @@ class ModuleSecurityTests(unittest.TestCase):
self.failUnless('AccessControl.tests.nonesuch' in MS)
def test_level_zero(self):
self.assertAuth('AccessControl.tests.public_module', (), level=0)
self.assertAuth('AccessControl.tests.public_module', (), level=-1)
def test_level_nonzero(self):
self.assertUnauth('AccessControl.tests.public_module', (), level=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