CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
argparse._ActionsContainer Class Reference
Inheritance diagram for argparse._ActionsContainer:
argparse._ArgumentGroup argparse._ArgumentGroup argparse.ArgumentParser argparse.ArgumentParser argparse._MutuallyExclusiveGroup argparse._MutuallyExclusiveGroup argparse._MutuallyExclusiveGroup argparse._MutuallyExclusiveGroup

Public Member Functions

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

Public Attributes

 argument_default
 
 conflict_handler
 
 description
 
 prefix_chars
 

Private Member Functions

def _add_action
 
def _add_action
 
def _add_container_actions
 
def _add_container_actions
 
def _check_conflict
 
def _check_conflict
 
def _get_handler
 
def _get_handler
 
def _get_optional_kwargs
 
def _get_optional_kwargs
 
def _get_positional_kwargs
 
def _get_positional_kwargs
 
def _handle_conflict_error
 
def _handle_conflict_error
 
def _handle_conflict_resolve
 
def _handle_conflict_resolve
 
def _pop_action_class
 
def _pop_action_class
 
def _registry_get
 
def _registry_get
 
def _remove_action
 
def _remove_action
 

Private Attributes

 _action_groups
 
 _actions
 
 _defaults
 
 _has_negative_number_optionals
 
 _mutually_exclusive_groups
 
 _negative_number_matcher
 
 _option_string_actions
 
 _registries
 

Detailed Description

Definition at line 1165 of file argparse.py.

Constructor & Destructor Documentation

def argparse._ActionsContainer.__init__ (   self,
  description,
  prefix_chars,
  argument_default,
  conflict_handler 
)

Definition at line 1171 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__().

1172  conflict_handler):
1173  super(_ActionsContainer, self).__init__()
1175  self.description = description
1176  self.argument_default = argument_default
1177  self.prefix_chars = prefix_chars
1178  self.conflict_handler = conflict_handler
1179 
1180  # set up registries
1181  self._registries = {}
1182 
1183  # register actions
1184  self.register('action', None, _StoreAction)
1185  self.register('action', 'store', _StoreAction)
1186  self.register('action', 'store_const', _StoreConstAction)
1187  self.register('action', 'store_true', _StoreTrueAction)
1188  self.register('action', 'store_false', _StoreFalseAction)
1189  self.register('action', 'append', _AppendAction)
1190  self.register('action', 'append_const', _AppendConstAction)
1191  self.register('action', 'count', _CountAction)
1192  self.register('action', 'help', _HelpAction)
1193  self.register('action', 'version', _VersionAction)
1194  self.register('action', 'parsers', _SubParsersAction)
1195 
1196  # raise an exception if the conflict handler is invalid
1197  self._get_handler()
1198 
1199  # action storage
1200  self._actions = []
1201  self._option_string_actions = {}
1202 
1203  # groups
1204  self._action_groups = []
1205  self._mutually_exclusive_groups = []
1206 
1207  # defaults storage
1208  self._defaults = {}
1209 
1210  # determines whether an "option" looks like a negative number
1211  self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$')
1212 
1213  # whether or not there are any optionals that look like negative
1214  # numbers -- uses a list so it can be shared and edited
def argparse._ActionsContainer.__init__ (   self,
  description,
  prefix_chars,
  argument_default,
  conflict_handler 
)

Definition at line 1167 of file argparse.py.

References argparse._ActionsContainer.__init__(), argparse._ActionsContainer._action_groups, argparse._ActionsContainer._actions, argparse._ActionsContainer._defaults, argparse._ActionsContainer._get_handler(), argparse._ActionsContainer._has_negative_number_optionals, argparse._ActionsContainer._mutually_exclusive_groups, argparse._ActionsContainer._negative_number_matcher, argparse._ActionsContainer._option_string_actions, argparse._ActionsContainer._registries, argparse._ActionsContainer.argument_default, argparse._ActionsContainer.conflict_handler, ExpressionHisto< T >.description, argparse._ActionsContainer.description, argparse._ActionsContainer.prefix_chars, VarParsing.VarParsing.register(), and argparse._ActionsContainer.register().

1168  conflict_handler):
1169  super(_ActionsContainer, self).__init__()
1170 
1171  self.description = description
1172  self.argument_default = argument_default
1173  self.prefix_chars = prefix_chars
1174  self.conflict_handler = conflict_handler
1175 
1176  # set up registries
1177  self._registries = {}
1178 
1179  # register actions
1180  self.register('action', None, _StoreAction)
1181  self.register('action', 'store', _StoreAction)
1182  self.register('action', 'store_const', _StoreConstAction)
1183  self.register('action', 'store_true', _StoreTrueAction)
1184  self.register('action', 'store_false', _StoreFalseAction)
1185  self.register('action', 'append', _AppendAction)
1186  self.register('action', 'append_const', _AppendConstAction)
1187  self.register('action', 'count', _CountAction)
1188  self.register('action', 'help', _HelpAction)
1189  self.register('action', 'version', _VersionAction)
1190  self.register('action', 'parsers', _SubParsersAction)
1191 
1192  # raise an exception if the conflict handler is invalid
1193  self._get_handler()
1194 
1195  # action storage
1196  self._actions = []
1197  self._option_string_actions = {}
1198 
1199  # groups
1200  self._action_groups = []
1201  self._mutually_exclusive_groups = []
1202 
1203  # defaults storage
1204  self._defaults = {}
1205 
1206  # determines whether an "option" looks like a negative number
1207  self._negative_number_matcher = _re.compile(r'^-\d+|-\d*.\d+$')
1208 
1209  # whether or not there are any optionals that look like negative
1210  # numbers -- uses a list so it can be shared and edited

Member Function Documentation

def argparse._ActionsContainer._add_action (   self,
  action 
)
private

Definition at line 1277 of file argparse.py.

References argparse._ActionsContainer._add_action(), argparse._ActionsContainer._check_conflict(), argparse._ActionsContainer._has_negative_number_optionals, and argparse._ActionsContainer._option_string_actions.

1278  def _add_action(self, action):
1279  # resolve any conflicts
1280  self._check_conflict(action)
1281 
1282  # add to actions list
1283  self._actions.append(action)
1284  action.container = self
1285 
1286  # index the action by any option strings it has
1287  for option_string in action.option_strings:
1288  self._option_string_actions[option_string] = action
1289 
1290  # set the flag if any option strings look like negative numbers
1291  for option_string in action.option_strings:
1292  if self._negative_number_matcher.match(option_string):
1293  if not self._has_negative_number_optionals:
1294  self._has_negative_number_optionals.append(True)
1295 
1296  # return the created action
1297  return action
def argparse._ActionsContainer._add_action (   self,
  action 
)
private

Definition at line 1298 of file argparse.py.

References argparse._ActionsContainer._check_conflict(), argparse._ActionsContainer._has_negative_number_optionals, and argparse._ActionsContainer._option_string_actions.

Referenced by argparse._ActionsContainer._add_action(), argparse._ActionsContainer._add_container_actions(), and argparse._ActionsContainer.add_argument().

1299  def _add_action(self, action):
1300  # resolve any conflicts
1301  self._check_conflict(action)
1302 
1303  # add to actions list
1304  self._actions.append(action)
1305  action.container = self
1306 
1307  # index the action by any option strings it has
1308  for option_string in action.option_strings:
1309  self._option_string_actions[option_string] = action
1310 
1311  # set the flag if any option strings look like negative numbers
1312  for option_string in action.option_strings:
1313  if self._negative_number_matcher.match(option_string):
1314  if not self._has_negative_number_optionals:
1315  self._has_negative_number_optionals.append(True)
1316 
1317  # return the created action
1318  return action
def argparse._ActionsContainer._add_container_actions (   self,
  container 
)
private

Definition at line 1301 of file argparse.py.

References argparse._ActionsContainer._action_groups, argparse._ActionsContainer._add_action(), argparse._ActionsContainer._add_container_actions(), argparse._ActionsContainer.add_argument_group(), and argparse._ActionsContainer.add_mutually_exclusive_group().

1302  def _add_container_actions(self, container):
1303  # collect groups by titles
1304  title_group_map = {}
1305  for group in self._action_groups:
1306  if group.title in title_group_map:
1307  msg = _('cannot merge actions - two groups are named %r')
1308  raise ValueError(msg % (group.title))
1309  title_group_map[group.title] = group
1310 
1311  # map each action to its group
1312  group_map = {}
1313  for group in container._action_groups:
1314 
1315  # if a group with the title exists, use that, otherwise
1316  # create a new group matching the container's group
1317  if group.title not in title_group_map:
1318  title_group_map[group.title] = self.add_argument_group(
1319  title=group.title,
1320  description=group.description,
1321  conflict_handler=group.conflict_handler)
1322 
1323  # map the actions to their new group
1324  for action in group._group_actions:
1325  group_map[action] = title_group_map[group.title]
1326 
1327  # add container's mutually exclusive groups
1328  # NOTE: if add_mutually_exclusive_group ever gains title= and
1329  # description= then this code will need to be expanded as above
1330  for group in container._mutually_exclusive_groups:
1331  mutex_group = self.add_mutually_exclusive_group(
1332  required=group.required)
1333 
1334  # map the actions to their new mutex group
1335  for action in group._group_actions:
1336  group_map[action] = mutex_group
1337 
1338  # add all actions to this container or their group
1339  for action in container._actions:
1340  group_map.get(action, self)._add_action(action)
def argparse._ActionsContainer._add_container_actions (   self,
  container 
)
private

Definition at line 1322 of file argparse.py.

References argparse._ActionsContainer._action_groups, argparse._ActionsContainer._add_action(), argparse._ActionsContainer.add_argument_group(), and argparse._ActionsContainer.add_mutually_exclusive_group().

Referenced by argparse.ArgumentParser.__init__(), and argparse._ActionsContainer._add_container_actions().

1323  def _add_container_actions(self, container):
1324  # collect groups by titles
1325  title_group_map = {}
1326  for group in self._action_groups:
1327  if group.title in title_group_map:
1328  msg = _('cannot merge actions - two groups are named %r')
1329  raise ValueError(msg % (group.title))
1330  title_group_map[group.title] = group
1331 
1332  # map each action to its group
1333  group_map = {}
1334  for group in container._action_groups:
1335 
1336  # if a group with the title exists, use that, otherwise
1337  # create a new group matching the container's group
1338  if group.title not in title_group_map:
1339  title_group_map[group.title] = self.add_argument_group(
1340  title=group.title,
1341  description=group.description,
1342  conflict_handler=group.conflict_handler)
1343 
1344  # map the actions to their new group
1345  for action in group._group_actions:
1346  group_map[action] = title_group_map[group.title]
1347 
1348  # add container's mutually exclusive groups
1349  # NOTE: if add_mutually_exclusive_group ever gains title= and
1350  # description= then this code will need to be expanded as above
1351  for group in container._mutually_exclusive_groups:
1352  mutex_group = self.add_mutually_exclusive_group(
1353  required=group.required)
1354 
1355  # map the actions to their new mutex group
1356  for action in group._group_actions:
1357  group_map[action] = mutex_group
1358 
1359  # add all actions to this container or their group
1360  for action in container._actions:
1361  group_map.get(action, self)._add_action(action)
def argparse._ActionsContainer._check_conflict (   self,
  action 
)
private

Definition at line 1414 of file argparse.py.

References argparse._ActionsContainer._check_conflict(), argparse._ActionsContainer._get_handler(), argparse._ActionsContainer._option_string_actions, and argparse._ActionsContainer.conflict_handler.

1415  def _check_conflict(self, action):
1416 
1417  # find all options that conflict with this option
1418  confl_optionals = []
1419  for option_string in action.option_strings:
1420  if option_string in self._option_string_actions:
1421  confl_optional = self._option_string_actions[option_string]
1422  confl_optionals.append((option_string, confl_optional))
1423 
1424  # resolve any conflicts
1425  if confl_optionals:
1426  conflict_handler = self._get_handler()
1427  conflict_handler(action, confl_optionals)
def argparse._ActionsContainer._check_conflict (   self,
  action 
)
private

Definition at line 1426 of file argparse.py.

References argparse._ActionsContainer._get_handler(), argparse._ActionsContainer._option_string_actions, and argparse._ActionsContainer.conflict_handler.

Referenced by argparse._ActionsContainer._add_action(), and argparse._ActionsContainer._check_conflict().

1427  def _check_conflict(self, action):
1428 
1429  # find all options that conflict with this option
1430  confl_optionals = []
1431  for option_string in action.option_strings:
1432  if option_string in self._option_string_actions:
1433  confl_optional = self._option_string_actions[option_string]
1434  confl_optionals.append((option_string, confl_optional))
1435 
1436  # resolve any conflicts
1437  if confl_optionals:
1438  conflict_handler = self._get_handler()
1439  conflict_handler(action, confl_optionals)
def argparse._ActionsContainer._get_handler (   self)
private

Definition at line 1405 of file argparse.py.

References argparse._ActionsContainer._get_handler(), and argparse._ActionsContainer.conflict_handler.

1406  def _get_handler(self):
1407  # determine function from conflict handler string
1408  handler_func_name = '_handle_conflict_%s' % self.conflict_handler
1409  try:
1410  return getattr(self, handler_func_name)
1411  except AttributeError:
1412  msg = _('invalid conflict_resolution value: %r')
1413  raise ValueError(msg % self.conflict_handler)
def argparse._ActionsContainer._get_handler (   self)
private

Definition at line 1417 of file argparse.py.

References argparse._ActionsContainer.conflict_handler.

Referenced by argparse._ActionsContainer.__init__(), argparse._ActionsContainer._check_conflict(), and argparse._ActionsContainer._get_handler().

1418  def _get_handler(self):
1419  # determine function from conflict handler string
1420  handler_func_name = '_handle_conflict_%s' % self.conflict_handler
1421  try:
1422  return getattr(self, handler_func_name)
1423  except AttributeError:
1424  msg = _('invalid conflict_resolution value: %r')
1425  raise ValueError(msg % self.conflict_handler)
def argparse._ActionsContainer._get_optional_kwargs (   self,
  args,
  kwargs 
)
private

Definition at line 1357 of file argparse.py.

References argparse._ActionsContainer._get_optional_kwargs(), argparse._set, python.multivaluedict.dict, and argparse._ActionsContainer.prefix_chars.

1358  def _get_optional_kwargs(self, *args, **kwargs):
1359  # determine short and long option strings
1360  option_strings = []
1361  long_option_strings = []
1362  for option_string in args:
1363  # error on one-or-fewer-character option strings
1364  if len(option_string) < 2:
1365  msg = _('invalid option string %r: '
1366  'must be at least two characters long')
1367  raise ValueError(msg % option_string)
1368 
1369  # error on strings that don't start with an appropriate prefix
1370  if not option_string[0] in self.prefix_chars:
1371  msg = _('invalid option string %r: '
1372  'must start with a character %r')
1373  tup = option_string, self.prefix_chars
1374  raise ValueError(msg % tup)
1375 
1376  # error on strings that are all prefix characters
1377  if not (_set(option_string) - _set(self.prefix_chars)):
1378  msg = _('invalid option string %r: '
1379  'must contain characters other than %r')
1380  tup = option_string, self.prefix_chars
1381  raise ValueError(msg % tup)
1382 
1383  # strings starting with two prefix characters are long options
1384  option_strings.append(option_string)
1385  if option_string[0] in self.prefix_chars:
1386  if option_string[1] in self.prefix_chars:
1387  long_option_strings.append(option_string)
1388 
1389  # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
1390  dest = kwargs.pop('dest', None)
1391  if dest is None:
1392  if long_option_strings:
1393  dest_option_string = long_option_strings[0]
1394  else:
1395  dest_option_string = option_strings[0]
1396  dest = dest_option_string.lstrip(self.prefix_chars)
1397  dest = dest.replace('-', '_')
1398 
1399  # return the updated keyword arguments
1400  return dict(kwargs, dest=dest, option_strings=option_strings)
def argparse._ActionsContainer._get_optional_kwargs (   self,
  args,
  kwargs 
)
private

Definition at line 1378 of file argparse.py.

References python.multivaluedict.dict, and argparse._ActionsContainer.prefix_chars.

Referenced by argparse._ActionsContainer._get_optional_kwargs(), and argparse._ActionsContainer.add_argument().

1379  def _get_optional_kwargs(self, *args, **kwargs):
1380  # determine short and long option strings
1381  option_strings = []
1382  long_option_strings = []
1383  for option_string in args:
1384  # error on strings that don't start with an appropriate prefix
1385  if not option_string[0] in self.prefix_chars:
1386  msg = _('invalid option string %r: '
1387  'must start with a character %r')
1388  tup = option_string, self.prefix_chars
1389  raise ValueError(msg % tup)
1390 
1391  # strings starting with two prefix characters are long options
1392  option_strings.append(option_string)
1393  if option_string[0] in self.prefix_chars:
1394  if len(option_string) > 1:
1395  if option_string[1] in self.prefix_chars:
1396  long_option_strings.append(option_string)
1397 
1398  # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
1399  dest = kwargs.pop('dest', None)
1400  if dest is None:
1401  if long_option_strings:
1402  dest_option_string = long_option_strings[0]
1403  else:
1404  dest_option_string = option_strings[0]
1405  dest = dest_option_string.lstrip(self.prefix_chars)
1406  if not dest:
1407  msg = _('dest= is required for options like %r')
1408  raise ValueError(msg % option_string)
1409  dest = dest.replace('-', '_')
1410 
1411  # return the updated keyword arguments
1412  return dict(kwargs, dest=dest, option_strings=option_strings)
def argparse._ActionsContainer._get_positional_kwargs (   self,
  dest,
  kwargs 
)
private

Definition at line 1341 of file argparse.py.

References argparse._ActionsContainer._get_positional_kwargs(), and python.multivaluedict.dict.

1342  def _get_positional_kwargs(self, dest, **kwargs):
1343  # make sure required is not specified
1344  if 'required' in kwargs:
1345  msg = _("'required' is an invalid argument for positionals")
1346  raise TypeError(msg)
1347 
1348  # mark positional arguments as required if at least one is
1349  # always required
1350  if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
1351  kwargs['required'] = True
1352  if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
1353  kwargs['required'] = True
1354 
1355  # return the keyword arguments with no option strings
1356  return dict(kwargs, dest=dest, option_strings=[])
def argparse._ActionsContainer._get_positional_kwargs (   self,
  dest,
  kwargs 
)
private

Definition at line 1362 of file argparse.py.

References python.multivaluedict.dict.

Referenced by argparse._ActionsContainer._get_positional_kwargs(), and argparse._ActionsContainer.add_argument().

1363  def _get_positional_kwargs(self, dest, **kwargs):
1364  # make sure required is not specified
1365  if 'required' in kwargs:
1366  msg = _("'required' is an invalid argument for positionals")
1367  raise TypeError(msg)
1368 
1369  # mark positional arguments as required if at least one is
1370  # always required
1371  if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
1372  kwargs['required'] = True
1373  if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
1374  kwargs['required'] = True
1375 
1376  # return the keyword arguments with no option strings
1377  return dict(kwargs, dest=dest, option_strings=[])
def argparse._ActionsContainer._handle_conflict_error (   self,
  action,
  conflicting_actions 
)
private

Definition at line 1428 of file argparse.py.

References argparse._ActionsContainer._handle_conflict_error(), and join().

1429  def _handle_conflict_error(self, action, conflicting_actions):
1430  message = _('conflicting option string(s): %s')
1431  conflict_string = ', '.join([option_string
1432  for option_string, action
1433  in conflicting_actions])
1434  raise ArgumentError(action, message % conflict_string)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def argparse._ActionsContainer._handle_conflict_error (   self,
  action,
  conflicting_actions 
)
private

Definition at line 1440 of file argparse.py.

References join().

Referenced by argparse._ActionsContainer._handle_conflict_error().

1441  def _handle_conflict_error(self, action, conflicting_actions):
1442  message = _('conflicting option string(s): %s')
1443  conflict_string = ', '.join([option_string
1444  for option_string, action
1445  in conflicting_actions])
1446  raise ArgumentError(action, message % conflict_string)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def argparse._ActionsContainer._handle_conflict_resolve (   self,
  action,
  conflicting_actions 
)
private

Definition at line 1435 of file argparse.py.

References argparse._ActionsContainer._handle_conflict_resolve().

1436  def _handle_conflict_resolve(self, action, conflicting_actions):
1437 
1438  # remove all conflicting options
1439  for option_string, action in conflicting_actions:
1440 
1441  # remove the conflicting option
1442  action.option_strings.remove(option_string)
1443  self._option_string_actions.pop(option_string, None)
1444 
1445  # if the option now has no option string, remove it from the
1446  # container holding it
1447  if not action.option_strings:
1448  action.container._remove_action(action)
1449 
def argparse._ActionsContainer._handle_conflict_resolve (   self,
  action,
  conflicting_actions 
)
private

Definition at line 1447 of file argparse.py.

Referenced by argparse._ActionsContainer._handle_conflict_resolve().

1448  def _handle_conflict_resolve(self, action, conflicting_actions):
1449 
1450  # remove all conflicting options
1451  for option_string, action in conflicting_actions:
1452 
1453  # remove the conflicting option
1454  action.option_strings.remove(option_string)
1455  self._option_string_actions.pop(option_string, None)
1456 
1457  # if the option now has no option string, remove it from the
1458  # container holding it
1459  if not action.option_strings:
1460  action.container._remove_action(action)
1461 
def argparse._ActionsContainer._pop_action_class (   self,
  kwargs,
  default = None 
)
private

Definition at line 1401 of file argparse.py.

References argparse._ActionsContainer._pop_action_class(), and argparse._ActionsContainer._registry_get().

1402  def _pop_action_class(self, kwargs, default=None):
1403  action = kwargs.pop('action', default)
1404  return self._registry_get('action', action, action)
def argparse._ActionsContainer._pop_action_class (   self,
  kwargs,
  default = None 
)
private

Definition at line 1413 of file argparse.py.

References argparse._ActionsContainer._registry_get().

Referenced by argparse._ActionsContainer._pop_action_class(), argparse._ActionsContainer.add_argument(), and argparse.ArgumentParser.add_subparsers().

1414  def _pop_action_class(self, kwargs, default=None):
1415  action = kwargs.pop('action', default)
1416  return self._registry_get('action', action, action)
def argparse._ActionsContainer._registry_get (   self,
  registry_name,
  value,
  default = None 
)
private

Definition at line 1219 of file argparse.py.

References argparse._ActionsContainer._registries, argparse._ActionsContainer._registry_get(), and reco.get().

1220  def _registry_get(self, registry_name, value, default=None):
1221  return self._registries[registry_name].get(value, default)
T get(const Candidate &c)
Definition: component.h:56
def argparse._ActionsContainer._registry_get (   self,
  registry_name,
  value,
  default = None 
)
private

Definition at line 1223 of file argparse.py.

References argparse._ActionsContainer._registries, and reco.get().

Referenced by argparse.ArgumentParser._get_value(), argparse._ActionsContainer._pop_action_class(), argparse._ActionsContainer._registry_get(), and argparse._ActionsContainer.add_argument().

1224  def _registry_get(self, registry_name, value, default=None):
1225  return self._registries[registry_name].get(value, default)
T get(const Candidate &c)
Definition: component.h:56
def argparse._ActionsContainer._remove_action (   self,
  action 
)
private

Definition at line 1298 of file argparse.py.

References argparse._ActionsContainer._remove_action().

1299  def _remove_action(self, action):
1300  self._actions.remove(action)
def argparse._ActionsContainer._remove_action (   self,
  action 
)
private

Definition at line 1319 of file argparse.py.

Referenced by argparse._ActionsContainer._remove_action().

1320  def _remove_action(self, action):
1321  self._actions.remove(action)
def argparse._ActionsContainer.add_argument (   self,
  args,
  kwargs 
)
add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...)

Definition at line 1237 of file argparse.py.

References argparse._ActionsContainer._add_action(), argparse._ActionsContainer._defaults, argparse._ActionsContainer._get_optional_kwargs(), argparse._ActionsContainer._get_positional_kwargs(), argparse._ActionsContainer._pop_action_class(), argparse._ActionsContainer.add_argument(), argparse._ActionsContainer.argument_default, and argparse._ActionsContainer.prefix_chars.

1238  def add_argument(self, *args, **kwargs):
1239  """
1240  add_argument(dest, ..., name=value, ...)
1241  add_argument(option_string, option_string, ..., name=value, ...)
1242  """
1243 
1244  # if no positional args are supplied or only one is supplied and
1245  # it doesn't look like an option string, parse a positional
1246  # argument
1247  chars = self.prefix_chars
1248  if not args or len(args) == 1 and args[0][0] not in chars:
1249  kwargs = self._get_positional_kwargs(*args, **kwargs)
1250 
1251  # otherwise, we're adding an optional argument
1252  else:
1253  kwargs = self._get_optional_kwargs(*args, **kwargs)
1254 
1255  # if no default was supplied, use the parser-level default
1256  if 'default' not in kwargs:
1257  dest = kwargs['dest']
1258  if dest in self._defaults:
1259  kwargs['default'] = self._defaults[dest]
1260  elif self.argument_default is not None:
1261  kwargs['default'] = self.argument_default
1262 
1263  # create the action object, and add it to the parser
1264  action_class = self._pop_action_class(kwargs)
1265  action = action_class(**kwargs)
1266  return self._add_action(action)
def argparse._ActionsContainer.add_argument (   self,
  args,
  kwargs 
)
add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...)

Definition at line 1248 of file argparse.py.

References argparse._ActionsContainer._add_action(), argparse._callable(), argparse._ActionsContainer._defaults, argparse._ActionsContainer._get_optional_kwargs(), argparse._ActionsContainer._get_positional_kwargs(), argparse._ActionsContainer._pop_action_class(), argparse._ActionsContainer._registry_get(), argparse._ActionsContainer.argument_default, and argparse._ActionsContainer.prefix_chars.

Referenced by argparse.ArgumentParser.__init__(), and argparse._ActionsContainer.add_argument().

1249  def add_argument(self, *args, **kwargs):
1250  """
1251  add_argument(dest, ..., name=value, ...)
1252  add_argument(option_string, option_string, ..., name=value, ...)
1253  """
1254 
1255  # if no positional args are supplied or only one is supplied and
1256  # it doesn't look like an option string, parse a positional
1257  # argument
1258  chars = self.prefix_chars
1259  if not args or len(args) == 1 and args[0][0] not in chars:
1260  if args and 'dest' in kwargs:
1261  raise ValueError('dest supplied twice for positional argument')
1262  kwargs = self._get_positional_kwargs(*args, **kwargs)
1263 
1264  # otherwise, we're adding an optional argument
1265  else:
1266  kwargs = self._get_optional_kwargs(*args, **kwargs)
1267 
1268  # if no default was supplied, use the parser-level default
1269  if 'default' not in kwargs:
1270  dest = kwargs['dest']
1271  if dest in self._defaults:
1272  kwargs['default'] = self._defaults[dest]
1273  elif self.argument_default is not None:
1274  kwargs['default'] = self.argument_default
1275 
1276  # create the action object, and add it to the parser
1277  action_class = self._pop_action_class(kwargs)
1278  if not _callable(action_class):
1279  raise ValueError('unknown action "%s"' % action_class)
1280  action = action_class(**kwargs)
1281 
1282  # raise an error if the action type is not callable
1283  type_func = self._registry_get('type', action.type, action.type)
1284  if not _callable(type_func):
1285  raise ValueError('%r is not callable' % type_func)
1286 
1287  return self._add_action(action)
def _callable
Definition: argparse.py:94
def argparse._ActionsContainer.add_argument_group (   self,
  args,
  kwargs 
)

Definition at line 1267 of file argparse.py.

References argparse._ActionsContainer.add_argument_group().

1268  def add_argument_group(self, *args, **kwargs):
1269  group = _ArgumentGroup(self, *args, **kwargs)
1270  self._action_groups.append(group)
1271  return group
def argparse._ActionsContainer.add_argument_group (   self,
  args,
  kwargs 
)

Definition at line 1288 of file argparse.py.

Referenced by argparse.ArgumentParser.__init__(), argparse._ActionsContainer._add_container_actions(), argparse._ActionsContainer.add_argument_group(), and argparse.ArgumentParser.add_subparsers().

1289  def add_argument_group(self, *args, **kwargs):
1290  group = _ArgumentGroup(self, *args, **kwargs)
1291  self._action_groups.append(group)
1292  return group
def argparse._ActionsContainer.add_mutually_exclusive_group (   self,
  kwargs 
)

Definition at line 1272 of file argparse.py.

References argparse._ActionsContainer.add_mutually_exclusive_group().

1273  def add_mutually_exclusive_group(self, **kwargs):
1274  group = _MutuallyExclusiveGroup(self, **kwargs)
1275  self._mutually_exclusive_groups.append(group)
1276  return group
def argparse._ActionsContainer.add_mutually_exclusive_group (   self,
  kwargs 
)

Definition at line 1293 of file argparse.py.

Referenced by argparse._ActionsContainer._add_container_actions(), and argparse._ActionsContainer.add_mutually_exclusive_group().

1294  def add_mutually_exclusive_group(self, **kwargs):
1295  group = _MutuallyExclusiveGroup(self, **kwargs)
1296  self._mutually_exclusive_groups.append(group)
1297  return group
def argparse._ActionsContainer.get_default (   self,
  dest 
)

Definition at line 1238 of file argparse.py.

References argparse._ActionsContainer._actions.

1239  def get_default(self, dest):
1240  for action in self._actions:
1241  if action.dest == dest and action.default is not None:
1242  return action.default
1243  return self._defaults.get(dest, None)
1244 
def argparse._ActionsContainer.register (   self,
  registry_name,
  value,
  object 
)

Definition at line 1215 of file argparse.py.

References argparse._ActionsContainer.register().

1216  def register(self, registry_name, value, object):
1217  registry = self._registries.setdefault(registry_name, {})
1218  registry[value] = object
def argparse._ActionsContainer.register (   self,
  registry_name,
  value,
  object 
)

Definition at line 1219 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse.ArgumentParser.__init__(), and argparse._ActionsContainer.register().

1220  def register(self, registry_name, value, object):
1221  registry = self._registries.setdefault(registry_name, {})
1222  registry[value] = object
def argparse._ActionsContainer.set_defaults (   self,
  kwargs 
)

Definition at line 1225 of file argparse.py.

References argparse._ActionsContainer._actions, and argparse._ActionsContainer.set_defaults().

1226  def set_defaults(self, **kwargs):
1227  self._defaults.update(kwargs)
1228 
1229  # if these defaults match any existing arguments, replace
1230  # the previous default on the object with the new one
1231  for action in self._actions:
1232  if action.dest in kwargs:
1233  action.default = kwargs[action.dest]
def argparse._ActionsContainer.set_defaults (   self,
  kwargs 
)

Definition at line 1229 of file argparse.py.

References argparse._ActionsContainer._actions.

Referenced by argparse._ActionsContainer.set_defaults().

1230  def set_defaults(self, **kwargs):
1231  self._defaults.update(kwargs)
1232 
1233  # if these defaults match any existing arguments, replace
1234  # the previous default on the object with the new one
1235  for action in self._actions:
1236  if action.dest in kwargs:
1237  action.default = kwargs[action.dest]

Member Data Documentation

argparse._ActionsContainer._action_groups
private

Definition at line 1203 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ActionsContainer._add_container_actions(), and argparse.ArgumentParser.format_help().

argparse._ActionsContainer._actions
private

Definition at line 1199 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ArgumentGroup.__init__(), argparse.ArgumentParser._get_optional_actions(), argparse.ArgumentParser._get_positional_actions(), argparse.ArgumentParser._parse_known_args(), argparse.ArgumentParser.format_help(), argparse.ArgumentParser.format_usage(), argparse._ActionsContainer.get_default(), argparse.ArgumentParser.parse_known_args(), and argparse._ActionsContainer.set_defaults().

argparse._ActionsContainer._defaults
private

Definition at line 1207 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ArgumentGroup.__init__(), argparse._ActionsContainer.add_argument(), and argparse.ArgumentParser.parse_known_args().

argparse._ActionsContainer._has_negative_number_optionals
private

Definition at line 1214 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ArgumentGroup.__init__(), argparse._ActionsContainer._add_action(), and argparse.ArgumentParser._parse_optional().

argparse._ActionsContainer._mutually_exclusive_groups
private

Definition at line 1204 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse.ArgumentParser._parse_known_args(), argparse.ArgumentParser.add_subparsers(), argparse.ArgumentParser.format_help(), and argparse.ArgumentParser.format_usage().

argparse._ActionsContainer._negative_number_matcher
private

Definition at line 1210 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__().

argparse._ActionsContainer._option_string_actions
private

Definition at line 1200 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ArgumentGroup.__init__(), argparse._ActionsContainer._add_action(), argparse._ActionsContainer._check_conflict(), argparse.ArgumentParser._get_option_tuples(), argparse.ArgumentParser._parse_known_args(), and argparse.ArgumentParser._parse_optional().

argparse._ActionsContainer._registries
private

Definition at line 1180 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ArgumentGroup.__init__(), and argparse._ActionsContainer._registry_get().

argparse._ActionsContainer.argument_default

Definition at line 1175 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), and argparse._ActionsContainer.add_argument().

argparse._ActionsContainer.conflict_handler

Definition at line 1177 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse._ActionsContainer._check_conflict(), and argparse._ActionsContainer._get_handler().

argparse._ActionsContainer.description

Definition at line 1174 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), and argparse.ArgumentParser.format_help().

argparse._ActionsContainer.prefix_chars

Definition at line 1176 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__(), argparse.ArgumentParser._get_option_tuples(), argparse._ActionsContainer._get_optional_kwargs(), argparse.ArgumentParser._parse_known_args(), argparse.ArgumentParser._parse_optional(), and argparse._ActionsContainer.add_argument().