Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(1)  |  Derive(0)  |  Import(3)

        def guarded_import(mname, globals=None, locals=None, fromlist=None,
    if fromlist is None:
        fromlist = ()
    if '*' in fromlist:
        raise Unauthorized("'from %s import *' is not allowed")
    if globals is None:
        globals = {}
    if locals is None:
        locals = {}
    # Refs https://bugs.launchpad.net/zope2/+bug/659968
    if level != -1:
        raise Unauthorized("Using import with a level specification isn't "
                           "supported by AccessControl: %s" % mname)

    mnameparts = mname.split('.')
    validate = getSecurityManager().validate
    module = load_module(None, None, mnameparts, validate, globals, locals)
    if module is None:
        raise Unauthorized("import of '%s' is unauthorized" % mname)
    if fromlist is None:
        fromlist = ()
    for name in fromlist:
        v = getattr(module, name, None)
        if v is None:
            v = load_module(module, mname, [name], validate,
                            globals, locals)
        if not validate(module, module, name, v):
            raise Unauthorized
        return __import__(mname, globals, locals, fromlist)

src/a/c/AccessControl-3.0.8/src/AccessControl/tests/testModuleSecurity.py   AccessControl(Download)
    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=-1):
        from AccessControl.ZopeGuards import guarded_import
        guarded_import(module, fromlist=fromlist, level=level)
    def test_failed_import_keeps_MSI(self):
        # LP #281156
        from AccessControl import ModuleSecurityInfo as MSI
        from AccessControl.SecurityInfo import _moduleSecurity as MS
        from AccessControl.ZopeGuards import guarded_import