(self, arg_strings, namespace)
| 1749 | self.error(str(err)) |
| 1750 | |
| 1751 | def _parse_known_args(self, arg_strings, namespace): |
| 1752 | # replace arg strings that are file references |
| 1753 | if self.fromfile_prefix_chars is not None: |
| 1754 | arg_strings = self._read_args_from_files(arg_strings) |
| 1755 | |
| 1756 | # map all mutually exclusive arguments to the other arguments |
| 1757 | # they can't occur with |
| 1758 | action_conflicts = {} |
| 1759 | for mutex_group in self._mutually_exclusive_groups: |
| 1760 | group_actions = mutex_group._group_actions |
| 1761 | for i, mutex_action in enumerate(mutex_group._group_actions): |
| 1762 | conflicts = action_conflicts.setdefault(mutex_action, []) |
| 1763 | conflicts.extend(group_actions[:i]) |
| 1764 | conflicts.extend(group_actions[i + 1:]) |
| 1765 | |
| 1766 | # find all option indices, and determine the arg_string_pattern |
| 1767 | # which has an 'O' if there is an option at an index, |
| 1768 | # an 'A' if there is an argument, or a '-' if there is a '--' |
| 1769 | option_string_indices = {} |
| 1770 | arg_string_pattern_parts = [] |
| 1771 | arg_strings_iter = iter(arg_strings) |
| 1772 | for i, arg_string in enumerate(arg_strings_iter): |
| 1773 | |
| 1774 | # all args after -- are non-options |
| 1775 | if arg_string == '--': |
| 1776 | arg_string_pattern_parts.append('-') |
| 1777 | for arg_string in arg_strings_iter: |
| 1778 | arg_string_pattern_parts.append('A') |
| 1779 | |
| 1780 | # otherwise, add the arg to the arg strings |
| 1781 | # and note the index if it was an option |
| 1782 | else: |
| 1783 | option_tuple = self._parse_optional(arg_string) |
| 1784 | if option_tuple is None: |
| 1785 | pattern = 'A' |
| 1786 | else: |
| 1787 | option_string_indices[i] = option_tuple |
| 1788 | pattern = 'O' |
| 1789 | arg_string_pattern_parts.append(pattern) |
| 1790 | |
| 1791 | # join the pieces together to form the pattern |
| 1792 | arg_strings_pattern = ''.join(arg_string_pattern_parts) |
| 1793 | |
| 1794 | # converts arg strings to the appropriate and then takes the action |
| 1795 | seen_actions = set() |
| 1796 | seen_non_default_actions = set() |
| 1797 | |
| 1798 | def take_action(action, argument_strings, option_string=None): |
| 1799 | seen_actions.add(action) |
| 1800 | argument_values = self._get_values(action, argument_strings) |
| 1801 | |
| 1802 | # error if this argument is not allowed with other previously |
| 1803 | # seen arguments, assuming that actions that use the default |
| 1804 | # value don't really count as "present" |
| 1805 | if argument_values is not action.default: |
| 1806 | seen_non_default_actions.add(action) |
| 1807 | for conflict_action in action_conflicts.get(action, []): |
| 1808 | if conflict_action in seen_non_default_actions: |
no test coverage detected