From c486bbdef1595be15576391abd32888ab12ba9a9 Mon Sep 17 00:00:00 2001 From: Miro HronĨok Date: Apr 30 2019 19:04:37 +0000 Subject: Try to always decode RPM data instead of working with bytes Since Fedora 31, those are unicode strings, but before they are bytes There is dummy .decode() method provided for backwards compatibility, but everything else stopped working. By always decoding first, we try to minimize the problem. In the future (when RPM is updated everywhere), the decode calls shall be removed. See https://pagure.io/FedoraReview/issue/356 See https://bugzilla.redhat.com/show_bug.cgi?id=1693751 --- diff --git a/plugins/R.py b/plugins/R.py index 6424bc0..a2bddf7 100644 --- a/plugins/R.py +++ b/plugins/R.py @@ -168,7 +168,7 @@ class RCheckLatestVersionIsPackaged(RCheckBase): "The package does not come from one of the standard sources", ) return - up_version = up_version.replace(b"-", b".").decode("utf-8") + up_version = up_version.decode("utf-8").replace("-", ".") self.set_passed( up_version == cur_version, diff --git a/plugins/ccpp.py b/plugins/ccpp.py index 9cae66c..b99448f 100644 --- a/plugins/ccpp.py +++ b/plugins/ccpp.py @@ -16,7 +16,7 @@ class Registry(RegistryBase): if self.is_user_enabled(): return self.user_enabled_value() archs = self.checks.spec.expand_tag("BuildArchs") - if len(archs) == 1 and archs[0].lower() == b"noarch": + if len(archs) == 1 and archs[0].decode("utf-8").lower() == "noarch": return False if self.checks.buildsrc.is_available: src = self.checks.buildsrc diff --git a/plugins/generic.py b/plugins/generic.py index d1e296a..ef57444 100644 --- a/plugins/generic.py +++ b/plugins/generic.py @@ -150,7 +150,7 @@ class CheckBuildCompilerFlags(GenericCheckBase): def run(self): archs = self.checks.spec.expand_tag("BuildArchs") - if len(archs) == 1 and archs[0].lower() == b"noarch": + if len(archs) == 1 and archs[0].decode("utf-8").lower() == "noarch": self.set_passed(self.NA) return self.set_passed(self.PENDING) diff --git a/plugins/generic_should.py b/plugins/generic_should.py index 9f39031..c868e99 100644 --- a/plugins/generic_should.py +++ b/plugins/generic_should.py @@ -263,7 +263,7 @@ class CheckFullVerReqSub(GenericShouldCheckBase): if len(self.spec.packages) == 1: self.set_passed(self.NA) return - if len(archs) == 1 and archs[0].lower() == b"noarch": + if len(archs) == 1 and archs[0].decode("utf-8").lower() == "noarch": isa = "" else: isa = Mock.get_macro("%_isa", self.spec, self.flags) @@ -639,7 +639,7 @@ class CheckSupportAllArchs(GenericShouldCheckBase): build_ok = self.checks.checkdict["CheckBuild"].is_passed arch = self.spec.expand_tag("BuildArch") - noarch = arch and arch[0].lower() == b"noarch" + noarch = arch and arch[0].decode("utf-8").lower() == "noarch" one_arch = self.spec.expand_tag("ExclusiveArch") if build_ok and (one_arch or noarch): self.set_passed(self.PASS) diff --git a/src/FedoraReview/rpm_file.py b/src/FedoraReview/rpm_file.py index 8a6da33..7681a1f 100644 --- a/src/FedoraReview/rpm_file.py +++ b/src/FedoraReview/rpm_file.py @@ -87,7 +87,7 @@ class RpmFile(object): def header_to_str(self, tag): """ Convert header in a string, to cope with API changes in F18""" if isinstance(self.header[tag], (dict, list)): - return b" ".join(self.header[tag]).decode("utf-8") + return " ".join(i.decode("utf-8") for i in self.header[tag]) elif self.header[tag]: return self.header[tag].decode("utf-8") else: diff --git a/src/FedoraReview/spec_file.py b/src/FedoraReview/spec_file.py index 433ff15..ab7e248 100644 --- a/src/FedoraReview/spec_file.py +++ b/src/FedoraReview/spec_file.py @@ -309,7 +309,7 @@ class SpecFile(object): return self._parse_files(pkg_name) if files is None: return None - return [l for l in [f.decode("utf-8").strip() for f in files.split(b"\n")] if l] + return [l for l in [f.strip() for f in files.decode("utf-8").split("\n")] if l] def get_section(self, section, raw=False): """