python-modernize -f libmodernize.fixes.fix_unicode_type
This commit is contained in:
parent
0eaf3349c4
commit
c579e36489
4 changed files with 17 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -2912,7 +2913,7 @@ def fixEncoding(value, fallback='iso8859-15', remove_nonprintable=False):
|
|||
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
|
||||
s = value.encode('utf8')
|
||||
|
|
@ -2946,7 +2947,7 @@ def fixEncodingRecurse(value, fallback='iso8859-15', remove_nonprintable=False):
|
|||
k = fixEncodingRecurse(k, fallback=fallback, remove_nonprintable=remove_nonprintable)
|
||||
ret[k] = v
|
||||
return ret
|
||||
elif isinstance(value, unicode):
|
||||
elif isinstance(value, six.text_type):
|
||||
if remove_nonprintable:
|
||||
return removeNonprintable(value.encode('utf8'))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue