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 1023 of file argparse.py.
def argparse::_SubParsersAction::__init__ | ( | self, | |
option_strings, | |||
prog, | |||
parser_class, | |||
dest = SUPPRESS , |
|||
help = None , |
|||
metavar = None |
|||
) |
Definition at line 1031 of file argparse.py.
01038 : 01039 01040 self._prog_prefix = prog 01041 self._parser_class = parser_class 01042 self._name_parser_map = _collections.OrderedDict() 01043 self._choices_actions = [] 01044 01045 super(_SubParsersAction, self).__init__( 01046 option_strings=option_strings, 01047 dest=dest, 01048 nargs=PARSER, 01049 choices=self._name_parser_map, 01050 help=help, 01051 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 1071 of file argparse.py.
01072 : 01073 parser_name = values[0] 01074 arg_strings = values[1:] 01075 01076 # set the parser name if requested 01077 if self.dest is not SUPPRESS: 01078 setattr(namespace, self.dest, parser_name) 01079 01080 # select the parser 01081 try: 01082 parser = self._name_parser_map[parser_name] 01083 except KeyError: 01084 tup = parser_name, ', '.join(self._name_parser_map) 01085 msg = _('unknown parser %r (choices: %s)') % tup 01086 raise ArgumentError(self, msg) 01087 01088 # parse all the remaining options into the namespace 01089 # store any unrecognized options on the object, so that the top 01090 # level parser can decide what to do with them 01091 namespace, arg_strings = parser.parse_known_args(arg_strings, namespace) 01092 if arg_strings: 01093 vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, []) 01094 getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings) 01095 01096 01097 # ============== 01098 # Type classes 01099 # ==============
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 1068 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 1052 of file argparse.py.
01053 : 01054 # set prog from the existing prefix 01055 if kwargs.get('prog') is None: 01056 kwargs['prog'] = '%s %s' % (self._prog_prefix, name) 01057 01058 # create a pseudo-action to hold the choice help 01059 if 'help' in kwargs: 01060 help = kwargs.pop('help') 01061 choice_action = self._ChoicesPseudoAction(name, help) 01062 self._choices_actions.append(choice_action) 01063 01064 # create the parser and add it to the map 01065 parser = self._parser_class(**kwargs) 01066 self._name_parser_map[name] = parser 01067 return parser
Definition at line 1031 of file argparse.py.
Definition at line 1031 of file argparse.py.
Definition at line 1031 of file argparse.py.
Definition at line 1031 of file argparse.py.