From 4a1ed7633aad84c8e3bd9e856b5d8d95136a739d Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Sep 16 2024 21:11:01 +0000 Subject: Fixing encoding of the url when checking lookaside In RHEL-7 (Python 2.7) encoding of the url was unicode. Curl's method 'setopt' expects utf-8. JIRA: RHELCMP-13939 Signed-off-by: Ondřej Nosek --- diff --git a/pyrpkg/lookaside.py b/pyrpkg/lookaside.py index 72109bf..5929fc9 100644 --- a/pyrpkg/lookaside.py +++ b/pyrpkg/lookaside.py @@ -167,7 +167,7 @@ class CGILookasideCache(object): self.log.info("Downloading %s from %s", filename, self.download_url) urled_file = urllib.parse.quote(filename) url = self.get_download_url(name, urled_file, hash, hashtype, **kwargs) - if isinstance(url, six.text_type): + if six.PY2 and isinstance(url, six.text_type): url = url.encode('utf-8') self.log.debug("Full url: %s", url) @@ -215,6 +215,8 @@ class CGILookasideCache(object): urled_file = urllib.parse.quote(filename) url = self.get_download_url(name, urled_file, hash, hashtype or self.hashtype) + if six.PY2 and isinstance(url, six.text_type): + url = url.encode('utf-8') c = pycurl.Curl() c.setopt(pycurl.URL, url) diff --git a/tests/test_lookaside.py b/tests/test_lookaside.py index 12da113..6bace2e 100644 --- a/tests/test_lookaside.py +++ b/tests/test_lookaside.py @@ -112,7 +112,10 @@ class CGILookasideCacheTestCase(unittest.TestCase): lc = CGILookasideCache('sha512', 'http://example.com', '_') lc.download(name, filename, hash, outfile, hashtype='sha512') self.assertEqual(curl.perform.call_count, 1) - self.assertEqual(curlopts[pycurl.URL].decode('utf-8'), full_url) + if six.PY2: + self.assertEqual(curlopts[pycurl.URL].decode('utf-8'), full_url) + else: + self.assertEqual(curlopts[pycurl.URL], full_url) self.assertEqual(os.path.getmtime(outfile), 0) with open(outfile) as f: @@ -167,7 +170,10 @@ class CGILookasideCacheTestCase(unittest.TestCase): lc.download(name, filename, hash, outfile, hashtype='sha512', branch=branch) self.assertEqual(curl.perform.call_count, 1) - self.assertEqual(curlopts[pycurl.URL].decode('utf-8'), full_url) + if six.PY2: + self.assertEqual(curlopts[pycurl.URL].decode('utf-8'), full_url) + else: + self.assertEqual(curlopts[pycurl.URL], full_url) @mock.patch('pyrpkg.lookaside.pycurl.Curl') def test_download_corrupted(self, mock_curl):