From e0951d90c064d26aa92ea9cc355fdc43b289a7d0 Mon Sep 17 00:00:00 2001 From: Pavel Šimerda Date: Nov 10 2016 11:25:39 +0000 Subject: python3: fix string types Fix text/binary string issues in pyrpkg. Could not execute verrel: endswith first arg must be bytes or a tuple of bytes, not str Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 526, in module_name self.load_module_name() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 545, in load_module_name if module_name.endswith('.git'): TypeError: endswith first arg must be bytes or a tuple of bytes, not str Could not execute verrel: 'str' does not support the buffer interface Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 808, in ver self.load_nameverrel() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 624, in load_nameverrel cmd.extend(self.rpmdefines) File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 687, in rpmdefines self.load_rpmdefines() File "/usr/lib64/python3.4/site-packages/fedpkg/__init__.py", line 167, in load_rpmdefines self.mockconfig = 'fedora-rawhide-%s' % self.localarch File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 493, in localarch self.load_localarch() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 501, in load_localarch self._localarch = proc.communicate()[0].strip('\n') TypeError: 'str' does not support the buffer interface Could not execute verrel: endswith first arg must be str or a tuple of str, not bytes Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 526, in module_name self.load_module_name() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 545, in load_module_name if module_name.endswith(b'.git'): TypeError: endswith first arg must be str or a tuple of str, not bytes Related: https://pagure.io/rpkg/issue/45 Signed-off-by: Pavel Šimerda --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index fc4ca22..57fb0a7 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -407,9 +407,9 @@ class Commands(object): raise rpkgError('Unable to find remote push url: %s' % e) if isinstance(url, six.text_type): # GitPython >= 1.0 return unicode. It must be encoded to string. - self._push_url = url.encode('utf-8') - else: self._push_url = url + else: + self._push_url = url.decode('utf-8') @property def commithash(self): @@ -490,7 +490,8 @@ class Commands(object): """Get the local arch as defined by rpm""" proc = subprocess.Popen(['rpm --eval %{_arch}'], shell=True, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + universal_newlines=True) self._localarch = proc.communicate()[0].strip('\n') @property @@ -534,8 +535,8 @@ class Commands(object): # self._module_name = "/".join(parts.path.split("/")[-2:]) module_name = posixpath.basename(parts.path) - if module_name.endswith(b'.git'): - module_name = module_name[:-len(b'.git')] + if module_name.endswith('.git'): + module_name = module_name[:-len('.git')] self._module_name = module_name return except rpkgError: diff --git a/tests/commands/test_package_name.py b/tests/commands/test_package_name.py index 23cdb69..69cf45a 100644 --- a/tests/commands/test_package_name.py +++ b/tests/commands/test_package_name.py @@ -20,7 +20,5 @@ class CommandPackageNameTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir - # pycurl can't handle unicode variable - # module_name needs to be a byte string - self.assertNotEqual(type(cmd.module_name), six.text_type) - self.assertEqual(type(cmd.module_name), six.binary_type) + self.assertNotEqual(type(cmd.module_name), six.binary_type) + self.assertEqual(type(cmd.module_name), six.text_type)