Bug 1604277 - mozpack/errors.py and mozpack/manifests.py support python3 r=mars

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ricky Stewart 2019-12-18 16:43:09 +00:00
parent 3e58392872
commit c8aa318a85
5 changed files with 12 additions and 11 deletions

View File

@ -113,7 +113,7 @@ class FileRegistry(object):
'''
Return all paths stored in the container, in the order they were added.
'''
return self._files.keys()
return list(self._files)
def __len__(self):
'''

View File

@ -6,6 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals
from contextlib import contextmanager
import json
import six
from .files import (
AbsoluteSymlinkFile,
@ -116,7 +117,7 @@ class InstallManifest(object):
self._source_files = set()
if path or fileobj:
with _auto_fileobj(path, fileobj, 'rb') as fh:
with _auto_fileobj(path, fileobj, 'r') as fh:
self._source_files.add(fh.name)
self._load_from_fileobj(fh)
@ -175,7 +176,7 @@ class InstallManifest(object):
dest, content = fields[1:]
self.add_content(
self._decode_field_entry(content).encode('utf-8'), dest)
six.ensure_text(self._decode_field_entry(content)), dest)
continue
# Don't fail for non-actionable items, allowing
@ -228,7 +229,7 @@ class InstallManifest(object):
It is an error if both are specified.
"""
with _auto_fileobj(path, fileobj, 'wb') as fh:
with _auto_fileobj(path, fileobj, 'wt') as fh:
fh.write('%d\n' % self.CURRENT_VERSION)
for dest in sorted(self._dests):
@ -243,12 +244,12 @@ class InstallManifest(object):
source = mozpath.join(base, path)
parts = ['%d' % type, mozpath.join(dest, path), source]
fh.write('%s\n' % self.FIELD_SEPARATOR.join(
p.encode('utf-8') for p in parts))
six.ensure_text(p) for p in parts))
else:
parts = ['%d' % entry[0], dest]
parts.extend(entry[1:])
fh.write('%s\n' % self.FIELD_SEPARATOR.join(
p.encode('utf-8') for p in parts))
six.ensure_text(p) for p in parts))
def add_link(self, source, dest):
"""Add a link to this manifest.

View File

@ -4,6 +4,8 @@ subsuite = mozbuild
[test_archive.py]
[test_chrome_flags.py]
[test_chrome_manifest.py]
[test_errors.py]
[test_files.py]
[test_manifests.py]
[test_mozjar.py]
[test_path.py]

View File

@ -3,8 +3,6 @@ subsuite = mozbuild
skip-if = python == 3
[test_copier.py]
[test_errors.py]
[test_manifests.py]
[test_packager.py]
[test_packager_formats.py]
[test_packager_l10n.py]

View File

@ -26,7 +26,7 @@ class TestInstallManifest(TestWithTmpDir):
def test_malformed(self):
f = self.tmppath('manifest')
open(f, 'wb').write('junk\n')
open(f, 'wt').write('junk\n')
with self.assertRaises(UnreadableInstallManifest):
InstallManifest(f)
@ -94,7 +94,7 @@ class TestInstallManifest(TestWithTmpDir):
m.write(path=p)
self.assertTrue(os.path.isfile(p))
with open(p, 'rb') as fh:
with open(p, 'r') as fh:
c = fh.read()
self.assertEqual(c.count('\n'), 9)
@ -109,7 +109,7 @@ class TestInstallManifest(TestWithTmpDir):
p2 = self.tmppath('m2')
m2.write(path=p2)
with open(p2, 'rb') as fh:
with open(p2, 'r') as fh:
c2 = fh.read()
self.assertEqual(c, c2)