From 7e1203ea5144e0983768941e70431fec54e2c6dd Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 15 Feb 2022 17:02:41 +0100 Subject: [PATCH] use regex rather then explicit values --- openpype/lib/transcoding.py | 45 +++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/openpype/lib/transcoding.py b/openpype/lib/transcoding.py index 5caea32ee1..cc31016bb2 100644 --- a/openpype/lib/transcoding.py +++ b/openpype/lib/transcoding.py @@ -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")