| 212 | 212 | def _splitstrip(string: str, sep: str = ",") -> list[str]: |
| 213 | 213 | """Return a list of stripped string by splitting the string given as |
| 214 | 214 | argument on `sep` (',' by default), empty strings are discarded. |
| 215 | For regex patterns, intelligently handles commas within regex constructs. | |
| 215 | 216 | |
| 216 | 217 | >>> _splitstrip('a, b, c , 4,,') |
| 217 | 218 | ['a', 'b', 'c', '4'] |
| 219 | 220 | ['a'] |
| 220 | 221 | >>> _splitstrip('a,\nb,\nc,') |
| 221 | 222 | ['a', 'b', 'c'] |
| 223 | >>> _splitstrip('(foo{1,3}), (bar{2,5})') | |
| 224 | ['(foo{1,3})', '(bar{2,5})'] | |
| 222 | 225 | |
| 223 | 226 | :type string: str or unicode |
| 224 | 227 | :param string: a csv line |
| 229 | 232 | :rtype: str or unicode |
| 230 | 233 | :return: the unquoted string (or the input string if it wasn't quoted) |
| 231 | 234 | """ |
| 232 | return [word.strip() for word in string.split(sep) if word.strip()] | |
| 235 | if sep != ",": | |
| 236 | # For non-comma separators, use the original simple splitting | |
| 237 | return [word.strip() for word in string.split(sep) if word.strip()] | |
| 238 | ||
| 239 | # For comma separators, handle regex patterns intelligently | |
| 240 | result = [] | |
| 241 | current_item = "" | |
| 242 | brace_depth = 0 | |
| 243 | bracket_depth = 0 | |
| 244 | paren_depth = 0 | |
| 245 | i = 0 | |
| 246 | ||
| 247 | while i < len(string): | |
| 248 | char = string[i] | |
| 249 | ||
| 250 | # Track nesting levels for regex constructs | |
| 251 | if char == '{' and brace_depth >= 0: | |
| 252 | brace_depth += 1 | |
| 253 | elif char == '}' and brace_depth > 0: | |
| 254 | brace_depth -= 1 | |
| 255 | elif char == '[' and bracket_depth >= 0: | |
| 256 | bracket_depth += 1 | |
| 257 | elif char == ']' and bracket_depth > 0: | |
| 258 | bracket_depth -= 1 | |
| 259 | elif char == '(' and paren_depth >= 0: | |
| 260 | paren_depth += 1 | |
| 261 | elif char == ')' and paren_depth > 0: | |
| 262 | paren_depth -= 1 | |
| 263 | ||
| 264 | # Split on comma only if we're not inside any regex construct | |
| 265 | if char == ',' and brace_depth == 0 and bracket_depth == 0 and paren_depth == 0: | |
| 266 | # End of current item | |
| 267 | stripped_item = current_item.strip() | |
| 268 | if stripped_item: | |
| 269 | result.append(stripped_item) | |
| 270 | current_item = "" | |
| 271 | else: | |
| 272 | current_item += char | |
| 273 | ||
| 274 | i += 1 | |
| 275 | ||
| 276 | # Add the last item | |
| 277 | stripped_item = current_item.strip() | |
| 278 | if stripped_item: | |
| 279 | result.append(stripped_item) | |
| 280 | ||
| 281 | return result | |
| 233 | 282 | |
| 234 | 283 | |
| 235 | 284 | def _unquote(string: str) -> str: |
| 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.