| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 115 | """Transforms a comma separated list of regular expressions. | |
| 116 | ||
| 117 | Commas can be escaped with backslashes to include them in regex patterns. | |
| 118 | For example: "pattern1,pattern2\\,with\\,commas,pattern3" | |
| 119 | ||
| 120 | If the entire string is a valid regex, it will be treated as a single pattern. | |
| 121 | """ | |
| 122 | if not value: | |
| 123 | return [] | |
| 124 | ||
| 125 | # First, try to treat the entire string as a single regex pattern | |
| 126 | try: | |
| 127 | pattern = _regex_transformer(value.strip()) | |
| 128 | return [pattern] | |
| 129 | except argparse.ArgumentTypeError: | |
| 130 | # If the entire string is not a valid regex, try splitting on commas | |
| 131 | pass | |
| 132 | ||
| 116 | 133 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 134 | ||
| 135 | # Handle escaped commas by splitting on unescaped commas only | |
| 136 | parts = [] | |
| 137 | current_part = "" | |
| 138 | i = 0 | |
| 139 | while i < len(value): | |
| 140 | if value[i] == '\\' and i + 1 < len(value) and value[i + 1] == ',': | |
| 141 | # Escaped comma, add it to current part | |
| 142 | current_part += ',' | |
| 143 | i += 2 # Skip both backslash and comma | |
| 144 | elif value[i] == ',': | |
| 145 | # Unescaped comma, end current part | |
| 146 | parts.append(current_part) | |
| 147 | current_part = "" | |
| 148 | i += 1 | |
| 149 | else: | |
| 150 | # Regular character | |
| 151 | current_part += value[i] | |
| 152 | i += 1 | |
| 153 | ||
| 154 | # Add the last part | |
| 155 | parts.append(current_part) | |
| 156 | ||
| 157 | for part in parts: | |
| 158 | pattern = part.strip() | |
| 159 | if pattern: # Skip empty patterns | |
| 160 | patterns.append(_regex_transformer(pattern)) | |
| 119 | 161 | return patterns |
| 120 | 162 | |
| 121 | 163 |
| 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,bar-expected1] | 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_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.