From 8311e7360f039d3ffbcd013180881e4cf0dedb4d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 9 Feb 2016 17:54:02 +0100 Subject: [PATCH] Port utils.safe_minidom_parse_string() to Python 3 Partial-Implements: blueprint cinder-python3 Change-Id: I3ef021d808f5d3963db286d755f7a38cd00ea1fe --- cinder/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cinder/utils.py b/cinder/utils.py index 8a7237792..9135035ef 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -334,6 +334,12 @@ def safe_minidom_parse_string(xml_string): """ try: + if six.PY3 and isinstance(xml_string, bytes): + # On Python 3, minidom.parseString() requires Unicode when + # the parser parameter is used. + # + # Bet that XML used in Cinder is always encoded to UTF-8. + xml_string = xml_string.decode('utf-8') return minidom.parseString(xml_string, parser=ProtectedExpatParser()) except sax.SAXParseException: raise expat.ExpatError() -- 2.45.2