| 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 | Supports escaping the separator with a backslash. | |
| 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('a\\,b,c') | |
| 224 | ['a,b', 'c'] | |
| 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 not string: | |
| 236 | return [] | |
| 237 | ||
| 238 | # Split on unescaped separators | |
| 239 | parts = [] | |
| 240 | current = '' | |
| 241 | i = 0 | |
| 242 | while i < len(string): | |
| 243 | if string[i] == '\\' and i + 1 < len(string): | |
| 244 | # Next character is escaped | |
| 245 | if string[i + 1] == sep: | |
| 246 | # Escaped separator, add the separator character without the backslash | |
| 247 | current += sep | |
| 248 | i += 2 | |
| 249 | else: | |
| 250 | # Escaped other character, keep both | |
| 251 | current += string[i] + string[i + 1] | |
| 252 | i += 2 | |
| 253 | elif string[i] == sep: | |
| 254 | # Unescaped separator - split here | |
| 255 | parts.append(current.strip()) | |
| 256 | current = '' | |
| 257 | i += 1 | |
| 258 | else: | |
| 259 | current += string[i] | |
| 260 | i += 1 | |
| 261 | ||
| 262 | # Add the last part | |
| 263 | parts.append(current.strip()) | |
| 264 | ||
| 265 | # Filter out empty parts | |
| 266 | return [part for part in parts if part] | |
| 233 | 267 | |
| 234 | 268 | |
| 235 | 269 | def _unquote(string: str) -> str: |
| 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.