Python __builtin__ 模块,__import__() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用__builtin__.__import__()

项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def test_discovery_failed_discovery(self):
        loader = unittest.TestLoader()
        package = types.ModuleType('package')
        orig_import = __import__

        def _import(packagename, *args, **kwargs):
            sys.modules[packagename] = package
            return package

        def cleanup():
            builtins.__import__ = orig_import
        self.addCleanup(cleanup)
        builtins.__import__ = _import

        with self.assertRaises(TypeError) as cm:
            loader.discover('package')
        self.assertEqual(str(cm.exception),
                         'don\'t know how to discover from {0!r}'
                         .format(package))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:sagecipher    作者:p-sherratt    | 项目源码 | 文件源码
def test_passlib(self):
        # force import of passlib pbkdf2 function, and compare headers/keys
        # generated from both hashlib and passlib
        self.cipher1 = sagecipher.Cipher()
        try:
            import builtins
        except ImportError:
            import __builtin__ as builtins
        realimport = builtins.__import__
        def myimport(*args, **kwargs):
            if args[0] == 'hashlib' and args[3] is not None and 'pbkdf2_hmac' in args[3]: 
                raise ImportError
            return realimport(*args, **kwargs)
        builtins.__import__ = myimport
        del(sagecipher.cipher.pbkdf2_hashlib)
        reload(sagecipher.cipher)
        reload(sagecipher)
        self.assertIn('pbkdf2_passlib', dir(sagecipher.cipher))
        self.assertNotIn('pbkdf2_hashlib', dir(sagecipher.cipher))
        self.cipher2 = sagecipher.Cipher(self.cipher1.header())
        self.assertEqual(self.cipher1.header(), self.cipher2.header())
项目:end    作者:nya3jp    | 项目源码 | 文件源码
def test_hooked_import(self):
        # It should work even if __import__ is hooked by someone else.
        saved_import = builtins.__import__
        @functools.wraps(saved_import)
        def my_import(*args, **kwargs):
            return saved_import(*args, **kwargs)
        end
        builtins.__import__ = my_import
        try:
            with self.assertRaises(SyntaxError) as cm:
                import cases.hooked_import
            end
            self.assertTrue('hooked_import.py' in str(cm.exception))
        finally:
            builtins.__import__ = saved_import
        end
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
def import_it(self, partname, fqname, parent, force_load=0):
        if not partname:
            # completely empty module name should only happen in
            # 'from . import' or __import__("")
            return parent
        if not force_load:
            try:
                return self.modules[fqname]
            except KeyError:
                pass
        try:
            path = parent and parent.__path__
        except AttributeError:
            return None
        partname = str(partname)
        stuff = self.loader.find_module(partname, path)
        if not stuff:
            return None
        fqname = str(fqname)
        m = self.loader.load_module(fqname, stuff)
        if parent:
            setattr(parent, partname, m)
        return m
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1):
    """Replacement for __import__()"""
    parent, buf = get_parent(globals, level)

    head, name, buf = load_next(
        parent, None if level < 0 else parent, name, buf)

    tail = head
    while name:
        tail, name, buf = load_next(tail, tail, name, buf)

    # If tail is None, both get_parent and load_next found
    # an empty module name: someone called __import__("") or
    # doctored faulty bytecode
    if tail is None:
        raise ValueError('Empty module name')

    if not fromlist:
        return head

    ensure_fromlist(tail, fromlist, buf, 0)
    return tail
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def _import(self, mod, **kwds):
        """
        Request the remote process import a module (or symbols from a module)
        and return the proxied results. Uses built-in __import__() function, but 
        adds a bit more processing:

            _import('module')  =>  returns module
            _import('module.submodule')  =>  returns submodule 
                                             (note this differs from behavior of __import__)
            _import('module', fromlist=[name1, name2, ...])  =>  returns [module.name1, module.name2, ...]
                                             (this also differs from behavior of __import__)

        """
        return self.send(request='import', callSync='sync', opts=dict(module=mod), **kwds)
项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def _import(self, mod, **kwds):
        """
        Request the remote process import a module (or symbols from a module)
        and return the proxied results. Uses built-in __import__() function, but 
        adds a bit more processing:

            _import('module')  =>  returns module
            _import('module.submodule')  =>  returns submodule 
                                             (note this differs from behavior of __import__)
            _import('module', fromlist=[name1, name2, ...])  =>  returns [module.name1, module.name2, ...]
                                             (this also differs from behavior of __import__)

        """
        return self.send(request='import', callSync='sync', opts=dict(module=mod), **kwds)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def test_discovery_from_dotted_namespace_packages(self):
        if not getattr(types, 'SimpleNamespace', None):
            raise unittest.SkipTest('Namespaces not supported')
        loader = unittest.TestLoader()

        orig_import = __import__
        package = types.ModuleType('package')
        package.__path__ = ['/a', '/b']
        package.__spec__ = types.SimpleNamespace(
           loader=None,
           submodule_search_locations=['/a', '/b']
        )

        def _import(packagename, *args, **kwargs):
            sys.modules[packagename] = package
            return package

        def cleanup():
            builtins.__import__ = orig_import
        self.addCleanup(cleanup)
        builtins.__import__ = _import

        _find_tests_args = []
        def _find_tests(start_dir, pattern, namespace=None):
            _find_tests_args.append((start_dir, pattern))
            return ['%s/tests' % start_dir]

        loader._find_tests = _find_tests
        loader.suiteClass = list
        suite = loader.discover('package')
        self.assertEqual(suite, ['/a/tests', '/b/tests'])
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def __import__(name, globals={}, locals={}, fromlist=[], level=-1):
        """Compatibility definition for Python 2.4.

        Silently ignore the `level` argument missing in Python < 2.5.
        """
        # we need the level arg because the default changed in Python 3.3
        return __builtin__.__import__(name, globals, locals, fromlist)
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def __import__(name, globals={}, locals={}, fromlist=[], level=-1):
        """Compatibility definition for Python 2.4.

        Silently ignore the `level` argument missing in Python < 2.5.
        """
        # we need the level arg because the default changed in Python 3.3
        return __builtin__.__import__(name, globals, locals, fromlist)
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def local_import_aux(name, reload_force=False, app='welcome'):
    """
    In apps, instead of importing a local module
    (in applications/app/modules) with::

       import a.b.c as d

    you should do::

       d = local_import('a.b.c')

    or (to force a reload):

       d = local_import('a.b.c', reload=True)

    This prevents conflict between applications and un-necessary execs.
    It can be used to import any module, including regular Python modules.
    """
    items = name.replace('/', '.')
    name = "applications.%s.modules.%s" % (app, items)
    module = __import__(name)
    for item in name.split(".")[1:]:
        module = getattr(module, item)
    if reload_force:
        reload(module)
    return module
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def custom_import_install():
    if __builtin__.__import__ == NATIVE_IMPORTER:
        INVALID_MODULES.update(sys.modules.keys())
        __builtin__.__import__ = custom_importer
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def __import__(*args, **kwargs):
    """
    __import__(name, globals=None, locals=None, fromlist=(), level=0) -> object

    Normally python protects imports against concurrency by doing some locking
    at the C level (at least, it does that in CPython).  This function just
    wraps the normal __import__ functionality in a recursive lock, ensuring that
    we're protected against greenlet import concurrency as well.
    """
    if len(args) > 0 and not issubclass(type(args[0]), _allowed_module_name_types):
        # if a builtin has been acquired as a bound instance method,
        # python knows not to pass 'self' when the method is called.
        # No such protection exists for monkey-patched builtins,
        # however, so this is necessary.
        args = args[1:]

    if not __lock_imports:
        return _import(*args, **kwargs)

    module_lock = __module_lock(args[0]) # Get a lock for the module name
    imp.acquire_lock()
    try:
        module_lock.acquire()
        try:
            result = _import(*args, **kwargs)
        finally:
            module_lock.release()
    finally:
        imp.release_lock()
    return result
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def _unlock_imports():
    """
    Internal function, called when gevent needs to perform imports
    lazily, but does not know the state of the system. It may be impossible
    to take the import lock because there are no other running greenlets, for
    example. This causes a monkey-patched __import__ to avoid taking any locks.
    until the corresponding call to lock_imports. This should only be done for limited
    amounts of time and when the set of imports is statically known to be "safe".
    """
    global __lock_imports
    # This could easily become a list that we push/pop from or an integer
    # we increment if we need to do this recursively, but we shouldn't get
    # that complex.
    __lock_imports = False
项目:RealtimePythonChat    作者:quangtqag    | 项目源码 | 文件源码
def __import__(*args, **kwargs):
    """
    __import__(name, globals=None, locals=None, fromlist=(), level=0) -> object

    Normally python protects imports against concurrency by doing some locking
    at the C level (at least, it does that in CPython).  This function just
    wraps the normal __import__ functionality in a recursive lock, ensuring that
    we're protected against greenlet import concurrency as well.
    """
    if len(args) > 0 and not issubclass(type(args[0]), _allowed_module_name_types):
        # if a builtin has been acquired as a bound instance method,
        # python knows not to pass 'self' when the method is called.
        # No such protection exists for monkey-patched builtins,
        # however, so this is necessary.
        args = args[1:]

    if not __lock_imports:
        return _import(*args, **kwargs)

    module_lock = __module_lock(args[0]) # Get a lock for the module name
    imp.acquire_lock()
    try:
        module_lock.acquire()
        try:
            result = _import(*args, **kwargs)
        finally:
            module_lock.release()
    finally:
        imp.release_lock()
    return result
项目:RealtimePythonChat    作者:quangtqag    | 项目源码 | 文件源码
def _unlock_imports():
    """
    Internal function, called when gevent needs to perform imports
    lazily, but does not know the state of the system. It may be impossible
    to take the import lock because there are no other running greenlets, for
    example. This causes a monkey-patched __import__ to avoid taking any locks.
    until the corresponding call to lock_imports. This should only be done for limited
    amounts of time and when the set of imports is statically known to be "safe".
    """
    global __lock_imports
    # This could easily become a list that we push/pop from or an integer
    # we increment if we need to do this recursively, but we shouldn't get
    # that complex.
    __lock_imports = False
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def custom_import_install():
    if __builtin__.__import__ == NATIVE_IMPORTER:
        INVALID_MODULES.update(sys.modules.keys())
        __builtin__.__import__ = custom_importer
项目:pytypes    作者:Stewori    | 项目源码 | 文件源码
def _install_import_hook():
    global _import_hook_installed
    if not _import_hook_installed:
        builtins.__import__ = _pytypes___import__
        _import_hook_installed = True
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def local_import_aux(name, reload_force=False, app='welcome'):
    """
    In apps, instead of importing a local module
    (in applications/app/modules) with::

       import a.b.c as d

    you should do::

       d = local_import('a.b.c')

    or (to force a reload):

       d = local_import('a.b.c', reload=True)

    This prevents conflict between applications and un-necessary execs.
    It can be used to import any module, including regular Python modules.
    """
    items = name.replace('/', '.')
    name = "applications.%s.modules.%s" % (app, items)
    module = __import__(name)
    for item in name.split(".")[1:]:
        module = getattr(module, item)
    if reload_force:
        reload(module)
    return module
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def custom_import_install():
    if __builtin__.__import__ == NATIVE_IMPORTER:
        INVALID_MODULES.update(sys.modules.keys())
        __builtin__.__import__ = custom_importer
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def __import__(name, globals={}, locals={}, fromlist=[], level=-1):
        """Compatibility definition for Python 2.4.

        Silently ignore the `level` argument missing in Python < 2.5.
        """
        # we need the level arg because the default changed in Python 3.3
        return __builtin__.__import__(name, globals, locals, fromlist)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:specto    作者:mrknow    | 项目源码 | 文件源码
def _patch_import_to_patch_pyqt_on_import(patch_qt_on_import):
    # I don't like this approach very much as we have to patch __import__, but I like even less
    # asking the user to configure something in the client side...
    # So, our approach is to patch PyQt4/5 right before the user tries to import it (at which
    # point he should've set the sip api version properly already anyways).

    dotted = patch_qt_on_import + '.'
    original_import = __import__

    from _pydev_imps._pydev_sys_patch import patch_sys_module, patch_reload, cancel_patches_in_sys_module

    patch_sys_module()
    patch_reload()

    def patched_import(name, *args, **kwargs):
        if patch_qt_on_import == name or name.startswith(dotted):
            builtins.__import__ = original_import
            cancel_patches_in_sys_module()
            _internal_patch_qt() # Patch it only when the user would import the qt module
        return original_import(name, *args, **kwargs)

    try:
        import builtins
    except ImportError:
        import __builtin__ as builtins
    builtins.__import__ = patched_import
项目:celery-monitor    作者:jimmy201602    | 项目源码 | 文件源码
def enable(blacklist=None):
    """Enable global module dependency tracking.
    A blacklist can be specified to exclude specific modules (and their import
    hierachies) from the reloading process.  The blacklist can be any iterable
    listing the fully-qualified names of modules that should be ignored.  Note
    that blacklisted modules will still appear in the dependency graph; they
    will just not be reloaded.
    """
    global _blacklist
    builtins.__import__ = _import
    if blacklist is not None:
        _blacklist = frozenset(blacklist)
项目:celery-monitor    作者:jimmy201602    | 项目源码 | 文件源码
def disable():
    """Disable global module dependency tracking."""
    global _blacklist, _parent
    builtins.__import__ = _baseimport
    _blacklist = None
    _dependencies.clear()
    _parent = None
项目:celery-monitor    作者:jimmy201602    | 项目源码 | 文件源码
def _import(name, globals=None, locals=None, fromlist=None, level=_default_level):
    """__import__() replacement function that tracks module dependencies."""
    # Track our current parent module.  This is used to find our current place
    # in the dependency graph.
    global _parent
    parent = _parent
    _parent = name

    # Perform the actual import work using the base import function.
    base = _baseimport(name, globals, locals, fromlist, level)

    if base is not None and parent is not None:
        m = base

        # We manually walk through the imported hierarchy because the import
        # function only returns the top-level package reference for a nested
        # import statement (e.g. 'package' for `import package.module`) when
        # no fromlist has been specified.  It's possible that the package
        # might not have all of its descendents as attributes, in which case
        # we fall back to using the immediate ancestor of the module instead.
        if fromlist is None:
            for component in name.split('.')[1:]:
                try:
                    m = getattr(m, component)
                except AttributeError:
                    m = sys.modules[m.__name__ + '.' + component]

        # If this is a nested import for a reloadable (source-based) module,
        # we append ourself to our parent's dependency list.
        if hasattr(m, '__file__'):
            l = _dependencies.setdefault(parent, [])
            l.append(m)

    # Lastly, we always restore our global _parent pointer.
    _parent = parent

    return base
项目:end    作者:nya3jp    | 项目源码 | 文件源码
def install_import_hook():
    """Installs __import__ hook."""
    saved_import = builtins.__import__
    @functools.wraps(saved_import)
    def import_hook(name, *args, **kwargs):
        if name == 'end':
            process_import()
        end
        return saved_import(name, *args, **kwargs)
    end
    builtins.__import__ = import_hook
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def local_import_aux(name, reload_force=False, app='welcome'):
    """
    In apps, instead of importing a local module
    (in applications/app/modules) with::

       import a.b.c as d

    you should do::

       d = local_import('a.b.c')

    or (to force a reload):

       d = local_import('a.b.c', reload=True)

    This prevents conflict between applications and un-necessary execs.
    It can be used to import any module, including regular Python modules.
    """
    items = name.replace('/', '.')
    name = "applications.%s.modules.%s" % (app, items)
    module = __import__(name)
    for item in name.split(".")[1:]:
        module = getattr(module, item)
    if reload_force:
        reload(module)
    return module
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def custom_import_install():
    if __builtin__.__import__ == NATIVE_IMPORTER:
        INVALID_MODULES.update(sys.modules.keys())
        __builtin__.__import__ = custom_importer
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def uninstall(self):
        __builtin__.__import__ = self.save_import_module
        __builtin__.reload = self.save_reload
        __builtin__.unload = self.save_unload
        if not __builtin__.unload:
            del __builtin__.unload
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
def install(self):
        self.save_import_module = __builtin__.__import__
        self.save_reload = __builtin__.reload
        if not hasattr(__builtin__, 'unload'):
            __builtin__.unload = None
        self.save_unload = __builtin__.unload
        __builtin__.__import__ = self.import_module
        __builtin__.reload = self.reload
        __builtin__.unload = self.unload