| 2095 | return self._parse_known_args2(args, namespace, intermixed=False) |
| 2096 | |
| 2097 | def _parse_known_args2(self, args, namespace, intermixed): |
| 2098 | if args is None: |
| 2099 | # args default to the system args |
| 2100 | args = _sys.argv[1:] |
| 2101 | else: |
| 2102 | # make sure that args are mutable |
| 2103 | args = list(args) |
| 2104 | |
| 2105 | # default Namespace built from parser defaults |
| 2106 | if namespace is None: |
| 2107 | namespace = Namespace() |
| 2108 | |
| 2109 | # add any action defaults that aren't present |
| 2110 | for action in self._actions: |
| 2111 | if action.dest is not SUPPRESS: |
| 2112 | if not hasattr(namespace, action.dest): |
| 2113 | if action.default is not SUPPRESS: |
| 2114 | setattr(namespace, action.dest, action.default) |
| 2115 | |
| 2116 | # add any parser defaults that aren't present |
| 2117 | for dest in self._defaults: |
| 2118 | if not hasattr(namespace, dest): |
| 2119 | setattr(namespace, dest, self._defaults[dest]) |
| 2120 | |
| 2121 | # parse the arguments and exit if there are any errors |
| 2122 | if self.exit_on_error: |
| 2123 | try: |
| 2124 | namespace, args = self._parse_known_args(args, namespace, intermixed) |
| 2125 | except ArgumentError as err: |
| 2126 | self.error(str(err)) |
| 2127 | else: |
| 2128 | namespace, args = self._parse_known_args(args, namespace, intermixed) |
| 2129 | |
| 2130 | if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR): |
| 2131 | args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR)) |
| 2132 | delattr(namespace, _UNRECOGNIZED_ARGS_ATTR) |
| 2133 | return namespace, args |
| 2134 | |
| 2135 | def _parse_known_args(self, arg_strings, namespace, intermixed): |
| 2136 | # replace arg strings that are file references |