Blob Blame History Raw
From 7f3f4b607948f1babb154b7946813fa6f8edb8fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert-Andr=C3=A9=20Mauchin?= <zebob.m@gmail.com>
Date: Mon, 22 Apr 2019 16:13:24 +0200
Subject: [PATCH] Handle data from python RPM binding as UTF-8 string
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The RPM python3 bindings return ALL string data as surrogate-escaped
utf-8 string objects.
See: https://bugzilla.redhat.com/show_bug.cgi?id=1693751

Signed-off-by: Robert-André Mauchin <zebob.m@gmail.com>
---
 pyrpkg/__init__.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 8fe4ed0..23b1ed7 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -1248,8 +1248,11 @@ class Commands(object):
         archlist = [pkg.header['arch'] for pkg in hdr.packages]
         if not archlist:
             raise rpkgError('No compatible build arches found in %s' % spec)
-        if hasattr(archlist[0], 'decode'):
-            return [arch.decode('utf-8') for arch in archlist]
+        if six.PY3:
+            return [str(arch, encoding='utf-8')
+                    if not isinstance(arch, six.string_types)
+                    else arch
+                    for arch in archlist]
         else:
             return archlist
 
@@ -1339,10 +1342,10 @@ class Commands(object):
             hdr = koji.get_rpm_header(srpm)
             name = hdr[rpm.RPMTAG_NAME]
             contents = hdr[rpm.RPMTAG_FILENAMES]
-            if hasattr(name, 'decode'):
+            if six.PY3 and not isinstance(name, six.string_types):
                 # RPM before rhbz#1693751 returned bytes
-                name = name.decode('utf-8')
-                contents = [filename.decode('utf-8')
+                name = str(name, encoding='utf-8')
+                contents = [str(filename, encoding='utf-8')
                             for filename in contents]
         except Exception as e:
             raise rpkgError('Error querying srpm: {0}'.format(str(e)))
-- 
2.20.1