api

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 This function handles commas in regex patterns intelligently:
118 1. First tries to parse the entire string as a single regex pattern
119 2. If that fails and the string contains commas, parses as CSV with escaped comma support
120 3. Commas can be escaped with backslashes to include them in regex patterns
121
122 Examples:
123 - "(foo{1,3})" -> single pattern with comma in regex
124 - "(foo{1,3}),bar" -> two patterns: "(foo{1,3})" and "bar"
125 - "foo\\,bar,baz" -> two patterns: "foo,bar" and "baz"
126 """
116127 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
118 patterns.append(_regex_transformer(pattern))
128
129 # Handle empty input
130 if not value.strip():
131 return patterns
132
133 # Strategy 1: Try to parse the entire string as a single regex pattern
134 # This handles cases like "(foo{1,3})" where commas are part of regex syntax
135 try:
136 pattern = _regex_transformer(value.strip())
137 return [pattern]
138 except (ValueError, re.error):
139 # If single pattern parsing fails, try CSV parsing
140 pass
141
142 # Strategy 2: Parse as CSV with escaped comma support
143 # This handles multiple patterns and escaped commas
144 parts = []
145 current_part = []
146 i = 0
147 while i < len(value):
148 if value[i] == '\\' and i + 1 < len(value) and value[i + 1] == ',':
149 # Escaped comma - add literal comma
150 current_part.append(',')
151 i += 2 # Skip both backslash and comma
152 elif value[i] == ',':
153 # Unescaped comma - end current part
154 parts.append(''.join(current_part))
155 current_part = []
156 i += 1
157 else:
158 # Regular character
159 current_part.append(value[i])
160 i += 1
161
162 # Add the last part
163 if current_part:
164 parts.append(''.join(current_part))
165
166 # Process each pattern
167 for pattern in parts:
168 pattern = pattern.strip()
169 if pattern: # Only process non-empty patterns
170 patterns.append(_regex_transformer(pattern))
171
119172 return patterns
120173
121174
Test NameStatus
tests/config/test_config.py::test_csv_regex_error
Fail
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1]
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_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.