| 111 | 111 | raise argparse.ArgumentTypeError(msg) from e |
| 112 | 112 | |
| 113 | 113 | |
| 114 | def _parse_regex_csv(value: str) -> list[str]: | |
| 115 | """Parse a comma-separated list of regex patterns, respecting escaped commas. | |
| 116 | ||
| 117 | Commas can be escaped with backslashes to include them in regex patterns. | |
| 118 | """ | |
| 119 | if not value: | |
| 120 | return [] | |
| 121 | ||
| 122 | patterns = [] | |
| 123 | current_pattern = "" | |
| 124 | i = 0 | |
| 125 | while i < len(value): | |
| 126 | if value[i] == '\\' and i + 1 < len(value) and value[i + 1] == ',': | |
| 127 | # Escaped comma - add the comma and skip the backslash | |
| 128 | current_pattern += ',' | |
| 129 | i += 2 | |
| 130 | elif value[i] == ',': | |
| 131 | # Unescaped comma - end of current pattern | |
| 132 | patterns.append(current_pattern.strip()) | |
| 133 | current_pattern = "" | |
| 134 | i += 1 | |
| 135 | else: | |
| 136 | # Regular character | |
| 137 | current_pattern += value[i] | |
| 138 | i += 1 | |
| 139 | ||
| 140 | # Add the last pattern if it exists | |
| 141 | if current_pattern.strip(): | |
| 142 | patterns.append(current_pattern.strip()) | |
| 143 | ||
| 144 | return patterns | |
| 145 | ||
| 146 | ||
| 114 | 147 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 148 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 149 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 150 | for pattern in _parse_regex_csv(value): | |
| 118 | 151 | patterns.append(_regex_transformer(pattern)) |
| 119 | 152 | return patterns |
| 120 | 153 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Pass |
tests/config/test_config.py::test_unknown_message_id | Pass |
tests/config/test_config.py::test_unknown_option_name | Pass |
tests/config/test_config.py::test_unknown_short_option_name | Pass |
tests/config/test_config.py::test_unknown_confidence | Pass |
tests/config/test_config.py::test_empty_confidence | Pass |
tests/config/test_config.py::test_unknown_yes_no | Pass |
tests/config/test_config.py::test_unknown_py_version | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Pass |
tests/config/test_config.py::test_regex_error | Pass |
tests/config/test_config.py::test_short_verbose | Pass |
tests/config/test_config.py::test_argument_separator | Pass |
tests/config/test_config.py::test_clear_cache_post_run | Pass |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Pass |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Pass |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.