| 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 | This function handles commas within regex patterns by respecting | |
| 118 | braces {} and character classes [] that may contain commas. | |
| 119 | """ | |
| 116 | 120 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 121 | for pattern in _split_regex_csv(value): | |
| 118 | 122 | patterns.append(_regex_transformer(pattern)) |
| 119 | 123 | return patterns |
| 120 | 124 | |
| 121 | 125 | |
| 126 | def _split_regex_csv(value: str) -> Sequence[str]: | |
| 127 | """Split a CSV string while respecting commas within regex patterns. | |
| 128 | ||
| 129 | This function splits on commas that are not inside: | |
| 130 | - Braces {} (for quantifiers like {1,3}) | |
| 131 | - Character classes [] (for character sets like [a,b,c]) | |
| 132 | ||
| 133 | It does NOT handle parentheses - commas inside parentheses should | |
| 134 | still be treated as separators. | |
| 135 | ||
| 136 | Args: | |
| 137 | value: The CSV string to split | |
| 138 | ||
| 139 | Returns: | |
| 140 | List of split and stripped strings | |
| 141 | """ | |
| 142 | if not value: | |
| 143 | return [] | |
| 144 | ||
| 145 | result: list[str] = [] | |
| 146 | current = [] | |
| 147 | brace_depth = 0 | |
| 148 | in_char_class = False | |
| 149 | i = 0 | |
| 150 | ||
| 151 | while i < len(value): | |
| 152 | char = value[i] | |
| 153 | ||
| 154 | # Handle character classes | |
| 155 | if char == '[' and not in_char_class: | |
| 156 | in_char_class = True | |
| 157 | current.append(char) | |
| 158 | elif char == ']' and in_char_class: | |
| 159 | in_char_class = False | |
| 160 | current.append(char) | |
| 161 | # Handle braces for quantifiers | |
| 162 | elif char == '{' and not in_char_class: | |
| 163 | brace_depth += 1 | |
| 164 | current.append(char) | |
| 165 | elif char == '}' and not in_char_class and brace_depth > 0: | |
| 166 | brace_depth -= 1 | |
| 167 | current.append(char) | |
| 168 | # Handle comma separator | |
| 169 | elif char == ',' and brace_depth == 0 and not in_char_class: | |
| 170 | # End of current pattern | |
| 171 | pattern = ''.join(current).strip() | |
| 172 | if pattern: # Only add non-empty patterns | |
| 173 | result.append(pattern) | |
| 174 | current = [] | |
| 175 | else: | |
| 176 | current.append(char) | |
| 177 | ||
| 178 | i += 1 | |
| 179 | ||
| 180 | # Add the last pattern | |
| 181 | pattern = ''.join(current).strip() | |
| 182 | if pattern: # Only add non-empty patterns | |
| 183 | result.append(pattern) | |
| 184 | ||
| 185 | return result | |
| 186 | ||
| 187 | ||
| 122 | 188 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 189 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | 190 | patterns: list[Pattern[str]] = [] |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Pass |
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_csv_regex_comma_in_quantifier[foo, | 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.