當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。