Classes | |
class | _ChoicesPseudoAction |
Public Member Functions | |
def | __call__ |
def | __call__ |
def | __init__ |
def | __init__ |
def | add_parser |
def | add_parser |
Private Member Functions | |
def | _get_subactions |
def | _get_subactions |
Private Attributes | |
_choices_actions | |
_name_parser_map | |
_parser_class | |
_prog_prefix |
Definition at line 1022 of file argparse.py.
def argparse::_SubParsersAction::__init__ | ( | self, | |
option_strings, | |||
prog, | |||
parser_class, | |||
dest = SUPPRESS , |
|||
help = None , |
|||
metavar = None |
|||
) |
Definition at line 1030 of file argparse.py.
01037 : 01038 01039 self._prog_prefix = prog 01040 self._parser_class = parser_class 01041 self._name_parser_map = {} 01042 self._choices_actions = [] 01043 01044 super(_SubParsersAction, self).__init__( 01045 option_strings=option_strings, 01046 dest=dest, 01047 nargs=PARSER, 01048 choices=self._name_parser_map, 01049 help=help, 01050 metavar=metavar)
def argparse::_SubParsersAction::__init__ | ( | self, | |
option_strings, | |||
prog, | |||
parser_class, | |||
dest = SUPPRESS , |
|||
help = None , |
|||
metavar = None |
|||
) |
Definition at line 1036 of file argparse.py.
01042 : 01043 01044 self._prog_prefix = prog 01045 self._parser_class = parser_class 01046 self._name_parser_map = {} 01047 self._choices_actions = [] 01048 01049 super(_SubParsersAction, self).__init__( 01050 option_strings=option_strings, 01051 dest=dest, 01052 nargs=PARSER, 01053 choices=self._name_parser_map, 01054 help=help, 01055 metavar=metavar) 01056
def argparse::_SubParsersAction::__call__ | ( | self, | |
parser, | |||
namespace, | |||
values, | |||
option_string = None |
|||
) |
Reimplemented from argparse::Action.
Definition at line 1070 of file argparse.py.
01071 : 01072 parser_name = values[0] 01073 arg_strings = values[1:] 01074 01075 # set the parser name if requested 01076 if self.dest is not SUPPRESS: 01077 setattr(namespace, self.dest, parser_name) 01078 01079 # select the parser 01080 try: 01081 parser = self._name_parser_map[parser_name] 01082 except KeyError: 01083 tup = parser_name, ', '.join(self._name_parser_map) 01084 msg = _('unknown parser %r (choices: %s)' % tup) 01085 raise ArgumentError(self, msg) 01086 01087 # parse all the remaining options into the namespace 01088 # store any unrecognized options on the object, so that the top 01089 # level parser can decide what to do with them 01090 namespace, arg_strings = parser.parse_known_args(arg_strings, namespace) 01091 if arg_strings: 01092 vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, []) 01093 getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings) 01094 01095 01096 # ============== 01097 # Type classes 01098 # ==============
def argparse::_SubParsersAction::__call__ | ( | self, | |
parser, | |||
namespace, | |||
values, | |||
option_string = None |
|||
) |
Reimplemented from argparse::Action.
Definition at line 1076 of file argparse.py.
01076 : 01077 parser_name = values[0] 01078 arg_strings = values[1:] 01079 01080 # set the parser name if requested 01081 if self.dest is not SUPPRESS: 01082 setattr(namespace, self.dest, parser_name) 01083 01084 # select the parser 01085 try: 01086 parser = self._name_parser_map[parser_name] 01087 except KeyError: 01088 tup = parser_name, ', '.join(self._name_parser_map) 01089 msg = _('unknown parser %r (choices: %s)' % tup) 01090 raise ArgumentError(self, msg) 01091 01092 # parse all the remaining options into the namespace 01093 parser.parse_args(arg_strings, namespace) 01094 01095 01096 # ============== 01097 # Type classes 01098 # ============== 01099
def argparse::_SubParsersAction::_get_subactions | ( | self | ) | [private] |
Definition at line 1073 of file argparse.py.
01073 : 01074 return self._choices_actions 01075
def argparse::_SubParsersAction::_get_subactions | ( | self | ) | [private] |
Definition at line 1067 of file argparse.py.
def argparse::_SubParsersAction::add_parser | ( | self, | |
name, | |||
kwargs | |||
) |
Definition at line 1057 of file argparse.py.
01057 : 01058 # set prog from the existing prefix 01059 if kwargs.get('prog') is None: 01060 kwargs['prog'] = '%s %s' % (self._prog_prefix, name) 01061 01062 # create a pseudo-action to hold the choice help 01063 if 'help' in kwargs: 01064 help = kwargs.pop('help') 01065 choice_action = self._ChoicesPseudoAction(name, help) 01066 self._choices_actions.append(choice_action) 01067 01068 # create the parser and add it to the map 01069 parser = self._parser_class(**kwargs) 01070 self._name_parser_map[name] = parser 01071 return parser 01072
def argparse::_SubParsersAction::add_parser | ( | self, | |
name, | |||
kwargs | |||
) |
Definition at line 1051 of file argparse.py.
01052 : 01053 # set prog from the existing prefix 01054 if kwargs.get('prog') is None: 01055 kwargs['prog'] = '%s %s' % (self._prog_prefix, name) 01056 01057 # create a pseudo-action to hold the choice help 01058 if 'help' in kwargs: 01059 help = kwargs.pop('help') 01060 choice_action = self._ChoicesPseudoAction(name, help) 01061 self._choices_actions.append(choice_action) 01062 01063 # create the parser and add it to the map 01064 parser = self._parser_class(**kwargs) 01065 self._name_parser_map[name] = parser 01066 return parser
Definition at line 1030 of file argparse.py.
Definition at line 1030 of file argparse.py.
Definition at line 1030 of file argparse.py.
Definition at line 1030 of file argparse.py.