當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.meta_path方法代碼示例

本文整理匯總了Python中sys.meta_path方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.meta_path方法的具體用法?Python sys.meta_path怎麽用?Python sys.meta_path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sys的用法示例。


在下文中一共展示了sys.meta_path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ResetModules

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def ResetModules(self):
    """Clear modules so that when request is run they are reloaded."""
    lib_config._default_registry.reset()
    self._modules.clear()
    self._modules.update(self._default_modules)


    sys.path_hooks[:] = self._save_path_hooks


    sys.meta_path = []





    apiproxy_stub_map.apiproxy.GetPreCallHooks().Clear()
    apiproxy_stub_map.apiproxy.GetPostCallHooks().Clear() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:20,代碼來源:dev_appserver.py

示例2: find_loader

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def find_loader(name, path=None):
    """Find the loader for the specified module.

    First, sys.modules is checked to see if the module was already imported. If
    so, then sys.modules[name].__loader__ is returned. If that happens to be
    set to None, then ValueError is raised. If the module is not in
    sys.modules, then sys.meta_path is searched for a suitable loader with the
    value of 'path' given to the finders. None is returned if no loader could
    be found.

    Dotted names do not have their parent packages implicitly imported. You will
    most likely need to explicitly import all parent packages in the proper
    order for a submodule to get the correct loader.

    """
    try:
        loader = sys.modules[name].__loader__
        if loader is None:
            raise ValueError('{}.__loader__ is None'.format(name))
        else:
            return loader
    except KeyError:
        pass
    return _bootstrap._find_module(name, path) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:26,代碼來源:__init__.py

示例3: load_module

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def load_module(self, fullname):
        print('load_module {}'.format(fullname))
        if fullname in sys.modules:
            return sys.modules[fullname]

        # 先從 sys.meta_path 中刪除自定義的 finder
        # 防止下麵執行 import_module 的時候再次觸發此 finder
        # 從而出現遞歸調用的問題
        finder = sys.meta_path.pop(0)
        # 導入 module
        module = importlib.import_module(fullname)

        module_hook(fullname, module)

        sys.meta_path.insert(0, finder)
        return module 
開發者ID:mozillazg,項目名稱:apm-python-agent-principle,代碼行數:18,代碼來源:_hook.py

示例4: install_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def install_hooks():
    """
    This function installs the future.standard_library import hook into
    sys.meta_path.
    """
    if PY3:
        return

    install_aliases()

    flog.debug('sys.meta_path was: {0}'.format(sys.meta_path))
    flog.debug('Installing hooks ...')

    # Add it unless it's there already
    newhook = RenameImport(RENAMES)
    if not detect_hooks():
        sys.meta_path.append(newhook)
    flog.debug('sys.meta_path is now: {0}'.format(sys.meta_path)) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:20,代碼來源:__init__.py

示例5: remove_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def remove_hooks(scrub_sys_modules=False):
    """
    This function removes the import hook from sys.meta_path.
    """
    if PY3:
        return
    flog.debug('Uninstalling hooks ...')
    # Loop backwards, so deleting items keeps the ordering:
    for i, hook in list(enumerate(sys.meta_path))[::-1]:
        if hasattr(hook, 'RENAMER'):
            del sys.meta_path[i]

    # Explicit is better than implicit. In the future the interface should
    # probably change so that scrubbing the import hooks requires a separate
    # function call. Left as is for now for backward compatibility with
    # v0.11.x.
    if scrub_sys_modules:
        scrub_future_sys_modules() 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:20,代碼來源:__init__.py

示例6: detect_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def detect_hooks():
    """
    Returns True if the import hooks are installed, False if not.
    """
    flog.debug('Detecting hooks ...')
    present = any([hasattr(hook, 'RENAMER') for hook in sys.meta_path])
    if present:
        flog.debug('Detected.')
    else:
        flog.debug('Not detected.')
    return present


# As of v0.12, this no longer happens implicitly:
# if not PY3:
#     install_hooks() 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:18,代碼來源:__init__.py

示例7: mount

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def mount(self, append=False):
        pathname = os.path.abspath(os.path.join(self.dirname, self.filename))
        if not self.is_compatible():
            msg = 'Wheel %s not compatible with this Python.' % pathname
            raise DistlibException(msg)
        if not self.is_mountable():
            msg = 'Wheel %s is marked as not mountable.' % pathname
            raise DistlibException(msg)
        if pathname in sys.path:
            logger.debug('%s already in path', pathname)
        else:
            if append:
                sys.path.append(pathname)
            else:
                sys.path.insert(0, pathname)
            extensions = self._get_extensions()
            if extensions:
                if _hook not in sys.meta_path:
                    sys.meta_path.append(_hook)
                _hook.add(pathname, extensions) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:wheel.py

示例8: _FakeProxyBypassHelper

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def _FakeProxyBypassHelper(fn,
                             original_module_dict=sys.modules.copy(),
                             original_uname=os.uname):
    """Setups and restores the state for the Mac OS X urllib fakes."""
    def Inner(*args, **kwargs):
      current_uname = os.uname
      current_meta_path = sys.meta_path[:]
      current_modules = sys.modules.copy()

      try:
        sys.modules.clear()
        sys.modules.update(original_module_dict)
        sys.meta_path[:] = []
        os.uname = original_uname

        return fn(*args, **kwargs)
      finally:
        sys.modules.clear()
        sys.modules.update(current_modules)
        os.uname = current_uname
        sys.meta_path[:] = current_meta_path
    return Inner 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:24,代碼來源:dev_appserver_import_hook.py

示例9: register_assert_rewrite

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def register_assert_rewrite(*names):
    """Register one or more module names to be rewritten on import.

    This function will make sure that this module or all modules inside
    the package will get their assert statements rewritten.
    Thus you should make sure to call this before the module is
    actually imported, usually in your __init__.py if you are a plugin
    using a package.

    :raise TypeError: if the given module names are not strings.
    """
    for name in names:
        if not isinstance(name, str):
            msg = "expected module names as *args, got {0} instead"
            raise TypeError(msg.format(repr(names)))
    for hook in sys.meta_path:
        if isinstance(hook, rewrite.AssertionRewritingHook):
            importhook = hook
            break
    else:
        importhook = DummyRewriteHook()
    importhook.mark_rewrite(*names) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:24,代碼來源:__init__.py

示例10: _add_git_repo

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def _add_git_repo(url_builder, username=None, repo=None, module=None, branch=None, commit=None, **kw):
    '''
Function that creates and adds to the 'sys.meta_path' an HttpImporter object equipped with a URL of a Online Git server.
The 'url_builder' parameter is a function that accepts the username, repo and branch/commit, and creates a HTTP/S URL of a Git server. Compatible functions are '__create_github_url', '__create_bitbucket_url'.
The 'username' parameter defines the Github username which is the repository's owner.
The 'repo' parameter defines the name of the repo that contains the modules/packages to be imported.
The 'module' parameter is optional and is a list containing the modules/packages that are available in the chosen Github repository.
If it is not provided, it defaults to the repositories name, as it is common that the a Python repository at "github.com/someuser/somereponame" contains a module/package of "somereponame".
The 'branch' and 'commit' parameters cannot be both populated at the same call. They specify the branch (last commit) or specific commit, that should be served.
    '''
    if username == None or repo == None:
        raise Error("'username' and 'repo' parameters cannot be None")
    if commit and branch:
        raise Error("'branch' and 'commit' parameters cannot be both set!")

    if commit:
        branch = commit
    if not branch:
        branch = 'master'
    if not module:
        module = repo
    if type(module) == str:
        module = [module]
    url = url_builder(username, repo, branch, **kw)
    return add_remote_repo(module, url) 
開發者ID:operatorequals,項目名稱:httpimport,代碼行數:27,代碼來源:httpimport.py

示例11: invalidate_caches

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def invalidate_caches():
    """Call the invalidate_caches() method on all meta path finders stored in
    sys.meta_path (where implemented)."""
    for finder in sys.meta_path:
        if hasattr(finder, 'invalidate_caches'):
            finder.invalidate_caches() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:8,代碼來源:__init__.py

示例12: _unload_pkg_resources

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def _unload_pkg_resources():
    sys.meta_path = [
        importer
        for importer in sys.meta_path
        if importer.__class__.__module__ != 'pkg_resources.extern'
    ]
    del_modules = [
        name for name in sys.modules
        if name.startswith('pkg_resources')
    ]
    for mod_name in del_modules:
        del sys.modules[mod_name] 
開發者ID:aimuch,項目名稱:iAI,代碼行數:14,代碼來源:ez_setup.py

示例13: install_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def install_hooks(include_paths=(), exclude_paths=()):
    if isinstance(include_paths, str):
        include_paths = (include_paths,)
    if isinstance(exclude_paths, str):
        exclude_paths = (exclude_paths,)
    assert len(include_paths) + len(exclude_paths) > 0, 'Pass at least one argument'
    _hook.include(include_paths)
    _hook.exclude(exclude_paths)
    # _hook.debug = debug
    enable = sys.version_info[0] >= 3   # enabled for all 3.x
    if enable and _hook not in sys.meta_path:
        sys.meta_path.insert(0, _hook)  # insert at beginning. This could be made a parameter

    # We could return the hook when there are ways of configuring it
    #return _hook 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:17,代碼來源:__init__.py

示例14: remove_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def remove_hooks():
    if _hook in sys.meta_path:
        sys.meta_path.remove(_hook) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:5,代碼來源:__init__.py

示例15: detect_hooks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import meta_path [as 別名]
def detect_hooks():
    """
    Returns True if the import hooks are installed, False if not.
    """
    return _hook in sys.meta_path
    # present = any([hasattr(hook, 'PY2FIXER') for hook in sys.meta_path])
    # return present 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:9,代碼來源:__init__.py


注:本文中的sys.meta_path方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。