Back to index

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

List of all members.

Public Member Functions

def __init__
def register
def set_defaults
def get_default
def add_argument
def add_argument_group
def add_mutually_exclusive_group

Public Attributes

 title
 description
 argument_default
 prefix_chars
 conflict_handler
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _add_action
def _remove_action

Private Attributes

 _group_actions
 _registries
 _actions
 _option_string_actions
 _defaults
 _has_negative_number_optionals
 _mutually_exclusive_groups

Detailed Description

Definition at line 1484 of file argparse.py.


Constructor & Destructor Documentation

def argparse._ArgumentGroup.__init__ (   self,
  container,
  title = None,
  description = None,
  kwargs 
)

Reimplemented from argparse._ActionsContainer.

Definition at line 1486 of file argparse.py.

01486 
01487     def __init__(self, container, title=None, description=None, **kwargs):
01488         # add any missing keyword arguments by checking the container
01489         update = kwargs.setdefault
01490         update('conflict_handler', container.conflict_handler)
01491         update('prefix_chars', container.prefix_chars)
01492         update('argument_default', container.argument_default)
01493         super_init = super(_ArgumentGroup, self).__init__
01494         super_init(description=description, **kwargs)
01495 
01496         # group attributes
01497         self.title = title
01498         self._group_actions = []
01499 
01500         # share most attributes with the container
01501         self._registries = container._registries
01502         self._actions = container._actions
01503         self._option_string_actions = container._option_string_actions
01504         self._defaults = container._defaults
01505         self._has_negative_number_optionals = \
01506             container._has_negative_number_optionals
01507         self._mutually_exclusive_groups = container._mutually_exclusive_groups

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def argparse._ArgumentGroup._add_action (   self,
  action 
) [private]

Reimplemented from argparse._ActionsContainer.

Reimplemented in argparse._MutuallyExclusiveGroup.

Definition at line 1508 of file argparse.py.

01508 
01509     def _add_action(self, action):
01510         action = super(_ArgumentGroup, self)._add_action(action)
01511         self._group_actions.append(action)
01512         return action

def argparse._ArgumentGroup._remove_action (   self,
  action 
) [private]

Reimplemented from argparse._ActionsContainer.

Reimplemented in argparse._MutuallyExclusiveGroup.

Definition at line 1513 of file argparse.py.

01513 
01514     def _remove_action(self, action):
01515         super(_ArgumentGroup, self)._remove_action(action)
01516         self._group_actions.remove(action)
01517 

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._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 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

Reimplemented from argparse._ActionsContainer.

Definition at line 1501 of file argparse.py.

Reimplemented from argparse._ActionsContainer.

Definition at line 1503 of file argparse.py.

Definition at line 1497 of file argparse.py.

Reimplemented from argparse._ActionsContainer.

Definition at line 1504 of file argparse.py.

Reimplemented from argparse._ActionsContainer.

Definition at line 1506 of file argparse.py.

Reimplemented from argparse._ActionsContainer.

Definition at line 1502 of file argparse.py.

Reimplemented from argparse._ActionsContainer.

Definition at line 1500 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 107 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 1496 of file argparse.py.


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