(text: str)
| 1244 | |
| 1245 | |
| 1246 | def _parse_domain_rules_yaml(text: str) -> dict[str, list[dict[str, Any]]]: |
| 1247 | rules: dict[str, list[dict[str, Any]]] = {section: [] for section in DOMAIN_SECTIONS} |
| 1248 | section = "" |
| 1249 | current: dict[str, Any] | None = None |
| 1250 | current_list_key = "" |
| 1251 | |
| 1252 | for raw_line in text.splitlines(): |
| 1253 | line = _strip_yaml_comment(raw_line).rstrip() |
| 1254 | if not line.strip(): |
| 1255 | continue |
| 1256 | indent = len(line) - len(line.lstrip(" ")) |
| 1257 | stripped = line.strip() |
| 1258 | |
| 1259 | if indent == 0: |
| 1260 | current = None |
| 1261 | current_list_key = "" |
| 1262 | key, _, value = stripped.partition(":") |
| 1263 | key = DOMAIN_SECTION_ALIASES.get(key.strip(), key.strip()) |
| 1264 | if key in DOMAIN_SECTIONS: |
| 1265 | section = key |
| 1266 | if value.strip() == "[]": |
| 1267 | rules[section] = [] |
| 1268 | else: |
| 1269 | section = "" |
| 1270 | continue |
| 1271 | |
| 1272 | if section not in rules: |
| 1273 | continue |
| 1274 | |
| 1275 | if indent <= 2 and stripped.startswith("- "): |
| 1276 | current = {} |
| 1277 | rules[section].append(current) |
| 1278 | current_list_key = "" |
| 1279 | item = stripped[2:].strip() |
| 1280 | if item: |
| 1281 | key, separator, value = item.partition(":") |
| 1282 | if not separator: |
| 1283 | raise ValueError("Domain list entries must be mappings.") |
| 1284 | current[key.strip()] = _parse_yaml_value(value) |
| 1285 | continue |
| 1286 | |
| 1287 | if current is None: |
| 1288 | raise ValueError("Domain properties must belong to a list entry.") |
| 1289 | |
| 1290 | if stripped.startswith("- "): |
| 1291 | if not current_list_key: |
| 1292 | raise ValueError("List item without a list key.") |
| 1293 | item = _parse_yaml_scalar(stripped[2:].strip()) |
| 1294 | if item: |
| 1295 | current.setdefault(current_list_key, []).append(item) |
| 1296 | continue |
| 1297 | |
| 1298 | key, separator, value = stripped.partition(":") |
| 1299 | if not separator: |
| 1300 | raise ValueError("Expected key/value domain property.") |
| 1301 | key = key.strip() |
| 1302 | value = value.strip() |
| 1303 | if key in DOMAIN_LIST_KEYS: |
no test coverage detected