Back to index

python3.2  3.2.2
Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
argparse._SubParsersAction Class Reference
Inheritance diagram for argparse._SubParsersAction:
Inheritance graph
[legend]
Collaboration diagram for argparse._SubParsersAction:
Collaboration graph
[legend]

List of all members.

Classes

class  _ChoicesPseudoAction

Public Member Functions

def __init__
def add_parser
def __call__
def __repr__

Public Attributes

 option_strings
 dest
 nargs
 const
 default
 type
 choices
 required
 help
 metavar
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _get_subactions

Private Attributes

 _prog_prefix
 _parser_class
 _name_parser_map
 _choices_actions

Detailed Description

Definition at line 1023 of file argparse.py.


Constructor & Destructor Documentation

def argparse._SubParsersAction.__init__ (   self,
  option_strings,
  prog,
  parser_class,
  dest = SUPPRESS,
  help = None,
  metavar = None 
)

Definition at line 1041 of file argparse.py.

01041 
01042                  metavar=None):
01043 
01044         self._prog_prefix = prog
01045         self._parser_class = parser_class
01046         self._name_parser_map = _collections.OrderedDict()
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)

Here is the caller graph for this function:


Member Function Documentation

def argparse._SubParsersAction.__call__ (   self,
  parser,
  namespace,
  values,
  option_string = None 
)

Reimplemented from argparse.Action.

Definition at line 1082 of file argparse.py.

01082 
01083     def __call__(self, parser, namespace, values, option_string=None):
01084         parser_name = values[0]
01085         arg_strings = values[1:]
01086 
01087         # set the parser name if requested
01088         if self.dest is not SUPPRESS:
01089             setattr(namespace, self.dest, parser_name)
01090 
01091         # select the parser
01092         try:
01093             parser = self._name_parser_map[parser_name]
01094         except KeyError:
01095             args = {'parser_name': parser_name,
01096                     'choices': ', '.join(self._name_parser_map)}
01097             msg = _('unknown parser %(parser_name)r (choices: %(choices)s)') % args
01098             raise ArgumentError(self, msg)
01099 
01100         # parse all the remaining options into the namespace
01101         # store any unrecognized options on the object, so that the top
01102         # level parser can decide what to do with them
01103         namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
01104         if arg_strings:
01105             vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
01106             getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
01107 
01108 
01109 # ==============
01110 # Type classes
01111 # ==============

Here is the call graph for this function:

def argparse._AttributeHolder.__repr__ (   self) [inherited]

Definition at line 121 of file argparse.py.

00121 
00122     def __repr__(self):
00123         type_name = type(self).__name__
00124         arg_strings = []
00125         for arg in self._get_args():
00126             arg_strings.append(repr(arg))
00127         for name, value in self._get_kwargs():
00128             arg_strings.append('%s=%r' % (name, value))
00129         return '%s(%s)' % (type_name, ', '.join(arg_strings))

Here is the call graph for this function:

Definition at line 1079 of file argparse.py.

01079 
01080     def _get_subactions(self):
01081         return self._choices_actions

def argparse._SubParsersAction.add_parser (   self,
  name,
  kwargs 
)

Definition at line 1056 of file argparse.py.

01056 
01057     def add_parser(self, name, **kwargs):
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         aliases = kwargs.pop('aliases', ())
01063 
01064         # create a pseudo-action to hold the choice help
01065         if 'help' in kwargs:
01066             help = kwargs.pop('help')
01067             choice_action = self._ChoicesPseudoAction(name, aliases, help)
01068             self._choices_actions.append(choice_action)
01069 
01070         # create the parser and add it to the map
01071         parser = self._parser_class(**kwargs)
01072         self._name_parser_map[name] = parser
01073 
01074         # make parser available under aliases also
01075         for alias in aliases:
01076             self._name_parser_map[alias] = parser
01077 
01078         return parser


Member Data Documentation

Definition at line 1046 of file argparse.py.

Definition at line 1045 of file argparse.py.

Definition at line 1044 of file argparse.py.

Definition at line 1043 of file argparse.py.

Definition at line 780 of file argparse.py.

argparse.Action.const [inherited]

Definition at line 777 of file argparse.py.

Definition at line 778 of file argparse.py.

argparse.Action.dest [inherited]
argparse.Action.help [inherited]

Definition at line 782 of file argparse.py.

Definition at line 783 of file argparse.py.

argparse.Action.nargs [inherited]

Definition at line 776 of file argparse.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 774 of file argparse.py.

Definition at line 781 of file argparse.py.

argparse.Action.type [inherited]

Definition at line 779 of file argparse.py.


The documentation for this class was generated from the following file: