(self, arg_strings, namespace, intermixed)
| 2051 | return namespace, args |
| 2052 | |
| 2053 | def _parse_known_args(self, arg_strings, namespace, intermixed): |
| 2054 | # replace arg strings that are file references |
| 2055 | if self.fromfile_prefix_chars is not None: |
| 2056 | arg_strings = self._read_args_from_files(arg_strings) |
| 2057 | |
| 2058 | # map all mutually exclusive arguments to the other arguments |
| 2059 | # they can't occur with |
| 2060 | action_conflicts = {} |
| 2061 | for mutex_group in self._mutually_exclusive_groups: |
| 2062 | group_actions = mutex_group._group_actions |
| 2063 | for i, mutex_action in enumerate(mutex_group._group_actions): |
| 2064 | conflicts = action_conflicts.setdefault(mutex_action, []) |
| 2065 | conflicts.extend(group_actions[:i]) |
| 2066 | conflicts.extend(group_actions[i + 1:]) |
| 2067 | |
| 2068 | # find all option indices, and determine the arg_string_pattern |
| 2069 | # which has an 'O' if there is an option at an index, |
| 2070 | # an 'A' if there is an argument, or a '-' if there is a '--' |
| 2071 | option_string_indices = {} |
| 2072 | arg_string_pattern_parts = [] |
| 2073 | arg_strings_iter = iter(arg_strings) |
| 2074 | for i, arg_string in enumerate(arg_strings_iter): |
| 2075 | |
| 2076 | # all args after -- are non-options |
| 2077 | if arg_string == '--': |
| 2078 | arg_string_pattern_parts.append('-') |
| 2079 | for arg_string in arg_strings_iter: |
| 2080 | arg_string_pattern_parts.append('A') |
| 2081 | |
| 2082 | # otherwise, add the arg to the arg strings |
| 2083 | # and note the index if it was an option |
| 2084 | else: |
| 2085 | option_tuples = self._parse_optional(arg_string) |
| 2086 | if option_tuples is None: |
| 2087 | pattern = 'A' |
| 2088 | else: |
| 2089 | option_string_indices[i] = option_tuples |
| 2090 | pattern = 'O' |
| 2091 | arg_string_pattern_parts.append(pattern) |
| 2092 | |
| 2093 | # join the pieces together to form the pattern |
| 2094 | arg_strings_pattern = ''.join(arg_string_pattern_parts) |
| 2095 | |
| 2096 | # converts arg strings to the appropriate and then takes the action |
| 2097 | seen_actions = set() |
| 2098 | seen_non_default_actions = set() |
| 2099 | warned = set() |
| 2100 | |
| 2101 | def take_action(action, argument_strings, option_string=None): |
| 2102 | seen_actions.add(action) |
| 2103 | argument_values = self._get_values(action, argument_strings) |
| 2104 | |
| 2105 | # error if this argument is not allowed with other previously |
| 2106 | # seen arguments |
| 2107 | if action.option_strings or argument_strings: |
| 2108 | seen_non_default_actions.add(action) |
| 2109 | for conflict_action in action_conflicts.get(action, []): |
| 2110 | if conflict_action in seen_non_default_actions: |
no test coverage detected