• Home
  • Raw
  • Download

Lines Matching refs:action

258     def add_argument(self, action):  argument
259 if action.help is not SUPPRESS:
263 invocations = [get_invocation(action)]
264 for subaction in self._iter_indented_subactions(action):
274 self._add_item(self._format_action, [action])
277 for action in actions:
278 self.add_argument(action)
314 for action in actions:
315 if action.option_strings:
316 optionals.append(action)
318 positionals.append(action)
403 for action in group._group_actions:
404 group_actions.add(action)
422 for i, action in enumerate(actions):
426 if action.help is SUPPRESS:
434 elif not action.option_strings:
435 default = self._get_default_metavar_for_positional(action)
436 part = self._format_args(action, default)
439 if action in group_actions:
448 option_string = action.option_strings[0]
452 if action.nargs == 0:
458 default = self._get_default_metavar_for_optional(action)
459 args_string = self._format_args(action, default)
463 if not action.required and action not in group_actions:
495 def _format_action(self, action): argument
501 action_header = self._format_action_invocation(action)
504 if not action.help:
524 if action.help:
525 help_text = self._expand_help(action)
536 for subaction in self._iter_indented_subactions(action):
542 def _format_action_invocation(self, action): argument
543 if not action.option_strings:
544 default = self._get_default_metavar_for_positional(action)
545 metavar, = self._metavar_formatter(action, default)(1)
553 if action.nargs == 0:
554 parts.extend(action.option_strings)
559 default = self._get_default_metavar_for_optional(action)
560 args_string = self._format_args(action, default)
561 for option_string in action.option_strings:
566 def _metavar_formatter(self, action, default_metavar): argument
567 if action.metavar is not None:
568 result = action.metavar
569 elif action.choices is not None:
570 choice_strs = [str(choice) for choice in action.choices]
582 def _format_args(self, action, default_metavar): argument
583 get_metavar = self._metavar_formatter(action, default_metavar)
584 if action.nargs is None:
586 elif action.nargs == OPTIONAL:
588 elif action.nargs == ZERO_OR_MORE:
590 elif action.nargs == ONE_OR_MORE:
592 elif action.nargs == REMAINDER:
594 elif action.nargs == PARSER:
596 elif action.nargs == SUPPRESS:
599 formats = ['%s' for _ in range(action.nargs)]
600 result = ' '.join(formats) % get_metavar(action.nargs)
603 def _expand_help(self, action): argument
604 params = dict(vars(action), prog=self._prog)
614 return self._get_help_string(action) % params
616 def _iter_indented_subactions(self, action): argument
618 get_subactions = action._get_subactions
640 def _get_help_string(self, action): argument
641 return action.help
643 def _get_default_metavar_for_optional(self, action): argument
644 return action.dest.upper()
646 def _get_default_metavar_for_positional(self, action): argument
647 return action.dest
679 def _get_help_string(self, action): argument
680 help = action.help
681 if '%(default)' not in action.help:
682 if action.default is not SUPPRESS:
684 if action.option_strings or action.nargs in defaulting_nargs:
697 def _get_default_metavar_for_optional(self, action): argument
698 return action.type.__name__
700 def _get_default_metavar_for_positional(self, action): argument
701 return action.type.__name__
1308 for action in self._actions:
1309 if action.dest in kwargs:
1310 action.default = kwargs[action.dest]
1313 for action in self._actions:
1314 if action.dest == dest and action.default is not None:
1315 return action.default
1353 action = action_class(**kwargs)
1356 type_func = self._registry_get('type', action.type, action.type)
1363 self._get_formatter()._format_args(action, None)
1367 return self._add_action(action)
1379 def _add_action(self, action): argument
1381 self._check_conflict(action)
1384 self._actions.append(action)
1385 action.container = self
1388 for option_string in action.option_strings:
1389 self._option_string_actions[option_string] = action
1392 for option_string in action.option_strings:
1398 return action
1400 def _remove_action(self, action): argument
1401 self._actions.remove(action)
1425 for action in group._group_actions:
1426 group_map[action] = title_group_map[group.title]
1436 for action in group._group_actions:
1437 group_map[action] = mutex_group
1440 for action in container._actions:
1441 group_map.get(action, self)._add_action(action)
1496 action = kwargs.pop('action', default)
1497 return self._registry_get('action', action, action)
1508 def _check_conflict(self, action): argument
1512 for option_string in action.option_strings:
1520 conflict_handler(action, confl_optionals)
1522 def _handle_conflict_error(self, action, conflicting_actions): argument
1527 for option_string, action
1529 raise ArgumentError(action, message % conflict_string)
1531 def _handle_conflict_resolve(self, action, conflicting_actions): argument
1534 for option_string, action in conflicting_actions:
1537 action.option_strings.remove(option_string)
1542 if not action.option_strings:
1543 action.container._remove_action(action)
1570 def _add_action(self, action): argument
1571 action = super(_ArgumentGroup, self)._add_action(action)
1572 self._group_actions.append(action)
1573 return action
1575 def _remove_action(self, action): argument
1576 super(_ArgumentGroup, self)._remove_action(action)
1577 self._group_actions.remove(action)
1587 def _add_action(self, action): argument
1588 if action.required:
1591 action = self._container._add_action(action)
1592 self._group_actions.append(action)
1593 return action
1595 def _remove_action(self, action): argument
1596 self._container._remove_action(action)
1597 self._group_actions.remove(action)
1667 action='help', default=SUPPRESS,
1722 action = parsers_class(option_strings=[], **kwargs)
1723 self._subparsers._add_action(action)
1726 return action
1728 def _add_action(self, action): argument
1729 if action.option_strings:
1730 self._optionals._add_action(action)
1732 self._positionals._add_action(action)
1733 return action
1736 return [action
1737 for action in self._actions
1738 if action.option_strings]
1741 return [action
1742 for action in self._actions
1743 if not action.option_strings]
1768 for action in self._actions:
1769 if action.dest is not SUPPRESS:
1770 if not hasattr(namespace, action.dest):
1771 if action.default is not SUPPRESS:
1772 setattr(namespace, action.dest, action.default)
1837 def take_action(action, argument_strings, option_string=None): argument
1838 seen_actions.add(action)
1839 argument_values = self._get_values(action, argument_strings)
1844 if argument_values is not action.default:
1845 seen_non_default_actions.add(action)
1846 for conflict_action in action_conflicts.get(action, []):
1850 raise ArgumentError(action, msg % action_name)
1855 action(self, namespace, argument_values, option_string)
1862 action, option_string, explicit_arg = option_tuple
1871 if action is None:
1878 arg_count = match_argument(action, 'A')
1885 action_tuples.append((action, [], option_string))
1891 action = optionals_map[option_string]
1895 raise ArgumentError(action, msg % explicit_arg)
1902 action_tuples.append((action, args, option_string))
1909 raise ArgumentError(action, msg % explicit_arg)
1917 arg_count = match_argument(action, selected_patterns)
1920 action_tuples.append((action, args, option_string))
1926 for action, args, option_string in action_tuples:
1927 take_action(action, args, option_string)
1943 for action, arg_count in zip(positionals, arg_counts):
1946 take_action(action, args)
1998 for action in self._actions:
1999 if action not in seen_actions:
2000 if action.required:
2001 required_actions.append(_get_action_name(action))
2007 if (action.default is not None and
2008 isinstance(action.default, str) and
2009 hasattr(namespace, action.dest) and
2010 action.default is getattr(namespace, action.dest)):
2011 setattr(namespace, action.dest,
2012 self._get_value(action, action.default))
2021 for action in group._group_actions:
2022 if action in seen_non_default_actions:
2027 names = [_get_action_name(action)
2028 for action in group._group_actions
2029 if action.help is not SUPPRESS]
2065 def _match_argument(self, action, arg_strings_pattern): argument
2067 nargs_pattern = self._get_nargs_pattern(action)
2079 action.nargs) % action.nargs
2080 msg = nargs_errors.get(action.nargs, default)
2081 raise ArgumentError(action, msg)
2092 pattern = ''.join([self._get_nargs_pattern(action)
2093 for action in actions_slice])
2113 action = self._option_string_actions[arg_string]
2114 return action, arg_string, None
2124 action = self._option_string_actions[option_string]
2125 return action, option_string, explicit_arg
2135 for action, option_string, explicit_arg in option_tuples])
2175 action = self._option_string_actions[option_string]
2176 tup = action, option_string, explicit_arg
2190 action = self._option_string_actions[option_string]
2191 tup = action, option_string, short_explicit_arg
2194 action = self._option_string_actions[option_string]
2195 tup = action, option_string, explicit_arg
2205 def _get_nargs_pattern(self, action): argument
2208 nargs = action.nargs
2243 if action.option_strings:
2275 a = [action for action in positionals
2276 if action.nargs in [PARSER, REMAINDER]]
2281 if [action.dest for group in self._mutually_exclusive_groups
2282 for action in group._group_actions if action in positionals]:
2292 for action in positionals:
2294 action.save_nargs = action.nargs
2296 action.nargs = SUPPRESS
2297 action.save_default = action.default
2298 action.default = SUPPRESS
2301 for action in positionals:
2303 if (hasattr(namespace, action.dest)
2304 and getattr(namespace, action.dest)==[]):
2306 warn('Do not expect %s in %s' % (action.dest, namespace))
2307 delattr(namespace, action.dest)
2310 for action in positionals:
2311 action.nargs = action.save_nargs
2312 action.default = action.save_default
2317 for action in optionals:
2318 action.save_required = action.required
2319 action.required = False
2327 for action in optionals:
2328 action.required = action.save_required
2338 def _get_values(self, action, arg_strings): argument
2340 if action.nargs not in [PARSER, REMAINDER]:
2347 if not arg_strings and action.nargs == OPTIONAL:
2348 if action.option_strings:
2349 value = action.const
2351 value = action.default
2353 value = self._get_value(action, value)
2354 self._check_value(action, value)
2358 elif (not arg_strings and action.nargs == ZERO_OR_MORE and
2359 not action.option_strings):
2360 if action.default is not None:
2361 value = action.default
2364 self._check_value(action, value)
2367 elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]:
2369 value = self._get_value(action, arg_string)
2370 self._check_value(action, value)
2373 elif action.nargs == REMAINDER:
2374 value = [self._get_value(action, v) for v in arg_strings]
2377 elif action.nargs == PARSER:
2378 value = [self._get_value(action, v) for v in arg_strings]
2379 self._check_value(action, value[0])
2382 elif action.nargs == SUPPRESS:
2387 value = [self._get_value(action, v) for v in arg_strings]
2389 self._check_value(action, v)
2394 def _get_value(self, action, arg_string): argument
2395 type_func = self._registry_get('type', action.type, action.type)
2398 raise ArgumentError(action, msg % type_func)
2406 name = getattr(action.type, '__name__', repr(action.type))
2408 raise ArgumentError(action, msg)
2412 name = getattr(action.type, '__name__', repr(action.type))
2415 raise ArgumentError(action, msg % args)
2420 def _check_value(self, action, value): argument
2422 if action.choices is not None and value not in action.choices:
2424 'choices': ', '.join(map(repr, action.choices))}
2426 raise ArgumentError(action, msg % args)