]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port utils.safe_minidom_parse_string() to Python 3
authorVictor Stinner <vstinner@redhat.com>
Tue, 9 Feb 2016 16:54:02 +0000 (17:54 +0100)
committerVictor Stinner <vstinner@redhat.com>
Tue, 9 Feb 2016 17:45:13 +0000 (18:45 +0100)
Partial-Implements: blueprint cinder-python3
Change-Id: I3ef021d808f5d3963db286d755f7a38cd00ea1fe

cinder/utils.py

index 8a7237792fce53f45d1e5e8c879bea604fbea016..9135035ef247ba54d1a535a6e8b328b581ccb6be 100644 (file)
@@ -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()