From 3d9523be1ae64a84ce849fa199b3c1e01b3d805b Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Apr 19 2019 18:08:01 +0000 Subject: srpm_import: be compatible with rhbz#1693751 Older RPMs returned 'bytes' objects, newer return 'str'. If 'str' object is returned on Python 3 - it doesn't need to be decoded, and it actually raises error [1]: >>> str('', encoding='utf-8') Traceback (most recent call last): File "", line 1, in TypeError: decoding str is not supported This change also OK for Python 2 where str() has decode method (str is alternative for bytes). [1] https://pagure.io/copr/copr/issue/677 Signed-off-by: Pavel Raiskup --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index f1ecc6f..8fe4ed0 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1248,8 +1248,8 @@ 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 six.PY3: - return [str(arch, encoding='utf-8') for arch in archlist] + if hasattr(archlist[0], 'decode'): + return [arch.decode('utf-8') for arch in archlist] else: return archlist @@ -1339,9 +1339,10 @@ class Commands(object): hdr = koji.get_rpm_header(srpm) name = hdr[rpm.RPMTAG_NAME] contents = hdr[rpm.RPMTAG_FILENAMES] - if six.PY3: - name = str(name, encoding='utf-8') - contents = [str(filename, encoding='utf-8') + if hasattr(name, 'decode'): + # RPM before rhbz#1693751 returned bytes + name = name.decode('utf-8') + contents = [filename.decode('utf-8') for filename in contents] except Exception as e: raise rpkgError('Error querying srpm: {0}'.format(str(e)))