当前位置: 首页>>代码示例>>Python>>正文


Python pkgutil.ImpImporter方法代码示例

本文整理汇总了Python中pkgutil.ImpImporter方法的典型用法代码示例。如果您正苦于以下问题:Python pkgutil.ImpImporter方法的具体用法?Python pkgutil.ImpImporter怎么用?Python pkgutil.ImpImporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkgutil的用法示例。


在下文中一共展示了pkgutil.ImpImporter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_importer_deprecated

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import ImpImporter [as 别名]
def test_importer_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpImporter("") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_pkgutil.py

示例2: test_importer_deprecated

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import ImpImporter [as 别名]
def test_importer_deprecated(self):
        with self.check_deprecated():
            pkgutil.ImpImporter("") 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:5,代码来源:test_pkgutil.py

示例3: __init__

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import ImpImporter [as 别名]
def __init__(self, path):
        super(PyModulePath, self).__init__()
        self.is_pymodule = self.is_file() and \
                           lexer.analyse_text(self.open().read()) == 1.0
        if self.is_pymodule:
            self.module = ImpImporter(str(self.resolve().parent)) \
                          .find_module(self.stem).load_module(self.stem) 
开发者ID:dhondta,项目名称:python-sploitkit,代码行数:9,代码来源:path.py

示例4: load_actions

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import ImpImporter [as 别名]
def load_actions(filters=None, log_exceptions=True):
  """Loads Actions from the actions directory, and instantiates them.

  Args:
    filters: list, strings with names of action classes to load. Loader will
        skip classes not listed. In the absence of this list no filters are
        applied.
    log_exceptions: bool, whether to supress exceptions and log their messages
        instead.

  Returns:
    A dictionary of actions, with their names as keys and instaniated Action
    classes as their values.

  Raises:
    AttributeError: if log_exceptions is False and Action classes are missing
        ACTION_NAME or FRIENDLY_NAME attributes, or the run method.
  """
  global _CACHED_ACTIONS
  if _CACHED_ACTIONS:
    return _CACHED_ACTIONS
  actions = {base_action.ActionType.SYNC: {}, base_action.ActionType.ASYNC: {}}
  importer = pkgutil.ImpImporter(os.path.abspath(
      os.path.join(os.path.dirname(__file__), '..', 'actions')))
  for module_name, module in importer.iter_modules():
    del module  # Not used.
    if module_name.endswith('_test') or module_name.startswith('base_action'):
      continue
    try:
      loaded_module = importer.find_module(module_name).load_module(module_name)
    except ImportError:
      logging.info('Error importing module %s', module_name)
      continue
    for obj_name, obj in inspect.getmembers(loaded_module):
      if inspect.isclass(obj) and issubclass(obj, base_action.BaseAction):
        if filters and obj.ACTION_NAME not in filters:
          continue
        # Defaults to async for backward compatibility.
        action_type = getattr(obj, 'ACTION_TYPE', base_action.ActionType.ASYNC)
        try:
          action = obj()
        except AttributeError as e:
          error_message = _INSTANTIATION_ERROR_MSG % (
              obj_name, module_name, e.message)
          if log_exceptions:
            logging.warning(error_message)
            continue
          else:
            raise AttributeError(error_message)
        if (
            action.ACTION_NAME in actions[base_action.ActionType.SYNC] or
            action.ACTION_NAME in actions[base_action.ActionType.ASYNC]):
          logging.warning(_DUPLICATE_ACTION_MSG, obj.ACTION_NAME)
          continue
        actions[action_type][action.ACTION_NAME] = action
  _CACHED_ACTIONS = actions
  return actions 
开发者ID:google,项目名称:loaner,代码行数:59,代码来源:action_loader.py


注:本文中的pkgutil.ImpImporter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。