Bug 1547730 - don't use py2 builtin 'unicode' in mozpack and deps r=#build

Also adjust 'basestring' usage in some places.

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

--HG--
extra : rebase_source : f0fecd6b040336b0cf2f055e266fe37eea5a9a48
extra : intermediate-source : 712718250f0ba5c286c1fb6b6c7f370b713c7225
extra : source : 6b24ce2da518d8158e13627adb11c9fcad19c92a
This commit is contained in:
Justin Wood 2019-04-16 17:07:08 -04:00
Родитель 76d0c8183b
Коммит 8d0a1c56b3
7 изменённых файлов: 20 добавлений и 28 удалений

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

@ -22,12 +22,6 @@ from mozbuild.util import (
from mozbuild.shellutil import quote as shell_quote
if sys.version_info.major == 2:
text_type = unicode
else:
text_type = str
class BuildConfig(object):
"""Represents the output of configure."""
@ -197,7 +191,7 @@ class ConfigEnvironment(object):
self.substs_unicode = {}
def decode(v):
if not isinstance(v, text_type):
if not isinstance(v, six.text_type):
try:
return v.decode('utf-8')
except UnicodeDecodeError:
@ -207,7 +201,7 @@ class ConfigEnvironment(object):
if not isinstance(v, six.string_types):
if isinstance(v, Iterable):
type(v)(decode(i) for i in v)
elif not isinstance(v, text_type):
elif not isinstance(v, six.text_type):
v = decode(v)
self.substs_unicode[k] = v

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

@ -287,7 +287,7 @@ class ConfigureSandbox(dict):
for b in ('None', 'False', 'True', 'int', 'bool', 'any', 'all', 'len',
'list', 'tuple', 'set', 'dict', 'isinstance', 'getattr',
'hasattr', 'enumerate', 'range', 'zip', 'AssertionError')
}, __import__=forbidden_import, str=unicode)
}, __import__=forbidden_import, str=six.text_type)
# Expose a limited set of functions from os.path
OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{

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

@ -9,6 +9,7 @@ import itertools
import locale
import logging
import os
import six
import sys
from collections import deque
from contextlib import contextmanager
@ -54,7 +55,7 @@ class Version(LooseVersion):
def __cmp__(self, other):
# LooseVersion checks isinstance(StringType), so work around it.
if isinstance(other, unicode):
if isinstance(other, six.text_type):
other = other.encode('ascii')
return LooseVersion.__cmp__(self, other)

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

@ -27,6 +27,7 @@ from __future__ import absolute_import, print_function
import sys
import os
import re
import six
from optparse import OptionParser
import errno
from mozbuild.makeutil import Makefile
@ -791,7 +792,7 @@ class Preprocessor:
args can either be a file name, or a file-like object.
Files should be opened, and will be closed after processing.
"""
isName = type(args) == str or type(args) == unicode
isName = isinstance(args, six.string_types)
oldCheckLineNumbers = self.checkLineNumbers
self.checkLineNumbers = False
if isName:

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

@ -33,11 +33,6 @@ from io import (
)
if sys.version_info[0] == 3:
str_type = str
else:
str_type = basestring
if sys.platform == 'win32':
_kernel32 = ctypes.windll.kernel32
_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000
@ -78,7 +73,7 @@ def hash_file(path, hasher=None):
return h.hexdigest()
class EmptyValue(unicode):
class EmptyValue(six.text_type):
"""A dummy type that behaves like an empty string and sequence.
This type exists in order to support
@ -175,7 +170,7 @@ def mkdir(path, not_indexed=False):
if not_indexed:
if sys.platform == 'win32':
if isinstance(path, str_type):
if isinstance(path, six.string_types):
fn = _kernel32.SetFileAttributesW
else:
fn = _kernel32.SetFileAttributesA
@ -229,7 +224,7 @@ class FileAvoidWrite(BytesIO):
self.mode = mode
def write(self, buf):
if isinstance(buf, unicode):
if isinstance(buf, six.text_type):
buf = buf.encode('utf-8')
BytesIO.write(self, buf)
@ -821,7 +816,7 @@ class HierarchicalStringList(object):
if not isinstance(value, list):
raise ValueError('Expected a list of strings, not %s' % type(value))
for v in value:
if not isinstance(v, str_type):
if not isinstance(v, six.string_types):
raise ValueError(
'Expected a list of strings, not an element of %s' % type(v))
@ -1192,7 +1187,7 @@ class EnumStringComparisonError(Exception):
pass
class EnumString(unicode):
class EnumString(six.text_type):
'''A string type that only can have a limited set of values, similarly to
an Enum, and can only be compared against that set of values.
@ -1229,7 +1224,7 @@ def _escape_char(c):
# quoting could be done with either ' or ".
if c == "'":
return "\\'"
return unicode(c.encode('unicode_escape'))
return six.text_type(c.encode('unicode_escape'))
# Mapping table between raw characters below \x80 and their escaped
@ -1269,7 +1264,7 @@ def indented_repr(o, indent=4):
elif isinstance(o, bytes):
yield 'b'
yield repr(o)
elif isinstance(o, unicode):
elif isinstance(o, six.text_type):
yield "'"
# We want a readable string (non escaped unicode), but some
# special characters need escaping (e.g. \n, \t, etc.)
@ -1303,7 +1298,7 @@ def encode(obj, encoding='utf-8'):
}
if isinstance(obj, bytes):
return obj
if isinstance(obj, unicode):
if isinstance(obj, six.text_type):
return obj.encode(encoding)
if isinstance(obj, Iterable):
return [encode(i, encoding) for i in obj]
@ -1397,7 +1392,7 @@ def patch_main():
def ensure_bytes(value):
if isinstance(value, basestring):
if isinstance(value, six.text_type):
return value.encode('utf8')
return value

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

@ -68,7 +68,7 @@ else:
def _copyfile(src, dest):
# False indicates `dest` should be overwritten if it exists already.
if isinstance(src, unicode) and isinstance(dest, unicode):
if isinstance(src, six.text_type) and isinstance(dest, six.text_type):
_CopyFileW(src, dest, False)
elif isinstance(src, str) and isinstance(dest, str):
_CopyFileA(src, dest, False)

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

@ -32,6 +32,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import mercurial.error as error
import mercurial.hg as hg
import mercurial.ui as hgui
import six
from .files import (
BaseFinder,
@ -56,7 +57,7 @@ class MercurialNativeRevisionFinder(BaseFinder):
Accepts a Mercurial localrepo and changectx instance.
"""
if isinstance(repo, (str, unicode)):
if isinstance(repo, six.string_types):
path = repo
repo = hg.repository(hgui.ui(), repo)
else:
@ -85,7 +86,7 @@ class MercurialNativeRevisionFinder(BaseFinder):
return self._get(path)
def _get(self, path):
if isinstance(path, unicode):
if isinstance(path, six.text_type):
path = path.encode('utf-8', 'replace')
try: