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