Bug 1547730 - Finish up some final py3-izing in getting mozjar.py to work in py3 r=#build

Differential Revision: https://phabricator.services.mozilla.com/D28120

--HG--
extra : rebase_source : d0561578250ee77b4d14907cdaf83e69c60b42ff
extra : intermediate-source : 3dce2de9ddc1c36a4564337ecdfc5f4d5ed751c5
extra : source : 6dac07ac6e344d3f034cefeedead4642c2d69949
This commit is contained in:
Justin Wood 2019-04-18 15:21:31 -04:00
Родитель a287dbef6e
Коммит 6af7d5e25b
4 изменённых файлов: 50 добавлений и 50 удалений

Просмотреть файл

@ -296,7 +296,7 @@ class FileCopier(FileRegistry):
Returns a FileCopyResult that details what changed.
'''
assert isinstance(destination, basestring)
assert isinstance(destination, six.string_types)
assert not os.path.exists(destination) or os.path.isdir(destination)
result = FileCopyResult()
@ -565,7 +565,7 @@ class Jarrer(FileRegistry, BaseFile):
def exists(self):
return self.deflater is not None
if isinstance(dest, basestring):
if isinstance(dest, six.string_types):
dest = Dest(dest)
assert isinstance(dest, Dest)

Просмотреть файл

@ -177,7 +177,7 @@ class BaseFile(object):
disabled when skip_if_older is False.
Returns whether a copy was actually performed (True) or not (False).
'''
if isinstance(dest, basestring):
if isinstance(dest, six.string_types):
dest = Dest(dest)
else:
assert isinstance(dest, Dest)
@ -297,11 +297,11 @@ class ExecutableFile(File):
def copy(self, dest, skip_if_older=True):
real_dest = dest
if not isinstance(dest, basestring):
if not isinstance(dest, six.string_types):
fd, dest = mkstemp()
os.close(fd)
os.remove(dest)
assert isinstance(dest, basestring)
assert isinstance(dest, six.string_types)
# If File.copy didn't actually copy because dest is newer, check the
# file sizes. If dest is smaller, it means it is already stripped and
# elfhacked and xz_compressed, so we can skip.
@ -340,7 +340,7 @@ class AbsoluteSymlinkFile(File):
File.__init__(self, path)
def copy(self, dest, skip_if_older=True):
assert isinstance(dest, basestring)
assert isinstance(dest, six.string_types)
# The logic in this function is complicated by the fact that symlinks
# aren't universally supported. So, where symlinks aren't supported, we
@ -431,7 +431,7 @@ class HardlinkFile(File):
'''
def copy(self, dest, skip_if_older=True):
assert isinstance(dest, basestring)
assert isinstance(dest, six.string_types)
if not hasattr(os, 'link'):
return super(HardlinkFile, self).copy(
@ -493,7 +493,7 @@ class ExistingFile(BaseFile):
self.required = required
def copy(self, dest, skip_if_older=True):
if isinstance(dest, basestring):
if isinstance(dest, six.string_types):
dest = Dest(dest)
else:
assert isinstance(dest, Dest)
@ -540,7 +540,7 @@ class PreprocessedFile(BaseFile):
'''
Invokes the preprocessor to create the destination file.
'''
if isinstance(dest, basestring):
if isinstance(dest, six.string_types):
dest = Dest(dest)
else:
assert isinstance(dest, Dest)

Просмотреть файл

@ -67,7 +67,7 @@ class JarStruct(object):
(deserialized), or with empty fields.
'''
TYPE_MAPPING = {'uint32': ('I', 4), 'uint16': ('H', 2)}
TYPE_MAPPING = {'uint32': (b'I', 4), 'uint16': (b'H', 2)}
def __init__(self, data=None):
'''
@ -627,7 +627,7 @@ class JarWriter(object):
deflater = data
else:
deflater = Deflater(compress, compress_level=self._compress_level)
if isinstance(data, basestring):
if isinstance(data, (six.binary_type, six.string_types)):
deflater.write(data)
elif hasattr(data, 'read'):
if hasattr(data, 'seek'):

Просмотреть файл

@ -75,8 +75,8 @@ class TestJarStruct(unittest.TestCase):
self.assertEqual(foo['qux'], 0x01ef)
self.assertFalse('length' in foo)
self.assertFalse('length2' in foo)
self.assertEqual(foo['string'], '012345')
self.assertEqual(foo['string2'], '67')
self.assertEqual(foo['string'], b'012345')
self.assertEqual(foo['string2'], b'67')
def test_read_jar_struct(self):
data = b'\x00\x04\x03\x02\x01\x42\x43\x44\x45\xab\xcd\xef' + \
@ -130,7 +130,7 @@ class TestDeflater(unittest.TestCase):
self.assertFalse(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 0)
self.assertEqual(deflater.compressed_size, deflater.uncompressed_size)
self.assertEqual(deflater.compressed_data, '')
self.assertEqual(deflater.compressed_data, b'')
self.assertEqual(deflater.crc32, 0)
@ -151,23 +151,23 @@ class TestJar(unittest.TestCase):
files = [j for j in JarReader(fileobj=s)]
self.assertEqual(files[0].filename, 'foo')
self.assertEqual(files[0].filename, b'foo')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), b'foo')
self.assertEqual(files[1].filename, 'bar')
self.assertEqual(files[1].filename, b'bar')
self.assertTrue(files[1].compressed)
self.assertEqual(files[1].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertEqual(files[2].filename, b'baz/qux')
self.assertFalse(files[2].compressed)
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
if os.sep == '\\':
self.assertEqual(files[3].filename, 'baz/backslash',
self.assertEqual(files[3].filename, b'baz/backslash',
'backslashes in filenames on Windows should get normalized')
else:
self.assertEqual(files[3].filename, 'baz\\backslash',
self.assertEqual(files[3].filename, b'baz\\backslash',
'backslashes in filenames on POSIX platform are untouched')
s = MockDest()
@ -179,47 +179,47 @@ class TestJar(unittest.TestCase):
jar = JarReader(fileobj=s)
files = [j for j in jar]
self.assertEqual(files[0].filename, 'bar')
self.assertEqual(files[0].filename, b'bar')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[1].filename, 'foo')
self.assertEqual(files[1].filename, b'foo')
self.assertFalse(files[1].compressed)
self.assertEqual(files[1].read(), b'foo')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertEqual(files[2].filename, b'baz/qux')
self.assertTrue(files[2].compressed)
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertTrue('bar' in jar)
self.assertTrue('foo' in jar)
self.assertFalse('baz' in jar)
self.assertTrue('baz/qux' in jar)
self.assertTrue(jar['bar'], files[1])
self.assertTrue(jar['foo'], files[0])
self.assertTrue(jar['baz/qux'], files[2])
self.assertTrue(b'bar' in jar)
self.assertTrue(b'foo' in jar)
self.assertFalse(b'baz' in jar)
self.assertTrue(b'baz/qux' in jar)
self.assertTrue(jar[b'bar'], files[1])
self.assertTrue(jar[b'foo'], files[0])
self.assertTrue(jar[b'baz/qux'], files[2])
s.seek(0)
jar = JarReader(fileobj=s)
self.assertTrue('bar' in jar)
self.assertTrue('foo' in jar)
self.assertFalse('baz' in jar)
self.assertTrue('baz/qux' in jar)
self.assertTrue(b'bar' in jar)
self.assertTrue(b'foo' in jar)
self.assertFalse(b'baz' in jar)
self.assertTrue(b'baz/qux' in jar)
files[0].seek(0)
self.assertEqual(jar['bar'].filename, files[0].filename)
self.assertEqual(jar['bar'].compressed, files[0].compressed)
self.assertEqual(jar['bar'].read(), files[0].read())
self.assertEqual(jar[b'bar'].filename, files[0].filename)
self.assertEqual(jar[b'bar'].compressed, files[0].compressed)
self.assertEqual(jar[b'bar'].read(), files[0].read())
files[1].seek(0)
self.assertEqual(jar['foo'].filename, files[1].filename)
self.assertEqual(jar['foo'].compressed, files[1].compressed)
self.assertEqual(jar['foo'].read(), files[1].read())
self.assertEqual(jar[b'foo'].filename, files[1].filename)
self.assertEqual(jar[b'foo'].compressed, files[1].compressed)
self.assertEqual(jar[b'foo'].read(), files[1].read())
files[2].seek(0)
self.assertEqual(jar['baz/qux'].filename, files[2].filename)
self.assertEqual(jar['baz/qux'].compressed, files[2].compressed)
self.assertEqual(jar['baz/qux'].read(), files[2].read())
self.assertEqual(jar[b'baz/qux'].filename, files[2].filename)
self.assertEqual(jar[b'baz/qux'].compressed, files[2].compressed)
self.assertEqual(jar[b'baz/qux'].read(), files[2].read())
def test_rejar(self):
s = MockDest()
@ -236,15 +236,15 @@ class TestJar(unittest.TestCase):
jar = JarReader(fileobj=new)
files = [j for j in jar]
self.assertEqual(files[0].filename, 'foo')
self.assertEqual(files[0].filename, b'foo')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), b'foo')
self.assertEqual(files[1].filename, 'bar')
self.assertEqual(files[1].filename, b'bar')
self.assertTrue(files[1].compressed)
self.assertEqual(files[1].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertEqual(files[2].filename, b'baz/qux')
self.assertTrue(files[2].compressed)
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
@ -258,7 +258,7 @@ class TestJar(unittest.TestCase):
jar = JarReader(fileobj=s)
files = [j for j in jar]
self.assertEqual(files[0].filename, 'test_data')
self.assertEqual(files[0].filename, b'test_data')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), b'test_data')
@ -278,15 +278,15 @@ class TestPreload(unittest.TestCase):
jar.add('foo', b'foo')
jar.add('bar', b'abcdefghijklmnopqrstuvwxyz')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar.preload(['baz/qux', b'bar'])
jar.preload(['baz/qux', 'bar'])
jar = JarReader(fileobj=s)
self.assertEqual(jar.last_preloaded, b'bar')
files = [j for j in jar]
self.assertEqual(files[0].filename, 'baz/qux')
self.assertEqual(files[1].filename, 'bar')
self.assertEqual(files[2].filename, 'foo')
self.assertEqual(files[0].filename, b'baz/qux')
self.assertEqual(files[1].filename, b'bar')
self.assertEqual(files[2].filename, b'foo')
class TestJarLog(unittest.TestCase):