use regex rather then explicit values

This commit is contained in:
Jakub Trllo 2022-02-15 17:02:41 +01:00
parent fcb38b81cf
commit 7e1203ea51

View file

@ -31,37 +31,9 @@ INT_TAGS = {
"subimages",
}
XML_UNUSED_CHARS = {
"�",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
}
CHAR_REF_REGEX_DECIMAL = re.compile(r"&#[0-9]+;")
CHAR_REF_REGEX_HEX = re.compile(r"&#x[0-9a-zA-Z]+;")
# Regex to parse array attributes
ARRAY_TYPE_REGEX = re.compile(r"^(int|float|string)\[\d+\]$")
@ -226,10 +198,13 @@ def parse_oiio_xml_output(xml_string, logger=None):
# Fix values with ampresand (lazy fix)
# - ElementTree can't handle all escaped values with ampresand
# e.g. ""
for unused_char in XML_UNUSED_CHARS:
if unused_char in xml_string:
new_char = unused_char.replace("&", "&")
xml_string = xml_string.replace(unused_char, new_char)
matches = (
set(CHAR_REF_REGEX_HEX.findall(xml_string))
| set(CHAR_REF_REGEX_DECIMAL.findall(xml_string))
)
for match in matches:
new_value = match.replace("&", "&")
xml_string = xml_string.replace(match, new_value)
if logger is None:
logger = logging.getLogger("OIIO-xml-parse")