(self, args=None, namespace=None)
| 1715 | return args |
| 1716 | |
| 1717 | def parse_known_args(self, args=None, namespace=None): |
| 1718 | # args default to the system args |
| 1719 | if args is None: |
| 1720 | args = _sys.argv[1:] |
| 1721 | |
| 1722 | # default Namespace built from parser defaults |
| 1723 | if namespace is None: |
| 1724 | namespace = Namespace() |
| 1725 | |
| 1726 | # add any action defaults that aren't present |
| 1727 | for action in self._actions: |
| 1728 | if action.dest is not SUPPRESS: |
| 1729 | if not hasattr(namespace, action.dest): |
| 1730 | if action.default is not SUPPRESS: |
| 1731 | default = action.default |
| 1732 | if isinstance(action.default, basestring): |
| 1733 | default = self._get_value(action, default) |
| 1734 | setattr(namespace, action.dest, default) |
| 1735 | |
| 1736 | # add any parser defaults that aren't present |
| 1737 | for dest in self._defaults: |
| 1738 | if not hasattr(namespace, dest): |
| 1739 | setattr(namespace, dest, self._defaults[dest]) |
| 1740 | |
| 1741 | # parse the arguments and exit if there are any errors |
| 1742 | try: |
| 1743 | namespace, args = self._parse_known_args(args, namespace) |
| 1744 | if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR): |
| 1745 | args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR)) |
| 1746 | delattr(namespace, _UNRECOGNIZED_ARGS_ATTR) |
| 1747 | return namespace, args |
| 1748 | except ArgumentError: |
| 1749 | err = _sys.exc_info()[1] |
| 1750 | self.error(str(err)) |
| 1751 | |
| 1752 | def _parse_known_args(self, arg_strings, namespace): |
| 1753 | # replace arg strings that are file references |
no test coverage detected