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 1167 of file argparse.py.

Constructor & Destructor Documentation

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

Definition at line 1173 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__().

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

1308  def _add_action(self, action):
1309  # resolve any conflicts
1310  self._check_conflict(action)
1311 
1312  # add to actions list
1313  self._actions.append(action)
1314  action.container = self
1315 
1316  # index the action by any option strings it has
1317  for option_string in action.option_strings:
1318  self._option_string_actions[option_string] = action
1319 
1320  # set the flag if any option strings look like negative numbers
1321  for option_string in action.option_strings:
1322  if self._negative_number_matcher.match(option_string):
1323  if not self._has_negative_number_optionals:
1324  self._has_negative_number_optionals.append(True)
1325 
1326  # return the created action
1327  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 1331 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().

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

1436  def _check_conflict(self, action):
1437 
1438  # find all options that conflict with this option
1439  confl_optionals = []
1440  for option_string in action.option_strings:
1441  if option_string in self._option_string_actions:
1442  confl_optional = self._option_string_actions[option_string]
1443  confl_optionals.append((option_string, confl_optional))
1444 
1445  # resolve any conflicts
1446  if confl_optionals:
1447  conflict_handler = self._get_handler()
1448  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 1426 of file argparse.py.

References argparse._ActionsContainer.conflict_handler.

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

1427  def _get_handler(self):
1428  # determine function from conflict handler string
1429  handler_func_name = '_handle_conflict_%s' % self.conflict_handler
1430  try:
1431  return getattr(self, handler_func_name)
1432  except AttributeError:
1433  msg = _('invalid conflict_resolution value: %r')
1434  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 1387 of file argparse.py.

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

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

1388  def _get_optional_kwargs(self, *args, **kwargs):
1389  # determine short and long option strings
1390  option_strings = []
1391  long_option_strings = []
1392  for option_string in args:
1393  # error on strings that don't start with an appropriate prefix
1394  if not option_string[0] in self.prefix_chars:
1395  msg = _('invalid option string %r: '
1396  'must start with a character %r')
1397  tup = option_string, self.prefix_chars
1398  raise ValueError(msg % tup)
1399 
1400  # strings starting with two prefix characters are long options
1401  option_strings.append(option_string)
1402  if option_string[0] in self.prefix_chars:
1403  if len(option_string) > 1:
1404  if option_string[1] in self.prefix_chars:
1405  long_option_strings.append(option_string)
1406 
1407  # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
1408  dest = kwargs.pop('dest', None)
1409  if dest is None:
1410  if long_option_strings:
1411  dest_option_string = long_option_strings[0]
1412  else:
1413  dest_option_string = option_strings[0]
1414  dest = dest_option_string.lstrip(self.prefix_chars)
1415  if not dest:
1416  msg = _('dest= is required for options like %r')
1417  raise ValueError(msg % option_string)
1418  dest = dest.replace('-', '_')
1419 
1420  # return the updated keyword arguments
1421  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 1371 of file argparse.py.

References python.multivaluedict.dict.

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

1372  def _get_positional_kwargs(self, dest, **kwargs):
1373  # make sure required is not specified
1374  if 'required' in kwargs:
1375  msg = _("'required' is an invalid argument for positionals")
1376  raise TypeError(msg)
1377 
1378  # mark positional arguments as required if at least one is
1379  # always required
1380  if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
1381  kwargs['required'] = True
1382  if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
1383  kwargs['required'] = True
1384 
1385  # return the keyword arguments with no option strings
1386  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 1449 of file argparse.py.

References join().

Referenced by argparse._ActionsContainer._handle_conflict_error().

1450  def _handle_conflict_error(self, action, conflicting_actions):
1451  message = _('conflicting option string(s): %s')
1452  conflict_string = ', '.join([option_string
1453  for option_string, action
1454  in conflicting_actions])
1455  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 1456 of file argparse.py.

Referenced by argparse._ActionsContainer._handle_conflict_resolve().

1457  def _handle_conflict_resolve(self, action, conflicting_actions):
1458 
1459  # remove all conflicting options
1460  for option_string, action in conflicting_actions:
1461 
1462  # remove the conflicting option
1463  action.option_strings.remove(option_string)
1464  self._option_string_actions.pop(option_string, None)
1465 
1466  # if the option now has no option string, remove it from the
1467  # container holding it
1468  if not action.option_strings:
1469  action.container._remove_action(action)
1470 
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 1422 of file argparse.py.

References argparse._ActionsContainer._registry_get().

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

1423  def _pop_action_class(self, kwargs, default=None):
1424  action = kwargs.pop('action', default)
1425  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 1225 of file argparse.py.

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

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

1226  def _registry_get(self, registry_name, value, default=None):
1227  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 1328 of file argparse.py.

Referenced by argparse._ActionsContainer._remove_action().

1329  def _remove_action(self, action):
1330  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 1250 of file argparse.py.

References argparse._ActionsContainer._add_action(), argparse._callable(), argparse._ActionsContainer._defaults, argparse.ArgumentParser._get_formatter(), python.rootplot.argparse.ArgumentParser._get_formatter(), 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__(), argparse._ActionsContainer.add_argument(), and python.rootplot.argparse.HelpFormatter.add_arguments().

1251  def add_argument(self, *args, **kwargs):
1252  """
1253  add_argument(dest, ..., name=value, ...)
1254  add_argument(option_string, option_string, ..., name=value, ...)
1255  """
1256 
1257  # if no positional args are supplied or only one is supplied and
1258  # it doesn't look like an option string, parse a positional
1259  # argument
1260  chars = self.prefix_chars
1261  if not args or len(args) == 1 and args[0][0] not in chars:
1262  if args and 'dest' in kwargs:
1263  raise ValueError('dest supplied twice for positional argument')
1264  kwargs = self._get_positional_kwargs(*args, **kwargs)
1265 
1266  # otherwise, we're adding an optional argument
1267  else:
1268  kwargs = self._get_optional_kwargs(*args, **kwargs)
1269 
1270  # if no default was supplied, use the parser-level default
1271  if 'default' not in kwargs:
1272  dest = kwargs['dest']
1273  if dest in self._defaults:
1274  kwargs['default'] = self._defaults[dest]
1275  elif self.argument_default is not None:
1276  kwargs['default'] = self.argument_default
1277 
1278  # create the action object, and add it to the parser
1279  action_class = self._pop_action_class(kwargs)
1280  if not _callable(action_class):
1281  raise ValueError('unknown action "%s"' % (action_class,))
1282  action = action_class(**kwargs)
1283 
1284  # raise an error if the action type is not callable
1285  type_func = self._registry_get('type', action.type, action.type)
1286  if not _callable(type_func):
1287  raise ValueError('%r is not callable' % (type_func,))
1288 
1289  # raise an error if the metavar does not match the type
1290  if hasattr(self, "_get_formatter"):
1291  try:
1292  self._get_formatter()._format_args(action, None)
1293  except TypeError:
1294  raise ValueError("length of metavar tuple does not match nargs")
1295 
1296  return self._add_action(action)
def _callable
Definition: argparse.py:95
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 1297 of file argparse.py.

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

1298  def add_argument_group(self, *args, **kwargs):
1299  group = _ArgumentGroup(self, *args, **kwargs)
1300  self._action_groups.append(group)
1301  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 1302 of file argparse.py.

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

1303  def add_mutually_exclusive_group(self, **kwargs):
1304  group = _MutuallyExclusiveGroup(self, **kwargs)
1305  self._mutually_exclusive_groups.append(group)
1306  return group
def argparse._ActionsContainer.get_default (   self,
  dest 
)

Definition at line 1240 of file argparse.py.

References argparse._ActionsContainer._actions.

1241  def get_default(self, dest):
1242  for action in self._actions:
1243  if action.dest == dest and action.default is not None:
1244  return action.default
1245  return self._defaults.get(dest, None)
1246 
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 1221 of file argparse.py.

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

1222  def register(self, registry_name, value, object):
1223  registry = self._registries.setdefault(registry_name, {})
1224  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 1231 of file argparse.py.

References argparse._ActionsContainer._actions.

Referenced by argparse._ActionsContainer.set_defaults().

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

Member Data Documentation

argparse._ActionsContainer._action_groups
private

Definition at line 1205 of file argparse.py.

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

argparse._ActionsContainer._actions
private

Definition at line 1201 of file argparse.py.

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

argparse._ActionsContainer._defaults
private

Definition at line 1209 of file argparse.py.

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

argparse._ActionsContainer._has_negative_number_optionals
private

Definition at line 1216 of file argparse.py.

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

argparse._ActionsContainer._mutually_exclusive_groups
private

Definition at line 1206 of file argparse.py.

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

argparse._ActionsContainer._negative_number_matcher
private

Definition at line 1212 of file argparse.py.

Referenced by argparse._ActionsContainer.__init__().

argparse._ActionsContainer._option_string_actions
private

Definition at line 1202 of file argparse.py.

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

argparse._ActionsContainer._registries
private

Definition at line 1182 of file argparse.py.

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

argparse._ActionsContainer.argument_default

Definition at line 1177 of file argparse.py.

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

argparse._ActionsContainer.conflict_handler

Definition at line 1179 of file argparse.py.

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

argparse._ActionsContainer.description

Definition at line 1176 of file argparse.py.

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

argparse._ActionsContainer.prefix_chars

Definition at line 1178 of file argparse.py.

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