コード例 #1
0
ファイル: actions.py プロジェクト: hemanthk92/CaseRoutingDemo
def GetArgparseBuiltInAction(action):
    """Get an argparse.Action from a string.

  This function takes one of the supplied argparse.Action strings (see below)
  and returns the corresponding argparse.Action class.

  This "work around" is (e.g. hack) is necessary due to the fact these required
  action mappings are only exposed through subclasses of
  argparse._ActionsContainer as opposed to a static function or global variable.

  Args:
    action: string, one of the following supplied argparse.Action names:
      'store', 'store_const', 'store_false', 'append', 'append_const', 'count',
      'version', 'parsers'.

  Returns:
    argparse.Action, the action class to use.

  Raises:
    ValueError: For unknown action string.
  """
    # pylint:disable=protected-access
    # Disabling lint check to access argparse._ActionsContainer
    dummy_actions_container = argparse._ActionsContainer(
        description=None,
        prefix_chars=None,
        argument_default=None,
        conflict_handler='error')

    action_cls = dummy_actions_container._registry_get('action', action)

    if action_cls is None:
        raise ValueError('unknown action "{0}"'.format(action_cls))

    return action_cls
コード例 #2
0
def GetArgparseBuiltInAction(action):
  """Get an argparse.Action from a string.

  This function takes one of the supplied argparse.Action strings (see below)
  and returns the corresponding argparse.Action class.

  This "work around" is (e.g. hack) is necessary due to the fact these required
  action mappings are only exposed through subclasses of
  argparse._ActionsContainer as opposed to a static function or global variable.

  Args:
    action: string, one of the following supplied argparse.Action names:
      'store', 'store_const', 'store_false', 'append', 'append_const', 'count',
      'version', 'parsers'.

  Returns:
    argparse.Action, the action class to use.

  Raises:
    ValueError: For unknown action string.
  """
  # pylint:disable=protected-access
  # Disabling lint check to access argparse._ActionsContainer
  dummy_actions_container = argparse._ActionsContainer(description=None,
                                                       prefix_chars=None,
                                                       argument_default=None,
                                                       conflict_handler='error')

  action_cls = dummy_actions_container._registry_get('action', action)

  if action_cls is None:
    raise ValueError('unknown action "{0}"'.format(action))

  return action_cls