sn62

Finished
112112
113113
114114def _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 Supports quoted regex patterns to handle commas within regex syntax.
118 For example: "(foo{1,3})" will be treated as a single pattern,
119 while "pattern1,pattern2" will be split into two patterns.
120 """
116121 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
122 for pattern in _smart_csv_split(value):
118123 patterns.append(_regex_transformer(pattern))
119124 return patterns
120125
121126
127def _smart_csv_split(value: str) -> Sequence[str]:
128 """Split a CSV string while respecting quoted values.
129
130 This function handles comma-separated values where individual values
131 may be quoted to preserve commas within the value. For example:
132 - "pattern1,pattern2" -> ["pattern1", "pattern2"]
133 - "\"(foo{1,3})\",pattern2" -> ["(foo{1,3})", "pattern2"]
134 - "\"(foo{1,3})\"" -> ["(foo{1,3})"]
135
136 :param value: The CSV string to split
137 :return: List of split and unquoted values
138 """
139 if isinstance(value, (list, tuple)):
140 return value
141
142 result = []
143 current = []
144 in_quotes = False
145 quote_char = None
146 i = 0
147
148 while i < len(value):
149 char = value[i]
150
151 if char in "\"'" and not in_quotes:
152 # Start of quoted section
153 in_quotes = True
154 quote_char = char
155 elif char == quote_char and in_quotes:
156 # End of quoted section
157 in_quotes = False
158 quote_char = None
159 elif char == ',' and not in_quotes:
160 # Comma separator outside quotes
161 result.append(''.join(current).strip())
162 current = []
163 i += 1
164 continue
165
166 current.append(char)
167 i += 1
168
169 # Add the last part
170 if current:
171 result.append(''.join(current).strip())
172
173 # Filter out empty strings and unquote quoted values
174 filtered_result = []
175 for item in result:
176 if item: # Skip empty strings
177 # Unquote if the item is quoted
178 if (item.startswith('"') and item.endswith('"')) or \
179 (item.startswith("'") and item.endswith("'")):
180 item = item[1:-1]
181 filtered_result.append(item)
182
183 return filtered_result
184
185
122186def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
123187 """Transforms a comma separated list of regular expressions paths."""
124188 patterns: list[Pattern[str]] = []
Test NameStatus
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.