From b26d522d38c11fa0ef2aaf79a680958b76a5dd93 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 12 2017 09:34:17 +0000 Subject: python-modernize -f libmodernize.fixes.fix_unicode_type --- diff --git a/hub/kojihub.py b/hub/kojihub.py index aa3d2be..63c28ed 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -59,6 +59,7 @@ import zipfile from koji.context import context from six.moves import range from six.moves import zip +import six try: import json @@ -2795,7 +2796,7 @@ def lookup_name(table, info, strict=False, create=False): q = """SELECT id,name FROM %s WHERE id=%%(info)d""" % table elif isinstance(info, str): q = """SELECT id,name FROM %s WHERE name=%%(info)s""" % table - elif isinstance(info, unicode): + elif isinstance(info, six.text_type): info = koji.fixEncoding(info) q = """SELECT id,name FROM %s WHERE name=%%(info)s""" % table else: @@ -5132,7 +5133,7 @@ class CG_Importer(object): if metadata is None: #default to looking for uploaded file metadata = 'metadata.json' - if not isinstance(metadata, (str, unicode)): + if not isinstance(metadata, (str, six.text_type)): raise koji.GenericError("Invalid metadata value: %r" % metadata) if metadata.endswith('.json'): # handle uploaded metadata @@ -9341,7 +9342,7 @@ class RootExports(object): if before: if isinstance(before, datetime.datetime): before = calendar.timegm(before.utctimetuple()) - elif isinstance(before, (str, unicode)): + elif isinstance(before, (str, six.text_type)): before = koji.util.parseTime(before) elif isinstance(before, (int, long)): pass @@ -9351,7 +9352,7 @@ class RootExports(object): if after: if isinstance(after, datetime.datetime): after = calendar.timegm(after.utctimetuple()) - elif isinstance(after, (str, unicode)): + elif isinstance(after, (str, six.text_type)): after = koji.util.parseTime(after) elif isinstance(after, (int, long)): pass diff --git a/koji/__init__.py b/koji/__init__.py index 267469b..49664b3 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -25,6 +25,7 @@ from __future__ import absolute_import import sys from six.moves import range from six.moves import zip +import six try: import krbV except ImportError: # pragma: no cover @@ -550,7 +551,7 @@ def rpm_hdr_size(f, ofs=None): f = filename or file object ofs = offset of the header """ - if isinstance(f, (str, unicode)): + if isinstance(f, (str, six.text_type)): fo = file(f, 'rb') else: fo = f @@ -580,7 +581,7 @@ def rpm_hdr_size(f, ofs=None): # add eight bytes for section header hdrsize = hdrsize + 8 - if not isinstance(f, (str, unicode)): + if not isinstance(f, (str, six.text_type)): fo.close() return hdrsize @@ -870,7 +871,7 @@ def get_rpm_header(f, ts=None): if ts is None: ts = rpm.TransactionSet() ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS) - if isinstance(f, (str, unicode)): + if isinstance(f, (str, six.text_type)): fo = file(f, "r") else: fo = f @@ -2906,7 +2907,7 @@ def fixEncoding(value, fallback='iso8859-15'): if not value: return '' - if isinstance(value, unicode): + if isinstance(value, six.text_type): # value is already unicode, so just convert it # to a utf8-encoded str return value.encode('utf8') @@ -2936,7 +2937,7 @@ def fixEncodingRecurse(value, fallback='iso8859-15'): k = fixEncodingRecurse(k) ret[k] = v return ret - elif isinstance(value, unicode): + elif isinstance(value, six.text_type): return value.encode('utf8') elif isinstance(value, str): # value is a str, but may be encoded in utf8 or some diff --git a/tests/test_tasks.py b/tests/test_tasks.py index cc69e36..fa28edd 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import random from io import StringIO from os import path, makedirs @@ -10,12 +11,13 @@ import koji from koji.tasks import BaseTaskHandler, FakeTask, ForkTask, SleepTask, \ WaitTestTask, scan_mounts, umount_all, \ safe_rmtree +import six def get_fake_mounts_file(): """ Returns contents of /prc/mounts in a file-like object """ - return StringIO(unicode(( + return StringIO(six.text_type(( 'sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0\n' 'proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0\n' 'devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=238836k,nr_inodes=59709,mode=755 0 0\n' @@ -460,7 +462,7 @@ class TasksTestCase(TestCase): obj = TestTask(123, 'some_method', ['random_arg'], None, options, temp_path) self.assertEquals(obj.localPath('test.txt'), dummy_file) - @patch('urllib2.urlopen', return_value=StringIO(unicode('Important things\nSome more important things\n'))) + @patch('urllib2.urlopen', return_value=StringIO(six.text_type('Important things\nSome more important things\n'))) def test_BaseTaskHandler_localPath_no_file(self, mock_urlopen): """ """ diff --git a/www/lib/kojiweb/util.py b/www/lib/kojiweb/util.py index 4201297..3d5212f 100644 --- a/www/lib/kojiweb/util.py +++ b/www/lib/kojiweb/util.py @@ -34,6 +34,7 @@ from xmlrpclib import ProtocolError from xml.parsers.expat import ExpatError import cgi from six.moves import range +import six class NoSuchException(Exception): pass @@ -96,7 +97,7 @@ class DecodeUTF8(Cheetah.Filters.Filter): def filter(self, *args, **kw): """Convert all strs to unicode objects""" result = super(DecodeUTF8, self).filter(*args, **kw) - if isinstance(result, unicode): + if isinstance(result, six.text_type): pass else: result = result.decode('utf-8', 'replace')