From fdc40f7be78e120f6b880d352cc916f39d36477f Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Dec 19 2019 13:48:20 +0000 Subject: RPM 4.15 changed header returns from type 'bytes' to 'string'. Handle either by converting to 'string' if necessary. Signed-off-by: Merlin Mathesius --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index a26e1be..6ae3d37 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1683,6 +1683,20 @@ class cliClient(object): contain RPM data. :rtype: str """ + + def _string(s): + """RPM 4.15 changed header returns from type 'bytes' to 'string'. + Handle either by always returning 'string'. + + :param s: a 'bytes' or 'string' value representing an RPM + package header. + :return: always a 'string' representation of the RPM header. + :rtype: str + """ + if isinstance(s, bytes): + return s.decode('utf-8') + return s + ts = rpm.TransactionSet() ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) fdno = os.open(rpm_file, os.O_RDONLY) @@ -1691,7 +1705,7 @@ class cliClient(object): except rpm.error: return None os.close(fdno) - return hdr[rpm.RPMTAG_NAME].decode('utf-8') + return _string(hdr[rpm.RPMTAG_NAME]) def _handle_srpm_option(self): """Generate SRPM according to --srpm option value and upload it