| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 116 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 117 | ||
| 118 | # Handle the case where the input is already a list/tuple | |
| 119 | if isinstance(value, (list, tuple)): | |
| 120 | for pattern in value: | |
| 121 | patterns.append(_regex_transformer(pattern)) | |
| 122 | return patterns | |
| 123 | ||
| 124 | # For string input, we need to parse comma-separated regex patterns | |
| 125 | # while respecting commas that are part of regex syntax | |
| 126 | if not value.strip(): | |
| 127 | return patterns | |
| 128 | ||
| 129 | # Parse the string manually to handle commas within regex patterns | |
| 130 | current_pattern = "" | |
| 131 | brace_depth = 0 | |
| 132 | bracket_depth = 0 | |
| 133 | paren_depth = 0 | |
| 134 | in_char_class = False | |
| 135 | i = 0 | |
| 136 | ||
| 137 | while i < len(value): | |
| 138 | char = value[i] | |
| 139 | ||
| 140 | # Track nesting levels to determine if a comma is inside a regex construct | |
| 141 | if char == '[' and not in_char_class: | |
| 142 | in_char_class = True | |
| 143 | bracket_depth += 1 | |
| 144 | elif char == ']' and in_char_class: | |
| 145 | in_char_class = False | |
| 146 | bracket_depth -= 1 | |
| 147 | elif char == '{' and not in_char_class: | |
| 148 | brace_depth += 1 | |
| 149 | elif char == '}' and not in_char_class: | |
| 150 | brace_depth -= 1 | |
| 151 | elif char == '(' and not in_char_class: | |
| 152 | paren_depth += 1 | |
| 153 | elif char == ')' and not in_char_class: | |
| 154 | paren_depth -= 1 | |
| 155 | elif char == ',' and not in_char_class and brace_depth == 0 and bracket_depth == 0 and paren_depth == 0: | |
| 156 | # This comma separates patterns | |
| 157 | pattern = current_pattern.strip() | |
| 158 | if pattern: | |
| 159 | patterns.append(_regex_transformer(pattern)) | |
| 160 | current_pattern = "" | |
| 161 | i += 1 | |
| 162 | continue | |
| 163 | ||
| 164 | current_pattern += char | |
| 165 | i += 1 | |
| 166 | ||
| 167 | # Add the last pattern | |
| 168 | pattern = current_pattern.strip() | |
| 169 | if pattern: | |
| 170 | patterns.append(_regex_transformer(pattern)) | |
| 171 | ||
| 172 | return patterns | |
| 173 | i = 0 | |
| 174 | ||
| 175 | while i < len(value): | |
| 176 | char = value[i] | |
| 177 | ||
| 178 | # Track nesting levels to determine if a comma is inside a regex construct | |
| 179 | if char == '[' and not in_char_class: | |
| 180 | in_char_class = True | |
| 181 | bracket_depth += 1 | |
| 182 | elif char == ']' and in_char_class: | |
| 183 | in_char_class = False | |
| 184 | bracket_depth -= 1 | |
| 185 | elif char == '{' and not in_char_class: | |
| 186 | brace_depth += 1 | |
| 187 | elif char == '}' and not in_char_class: | |
| 188 | brace_depth -= 1 | |
| 189 | elif char == '(' and not in_char_class: | |
| 190 | paren_depth += 1 | |
| 191 | elif char == ')' and not in_char_class: | |
| 192 | paren_depth -= 1 | |
| 193 | elif char == ',' and not in_char_class and brace_depth == 0 and bracket_depth == 0 and paren_depth == 0: | |
| 194 | # This comma separates patterns | |
| 195 | pattern = current_pattern.strip() | |
| 196 | if pattern: | |
| 197 | patterns.append(_regex_transformer(pattern)) | |
| 198 | current_pattern = "" | |
| 199 | i += 1 | |
| 200 | continue | |
| 201 | ||
| 202 | current_pattern += char | |
| 203 | i += 1 | |
| 204 | ||
| 205 | # Add the last pattern | |
| 206 | pattern = current_pattern.strip() | |
| 207 | if pattern: | |
| 118 | 208 | patterns.append(_regex_transformer(pattern)) |
| 209 | ||
| 119 | 210 | return patterns |
| 120 | 211 | |
| 121 | 212 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | 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_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.