Bug 1547730 - Do dict.iteritems() via six to support py3. r=#build

shellutil.py needed special handling since it is invoked earlier than the
vendor directory adding we do, so it does not have six available.

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

--HG--
extra : rebase_source : c5c611d280dc821747c9db736e4943c2cc421557
extra : intermediate-source : 30fb268b41fdc45937a22ab446a8805fb099c1f0
extra : source : d102292b6b5b812e7df165116410488d18042bd3
This commit is contained in:
Justin Wood 2019-04-15 11:48:03 -04:00
Родитель 6d9a1f6a63
Коммит 91e37fa7ff
14 изменённых файлов: 70 добавлений и 52 удалений

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

@ -9,6 +9,7 @@ import inspect
import logging
import os
import re
import six
import sys
import types
from collections import OrderedDict
@ -664,7 +665,7 @@ class ConfigureSandbox(dict):
'''
when = self._normalize_when(kwargs.get('when'), 'option')
args = [self._resolve(arg) for arg in args]
kwargs = {k: self._resolve(v) for k, v in kwargs.iteritems()
kwargs = {k: self._resolve(v) for k, v in six.iteritems(kwargs)
if k != 'when'}
option = Option(*args, **kwargs)
if when:
@ -762,7 +763,7 @@ class ConfigureSandbox(dict):
(k[:-len('_impl')], getattr(self, k))
for k in dir(self) if k.endswith('_impl') and k != 'template_impl'
)
glob.update((k, v) for k, v in self.iteritems() if k not in glob)
glob.update((k, v) for k, v in six.iteritems(self) if k not in glob)
template = self._prepare_function(func, update_globals)
@ -787,7 +788,7 @@ class ConfigureSandbox(dict):
def wrapper(*args, **kwargs):
args = [maybe_prepare_function(arg) for arg in args]
kwargs = {k: maybe_prepare_function(v)
for k, v in kwargs.iteritems()}
for k, v in kwargs.items()}
ret = template(*args, **kwargs)
if isfunction(ret):
# We can't expect the sandboxed code to think about all the
@ -1055,7 +1056,8 @@ class ConfigureSandbox(dict):
return func
glob = SandboxedGlobal(
(k, v) for k, v in func.func_globals.iteritems()
(k, v)
for k, v in six.iteritems(func.func_globals)
if (inspect.isfunction(v) and v not in self._templates) or (
inspect.isclass(v) and issubclass(v, Exception))
)

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

@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
import six
import sys
import types
from collections import OrderedDict
@ -132,7 +133,7 @@ class ConflictingOptionError(InvalidOptionError):
if format_data:
message = message.format(**format_data)
super(ConflictingOptionError, self).__init__(message)
for k, v in format_data.iteritems():
for k, v in six.iteritems(format_data):
setattr(self, k, v)

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

@ -296,10 +296,11 @@ class Preprocessor:
def __init__(self, defines=None, marker='#'):
self.context = Context()
for k, v in {'FILE': '',
'LINE': 0,
'DIRECTORY': os.path.abspath('.')}.iteritems():
self.context[k] = v
self.context.update({
'FILE': '',
'LINE': 0,
'DIRECTORY': os.path.abspath('.')
})
try:
# Can import globally because of bootstrapping issues.
from buildconfig import topsrcdir, topobjdir
@ -319,23 +320,25 @@ class Preprocessor:
self.checkLineNumbers = False
self.filters = []
self.cmds = {}
for cmd, level in {'define': 0,
'undef': 0,
'if': sys.maxint,
'ifdef': sys.maxint,
'ifndef': sys.maxint,
'else': 1,
'elif': 1,
'elifdef': 1,
'elifndef': 1,
'endif': sys.maxint,
'expand': 0,
'literal': 0,
'filter': 0,
'unfilter': 0,
'include': 0,
'includesubst': 0,
'error': 0}.iteritems():
for cmd, level in (
('define', 0),
('undef', 0),
('if', sys.maxint),
('ifdef', sys.maxint),
('ifndef', sys.maxint),
('else', 1),
('elif', 1),
('elifdef', 1),
('elifndef', 1),
('endif', sys.maxint),
('expand', 0),
('literal', 0),
('filter', 0),
('unfilter', 0),
('include', 0),
('includesubst', 0),
('error', 0),
):
self.cmds[cmd] = (level, getattr(self, 'do_' + cmd))
self.out = sys.stdout
self.setMarker(marker)

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

@ -17,7 +17,7 @@ def _tokens2re(**tokens):
# which matches the pattern and captures it in a named match group.
# The group names and patterns are given as arguments.
all_tokens = '|'.join('(?P<%s>%s)' % (name, value)
for name, value in tokens.iteritems())
for name, value in tokens.items())
nonescaped = r'(?<!\\)(?:%s)' % all_tokens
# The final pattern matches either the above pattern, or an escaped

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

@ -17,6 +17,7 @@ import hashlib
import itertools
import os
import re
import six
import stat
import sys
import time
@ -93,7 +94,7 @@ class ReadOnlyNamespace(object):
"""A class for objects with immutable attributes set at initialization."""
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
super(ReadOnlyNamespace, self).__setattr__(k, v)
def __delattr__(self, key):
@ -582,7 +583,7 @@ def FlagsFactory(flags):
_flags = flags
def update(self, **kwargs):
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
setattr(self, k, v)
def __getattr__(self, name):
@ -1298,7 +1299,7 @@ def encode(obj, encoding='utf-8'):
if isinstance(obj, dict):
return {
encode(k, encoding): encode(v, encoding)
for k, v in obj.iteritems()
for k, v in six.iteritems(obj)
}
if isinstance(obj, bytes):
return obj

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

@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import re
import six
from distutils.version import LooseVersion
from mozpack.errors import errors
from collections import OrderedDict
@ -262,7 +263,7 @@ class Flags(OrderedDict):
flags.match(application='foo', appversion='3.5') returns True
flags.match(application='foo', appversion='3.0') returns False
'''
for name, value in filter.iteritems():
for name, value in six.iteritems(filter):
if name not in self:
continue
if not self[name].matches(value):

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

@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
import six
import stat
import sys
@ -145,7 +146,7 @@ class FileRegistry(object):
for path, file in registry:
(...)
'''
return self._files.iteritems()
return six.iteritems(self._files)
def required_directories(self):
'''

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

@ -9,6 +9,7 @@ import inspect
import os
import platform
import shutil
import six
import stat
import subprocess
import uuid
@ -1093,7 +1094,7 @@ class ComposedFinder(BaseFinder):
from mozpack.copier import FileRegistry
self.files = FileRegistry()
for base, finder in sorted(finders.iteritems()):
for base, finder in sorted(six.iteritems(finders)):
if self.files.contains(base):
self.files.remove(base)
for p, f in finder.find(''):

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

@ -9,6 +9,7 @@ import struct
import subprocess
import zlib
import os
import six
from zipfile import (
ZIP_STORED,
ZIP_DEFLATED,
@ -96,7 +97,7 @@ class JarStruct(object):
# For all fields used as other fields sizes, keep track of their value
# separately.
sizes = dict((t, 0) for t in self.size_fields)
for name, t in self.STRUCT.iteritems():
for name, t in six.iteritems(self.STRUCT):
if t in JarStruct.TYPE_MAPPING:
value, size = JarStruct.get_data(t, data[offset:])
else:
@ -115,7 +116,7 @@ class JarStruct(object):
Initialize an instance with empty fields.
'''
self.signature = self.MAGIC
for name, t in self.STRUCT.iteritems():
for name, t in six.iteritems(self.STRUCT):
if name in self.size_fields:
continue
self._values[name] = 0 if t in JarStruct.TYPE_MAPPING else ''
@ -140,9 +141,10 @@ class JarStruct(object):
from self.STRUCT.
'''
serialized = struct.pack(b'<I', self.signature)
sizes = dict((t, name) for name, t in self.STRUCT.iteritems()
sizes = dict((t, name)
for name, t in six.iteritems(self.STRUCT)
if t not in JarStruct.TYPE_MAPPING)
for name, t in self.STRUCT.iteritems():
for name, t in six.iteritems(self.STRUCT):
if t in JarStruct.TYPE_MAPPING:
format, size = JarStruct.TYPE_MAPPING[t]
if name in sizes:
@ -161,7 +163,7 @@ class JarStruct(object):
variable length fields.
'''
size = JarStruct.TYPE_MAPPING['uint32'][1]
for name, type in self.STRUCT.iteritems():
for name, type in six.iteritems(self.STRUCT):
if type in JarStruct.TYPE_MAPPING:
size += JarStruct.TYPE_MAPPING[type][1]
else:
@ -182,7 +184,7 @@ class JarStruct(object):
return key in self._values
def __iter__(self):
return self._values.iteritems()
return six.iteritems(self._values)
def __repr__(self):
return "<%s %s>" % (self.__class__.__name__,

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

@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals
from mozbuild.preprocessor import Preprocessor
import re
import os
import six
from mozpack.errors import errors
from mozpack.chrome.manifest import (
Manifest,
@ -366,7 +367,8 @@ class SimplePackager(object):
bases = self.get_bases()
broken_bases = sorted(
m for m, includer in self._included_manifests.iteritems()
m
for m, includer in six.iteritems(self._included_manifests)
if mozpath.basedir(m, bases) != mozpath.basedir(includer, bases))
for m in broken_bases:
errors.fatal('"%s" is included from "%s", which is outside "%s"' %

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

@ -11,6 +11,7 @@ directory.
import json
import os
import six
import mozpack.path as mozpath
from mozpack.packager.formats import (
FlatFormatter,
@ -258,7 +259,7 @@ def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
formatter.add(p, f)
# Transplant jar preloading information.
for path, log in app_finder.jarlogs.iteritems():
for path, log in six.iteritems(app_finder.jarlogs):
assert isinstance(copier[path], Jarrer)
copier[path].preload([l.replace(locale, l10n_locale) for l in log])
@ -289,7 +290,7 @@ def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()):
finders = {
'': l10n_finder,
}
for base, path in extra_l10n.iteritems():
for base, path in six.iteritems(extra_l10n):
finders[base] = UnpackFinder(path)
l10n_finder = ComposedFinder(finders)
copier = FileCopier()

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

@ -19,6 +19,7 @@ import mozpack.path as mozpath
import unittest
import mozunit
import os
import six
import stat
from mozpack.errors import ErrorMessage
from mozpack.test.test_files import (
@ -130,7 +131,7 @@ class TestFileRegistry(BaseTestFileRegistry, unittest.TestCase):
'bar': [],
}
reg = FileRegistry()
for path, parts in cases.iteritems():
for path, parts in six.iteritems(cases):
self.assertEqual(reg._partial_paths(path), parts)
def test_file_registry(self):

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

@ -33,6 +33,7 @@ from mozpack.test.test_files import (
bar_xpt,
)
import mozpack.path as mozpath
import six
from itertools import chain
from test_errors import TestErrors
@ -123,7 +124,7 @@ RESULT_FLAT = {
for addon in ('addon0', 'addon1', 'app/chrome/addons/addon2'):
RESULT_FLAT.update({
mozpath.join(addon, p): f
for p, f in {
for p, f in six.iteritems({
'chrome.manifest': [
'manifest chrome/chrome.manifest',
'manifest components/components.manifest',
@ -138,7 +139,7 @@ for addon in ('addon0', 'addon1', 'app/chrome/addons/addon2'):
],
'components/bar.xpt': bar_xpt,
'components/foo.xpt': foo2_xpt,
}.iteritems()
})
})
RESULT_JAR = {
@ -186,12 +187,12 @@ RESULT_JAR.update({
},
'addon1.xpi': {
mozpath.relpath(p, 'addon1'): f
for p, f in RESULT_FLAT.iteritems()
for p, f in six.iteritems(RESULT_FLAT)
if p.startswith('addon1/')
},
'app/chrome/addons/addon2.xpi': {
mozpath.relpath(p, 'app/chrome/addons/addon2'): f
for p, f in RESULT_FLAT.iteritems()
for p, f in six.iteritems(RESULT_FLAT)
if p.startswith('app/chrome/addons/addon2/')
},
})
@ -262,7 +263,7 @@ RESULT_OMNIJAR_WITH_SUBPATH = {
CONTENTS_WITH_BASE = {
'bases': {
mozpath.join('base/root', b) if b else 'base/root': a
for b, a in CONTENTS['bases'].iteritems()
for b, a in six.iteritems(CONTENTS['bases'])
},
'manifests': [
m.move(mozpath.join('base/root', m.base))
@ -270,7 +271,7 @@ CONTENTS_WITH_BASE = {
],
'files': {
mozpath.join('base/root', p): f
for p, f in CONTENTS['files'].iteritems()
for p, f in six.iteritems(CONTENTS['files'])
},
}
@ -284,7 +285,7 @@ CONTENTS_WITH_BASE['files'].update(EXTRA_CONTENTS)
def result_with_base(results):
result = {
mozpath.join('base/root', p): v
for p, v in results.iteritems()
for p, v in six.iteritems(results)
}
result.update(EXTRA_CONTENTS)
return result
@ -302,7 +303,7 @@ def fill_formatter(formatter, contents):
for manifest in contents['manifests']:
formatter.add_manifest(manifest)
for k, v in sorted(contents['files'].iteritems()):
for k, v in sorted(six.iteritems(contents['files'])):
if k.endswith('.xpt'):
formatter.add_interfaces(k, v)
else:

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

@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import unittest
import six
import mozunit
from test_packager import MockFinder
from mozpack.packager import l10n
@ -120,7 +121,7 @@ class TestL10NRepack(unittest.TestCase):
self.assertEqual(
dict((p, f.open().read()) for p, f in copier),
dict((p, f.open().read()) for p, f in repacked.iteritems())
dict((p, f.open().read()) for p, f in six.iteritems(repacked)),
)