Skip to content

Commit f76ec22

Browse files
committed
perf: Only encode strings to utf-8 once in the event a parse error occurs in parseXMLStrings
1 parent 706461d commit f76ec22

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

plexapi/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ def parseXMLString(s: str):
726726
""" Parse an XML string and return an ElementTree object. """
727727
if not s.strip():
728728
return None
729+
encoded_s = s.encode('utf-8')
729730
try: # Attempt to parse the string as-is without cleaning (which is expensive)
730-
return ElementTree.fromstring(s.encode('utf-8'))
731+
return ElementTree.fromstring(encoded_s)
731732
except ElementTree.ParseError: # If it fails, clean the string and try again
732-
return ElementTree.fromstring(cleanXMLString(s).encode('utf-8'))
733+
return ElementTree.fromstring(cleanXMLString(encoded_s))

0 commit comments

Comments
 (0)