chiark / gitweb /
Work around encoding issues when using xml files
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 3 Jun 2015 16:42:24 +0000 (18:42 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 3 Jun 2015 16:42:24 +0000 (18:42 +0200)
The xml package returns "unicode" objects instead of strings in utf-8.

fdroidserver/common.py

index 7a2c6938f569b6a3221d066fff4b53cc4378242e..bad39a00af3d20ced17804db92baab3c55dae605 100644 (file)
@@ -882,7 +882,7 @@ def retrieve_string(app_dir, string, xmlfiles=None):
         xml = parse_xml(path)
         element = xml.find('string[@name="' + name + '"]')
         if element is not None:
-            return retrieve_string(app_dir, element.text, xmlfiles)
+            return retrieve_string(app_dir, element.text.encode('utf-8'), xmlfiles)
 
     return ''
 
@@ -915,7 +915,7 @@ def fetch_real_name(app_dir, flavours):
         app = xml.find('application')
         if "{http://schemas.android.com/apk/res/android}label" not in app.attrib:
             continue
-        label = app.attrib["{http://schemas.android.com/apk/res/android}label"]
+        label = app.attrib["{http://schemas.android.com/apk/res/android}label"].encode('utf-8')
         result = retrieve_string(app_dir, label)
         if result:
             result = result.strip()
@@ -1020,11 +1020,11 @@ def parse_androidmanifests(paths, ignoreversions=None):
         else:
             xml = parse_xml(path)
             if "package" in xml.attrib:
-                package = xml.attrib["package"]
+                package = xml.attrib["package"].encode('utf-8')
             if "{http://schemas.android.com/apk/res/android}versionName" in xml.attrib:
-                version = xml.attrib["{http://schemas.android.com/apk/res/android}versionName"]
+                version = xml.attrib["{http://schemas.android.com/apk/res/android}versionName"].encode('utf-8')
             if "{http://schemas.android.com/apk/res/android}versionCode" in xml.attrib:
-                vercode = xml.attrib["{http://schemas.android.com/apk/res/android}versionCode"]
+                vercode = xml.attrib["{http://schemas.android.com/apk/res/android}versionCode"].encode('utf-8')
 
         logging.debug("..got package={0}, version={1}, vercode={2}"
                       .format(package, version, vercode))