1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-05-11 03:23:46 +00:00
oot/tools/assets/descriptor/xml_errors.py
2025-02-18 10:07:20 +01:00

31 lines
811 B
Python

# SPDX-FileCopyrightText: © 2025 ZeldaRET
# SPDX-License-Identifier: CC0-1.0
from xml.etree import ElementTree
class XMLDescError(Exception):
pass
def check_attrib(
elem: ElementTree.Element,
required: set[str],
optional: set[str] = set(),
):
required_and_missing = required - elem.attrib.keys()
if required_and_missing:
raise XMLDescError(
"Missing attributes on "
+ ElementTree.tostring(elem, encoding="unicode")
+ ": "
+ ", ".join(required_and_missing)
)
unknown = elem.attrib.keys() - required - optional
if unknown:
raise XMLDescError(
"Unknown attributes on "
+ ElementTree.tostring(elem, encoding="unicode")
+ ": "
+ ", ".join(unknown)
)