Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
argparse._MutuallyExclusiveGroup Class Reference
Inheritance diagram for argparse._MutuallyExclusiveGroup:
Inheritance graph
[legend]
Collaboration diagram for argparse._MutuallyExclusiveGroup:
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

 required
 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

 _container

Detailed Description

Definition at line 1518 of file argparse.py.


Constructor & Destructor Documentation

def argparse._MutuallyExclusiveGroup.__init__ (   self,
  container,
  required = False 
)

Definition at line 1520 of file argparse.py.

01520 
01521     def __init__(self, container, required=False):
01522         super(_MutuallyExclusiveGroup, self).__init__(container)
01523         self.required = required
01524         self._container = container

Here is the caller graph for this function:


Member Function Documentation

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

Reimplemented from argparse._ArgumentGroup.

Definition at line 1525 of file argparse.py.

01525 
01526     def _add_action(self, action):
01527         if action.required:
01528             msg = _('mutually exclusive arguments must be optional')
01529             raise ValueError(msg)
01530         action = self._container._add_action(action)
01531         self._group_actions.append(action)
01532         return action

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

Reimplemented from argparse._ArgumentGroup.

Definition at line 1533 of file argparse.py.

01533 
01534     def _remove_action(self, action):
01535         self._container._remove_action(action)
01536         self._group_actions.remove(action)
01537 

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

Definition at line 1523 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 1522 of file argparse.py.

Definition at line 1496 of file argparse.py.


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