Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_argparse.ErrorRaisingArgumentParser Class Reference
Inheritance diagram for test.test_argparse.ErrorRaisingArgumentParser:
Inheritance graph
[legend]
Collaboration diagram for test.test_argparse.ErrorRaisingArgumentParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def parse_args
def exit
def error
def add_subparsers
def parse_known_args
def convert_arg_line_to_args
def format_usage
def format_help
def format_version
def print_usage
def print_help
def print_version
def error
def __repr__
def register
def set_defaults
def get_default
def add_argument
def add_argument_group
def add_mutually_exclusive_group

Public Attributes

 prog
 usage
 epilog
 version
 formatter_class
 fromfile_prefix_chars
 add_help
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
struct _typeobjectob_type
 description
 argument_default
 prefix_chars
 conflict_handler

Detailed Description

Definition at line 123 of file test_argparse.py.


Member Function Documentation

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:

def argparse._ActionsContainer.add_argument (   self,
  args,
  kwargs 
) [inherited]
add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...)

Definition at line 1260 of file argparse.py.

01260 
01261     def add_argument(self, *args, **kwargs):
01262         """
01263         add_argument(dest, ..., name=value, ...)
01264         add_argument(option_string, option_string, ..., name=value, ...)
01265         """
01266 
01267         # if no positional args are supplied or only one is supplied and
01268         # it doesn't look like an option string, parse a positional
01269         # argument
01270         chars = self.prefix_chars
01271         if not args or len(args) == 1 and args[0][0] not in chars:
01272             if args and 'dest' in kwargs:
01273                 raise ValueError('dest supplied twice for positional argument')
01274             kwargs = self._get_positional_kwargs(*args, **kwargs)
01275 
01276         # otherwise, we're adding an optional argument
01277         else:
01278             kwargs = self._get_optional_kwargs(*args, **kwargs)
01279 
01280         # if no default was supplied, use the parser-level default
01281         if 'default' not in kwargs:
01282             dest = kwargs['dest']
01283             if dest in self._defaults:
01284                 kwargs['default'] = self._defaults[dest]
01285             elif self.argument_default is not None:
01286                 kwargs['default'] = self.argument_default
01287 
01288         # create the action object, and add it to the parser
01289         action_class = self._pop_action_class(kwargs)
01290         if not _callable(action_class):
01291             raise ValueError('unknown action "%s"' % (action_class,))
01292         action = action_class(**kwargs)
01293 
01294         # raise an error if the action type is not callable
01295         type_func = self._registry_get('type', action.type, action.type)
01296         if not _callable(type_func):
01297             raise ValueError('%r is not callable' % (type_func,))
01298 
01299         # raise an error if the metavar does not match the type
01300         if hasattr(self, "_get_formatter"):
01301             try:
01302                 self._get_formatter()._format_args(action, None)
01303             except TypeError:
01304                 raise ValueError("length of metavar tuple does not match nargs")
01305 
01306         return self._add_action(action)

Here is the call graph for this function:

def argparse._ActionsContainer.add_argument_group (   self,
  args,
  kwargs 
) [inherited]

Definition at line 1307 of file argparse.py.

01307 
01308     def add_argument_group(self, *args, **kwargs):
01309         group = _ArgumentGroup(self, *args, **kwargs)
01310         self._action_groups.append(group)
01311         return group

Here is the caller graph for this function:

def argparse._ActionsContainer.add_mutually_exclusive_group (   self,
  kwargs 
) [inherited]

Definition at line 1312 of file argparse.py.

01312 
01313     def add_mutually_exclusive_group(self, **kwargs):
01314         group = _MutuallyExclusiveGroup(self, **kwargs)
01315         self._mutually_exclusive_groups.append(group)
01316         return group

Here is the caller graph for this function:

def argparse.ArgumentParser.add_subparsers (   self,
  kwargs 
) [inherited]

Definition at line 1649 of file argparse.py.

01649 
01650     def add_subparsers(self, **kwargs):
01651         if self._subparsers is not None:
01652             self.error(_('cannot have multiple subparser arguments'))
01653 
01654         # add the parser class to the arguments if it's not present
01655         kwargs.setdefault('parser_class', type(self))
01656 
01657         if 'title' in kwargs or 'description' in kwargs:
01658             title = _(kwargs.pop('title', 'subcommands'))
01659             description = _(kwargs.pop('description', None))
01660             self._subparsers = self.add_argument_group(title, description)
01661         else:
01662             self._subparsers = self._positionals
01663 
01664         # prog defaults to the usage message of this parser, skipping
01665         # optional arguments and with no "usage:" prefix
01666         if kwargs.get('prog') is None:
01667             formatter = self._get_formatter()
01668             positionals = self._get_positional_actions()
01669             groups = self._mutually_exclusive_groups
01670             formatter.add_usage(self.usage, positionals, groups, '')
01671             kwargs['prog'] = formatter.format_help().strip()
01672 
01673         # create the parsers action and add it to the positionals list
01674         parsers_class = self._pop_action_class(kwargs, 'parsers')
01675         action = parsers_class(option_strings=[], **kwargs)
01676         self._subparsers._add_action(action)
01677 
01678         # return the created parsers action
01679         return action

Here is the call graph for this function:

def argparse.ArgumentParser.convert_arg_line_to_args (   self,
  arg_line 
) [inherited]

Reimplemented in test.test_argparse.TestArgumentsFromFileConverter.FromFileConverterArgumentParser.

Definition at line 2006 of file argparse.py.

02006 
02007     def convert_arg_line_to_args(self, arg_line):
02008         return [arg_line]

Here is the caller graph for this function:

def test.test_argparse.ErrorRaisingArgumentParser.error (   self,
  args,
  kwargs 
)

Definition at line 133 of file test_argparse.py.

00133 
00134     def error(self, *args, **kwargs):
00135         error = super(ErrorRaisingArgumentParser, self).error
00136         return stderr_to_parser_error(error, *args, **kwargs)
00137 

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse.ArgumentParser.error (   self,
  message 
) [inherited]
error(message: string)

Prints a usage message incorporating the message to stderr and
exits.

If you override this in a subclass, it should not return -- it
should either exit or raise an exception.

Definition at line 2355 of file argparse.py.

02355 
02356     def error(self, message):
02357         """error(message: string)
02358 
02359         Prints a usage message incorporating the message to stderr and
02360         exits.
02361 
02362         If you override this in a subclass, it should not return -- it
02363         should either exit or raise an exception.
02364         """
02365         self.print_usage(_sys.stderr)
02366         args = {'prog': self.prog, 'message': message}
02367         self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_argparse.ErrorRaisingArgumentParser.exit (   self,
  args,
  kwargs 
)

Reimplemented from argparse.ArgumentParser.

Definition at line 129 of file test_argparse.py.

00129 
00130     def exit(self, *args, **kwargs):
00131         exit = super(ErrorRaisingArgumentParser, self).exit
00132         return stderr_to_parser_error(exit, *args, **kwargs)

Here is the call graph for this function:

def argparse.ArgumentParser.format_help (   self) [inherited]

Definition at line 2284 of file argparse.py.

02284 
02285     def format_help(self):
02286         formatter = self._get_formatter()
02287 
02288         # usage
02289         formatter.add_usage(self.usage, self._actions,
02290                             self._mutually_exclusive_groups)
02291 
02292         # description
02293         formatter.add_text(self.description)
02294 
02295         # positionals, optionals and user-defined groups
02296         for action_group in self._action_groups:
02297             formatter.start_section(action_group.title)
02298             formatter.add_text(action_group.description)
02299             formatter.add_arguments(action_group._group_actions)
02300             formatter.end_section()
02301 
02302         # epilog
02303         formatter.add_text(self.epilog)
02304 
02305         # determine help from format above
02306         return formatter.format_help()

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse.ArgumentParser.format_usage (   self) [inherited]

Definition at line 2278 of file argparse.py.

02278 
02279     def format_usage(self):
02280         formatter = self._get_formatter()
02281         formatter.add_usage(self.usage, self._actions,
02282                             self._mutually_exclusive_groups)
02283         return formatter.format_help()

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse.ArgumentParser.format_version (   self) [inherited]

Definition at line 2307 of file argparse.py.

02307 
02308     def format_version(self):
02309         import warnings
02310         warnings.warn(
02311             'The format_version method is deprecated -- the "version" '
02312             'argument to ArgumentParser is no longer supported.',
02313             DeprecationWarning)
02314         formatter = self._get_formatter()
02315         formatter.add_text(self.version)
02316         return formatter.format_help()

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse._ActionsContainer.get_default (   self,
  dest 
) [inherited]

Definition at line 1250 of file argparse.py.

01250 
01251     def get_default(self, dest):
01252         for action in self._actions:
01253             if action.dest == dest and action.default is not None:
01254                 return action.default
01255         return self._defaults.get(dest, None)
01256 

def test.test_argparse.ErrorRaisingArgumentParser.parse_args (   self,
  args,
  kwargs 
)

Reimplemented from argparse.ArgumentParser.

Definition at line 125 of file test_argparse.py.

00125 
00126     def parse_args(self, *args, **kwargs):
00127         parse_args = super(ErrorRaisingArgumentParser, self).parse_args
00128         return stderr_to_parser_error(parse_args, *args, **kwargs)

Here is the call graph for this function:

def argparse.ArgumentParser.parse_known_args (   self,
  args = None,
  namespace = None 
) [inherited]

Definition at line 1707 of file argparse.py.

01707 
01708     def parse_known_args(self, args=None, namespace=None):
01709         # args default to the system args
01710         if args is None:
01711             args = _sys.argv[1:]
01712 
01713         # default Namespace built from parser defaults
01714         if namespace is None:
01715             namespace = Namespace()
01716 
01717         # add any action defaults that aren't present
01718         for action in self._actions:
01719             if action.dest is not SUPPRESS:
01720                 if not hasattr(namespace, action.dest):
01721                     if action.default is not SUPPRESS:
01722                         default = action.default
01723                         if isinstance(action.default, str):
01724                             default = self._get_value(action, default)
01725                         setattr(namespace, action.dest, default)
01726 
01727         # add any parser defaults that aren't present
01728         for dest in self._defaults:
01729             if not hasattr(namespace, dest):
01730                 setattr(namespace, dest, self._defaults[dest])
01731 
01732         # parse the arguments and exit if there are any errors
01733         try:
01734             namespace, args = self._parse_known_args(args, namespace)
01735             if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
01736                 args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
01737                 delattr(namespace, _UNRECOGNIZED_ARGS_ATTR)
01738             return namespace, args
01739         except ArgumentError:
01740             err = _sys.exc_info()[1]
01741             self.error(str(err))

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse.ArgumentParser.print_help (   self,
  file = None 
) [inherited]

Definition at line 2328 of file argparse.py.

02328 
02329     def print_help(self, file=None):
02330         if file is None:
02331             file = _sys.stdout
02332         self._print_message(self.format_help(), file)

Here is the call graph for this function:

def argparse.ArgumentParser.print_usage (   self,
  file = None 
) [inherited]

Definition at line 2323 of file argparse.py.

02323 
02324     def print_usage(self, file=None):
02325         if file is None:
02326             file = _sys.stdout
02327         self._print_message(self.format_usage(), file)

Here is the call graph for this function:

Here is the caller graph for this function:

def argparse.ArgumentParser.print_version (   self,
  file = None 
) [inherited]

Definition at line 2333 of file argparse.py.

02333 
02334     def print_version(self, file=None):
02335         import warnings
02336         warnings.warn(
02337             'The print_version method is deprecated -- the "version" '
02338             'argument to ArgumentParser is no longer supported.',
02339             DeprecationWarning)
02340         self._print_message(self.format_version(), file)

Here is the call graph for this function:

def argparse._ActionsContainer.register (   self,
  registry_name,
  value,
  object 
) [inherited]

Definition at line 1231 of file argparse.py.

01231 
01232     def register(self, registry_name, value, object):
01233         registry = self._registries.setdefault(registry_name, {})
01234         registry[value] = object

Here is the caller graph for this function:

def argparse._ActionsContainer.set_defaults (   self,
  kwargs 
) [inherited]

Definition at line 1241 of file argparse.py.

01241 
01242     def set_defaults(self, **kwargs):
01243         self._defaults.update(kwargs)
01244 
01245         # if these defaults match any existing arguments, replace
01246         # the previous default on the object with the new one
01247         for action in self._actions:
01248             if action.dest in kwargs:
01249                 action.default = kwargs[action.dest]


Member Data Documentation

Definition at line 1594 of file argparse.py.

Definition at line 1187 of file argparse.py.

Definition at line 1189 of file argparse.py.

Definition at line 1186 of file argparse.py.

Definition at line 1590 of file argparse.py.

Definition at line 1592 of file argparse.py.

Definition at line 1593 of file argparse.py.

Definition at line 107 of file object.h.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 1188 of file argparse.py.

Definition at line 1588 of file argparse.py.

Definition at line 1589 of file argparse.py.

Definition at line 1591 of file argparse.py.


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