зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1471888
- [mozprofile] Add support for Python 3. r=davehunt
Bug 1471888
- [mozprofile] Add support for Python 3.
Differential Revision: https://phabricator.services.mozilla.com/D5187
--HG--
extra : moz-landing-system : lando
This commit is contained in:
Родитель
e1f72beb97
Коммит
21f7f10fe9
|
@ -11,14 +11,14 @@ import shutil
|
|||
import tempfile
|
||||
import zipfile
|
||||
import hashlib
|
||||
import binascii
|
||||
from xml.dom import minidom
|
||||
|
||||
from six import reraise, string_types
|
||||
|
||||
import mozfile
|
||||
from mozlog.unstructured import getLogger
|
||||
|
||||
_SALT = os.urandom(32).encode('hex')
|
||||
_SALT = binascii.hexlify(os.urandom(32))
|
||||
_TEMPORARY_ADDON_SUFFIX = "@temporary-addon"
|
||||
|
||||
# Logger for 'mozprofile.addons' module
|
||||
|
@ -203,7 +203,7 @@ class AddonManager(object):
|
|||
@classmethod
|
||||
def _gen_iid(cls, addon_path):
|
||||
hash = hashlib.sha1(_SALT)
|
||||
hash.update(addon_path)
|
||||
hash.update(addon_path.encode())
|
||||
return hash.hexdigest() + _TEMPORARY_ADDON_SUFFIX
|
||||
|
||||
@classmethod
|
||||
|
@ -262,7 +262,7 @@ class AddonManager(object):
|
|||
manifest = compressed_file.read('install.rdf')
|
||||
elif 'manifest.json' in filenames:
|
||||
is_webext = True
|
||||
manifest = compressed_file.read('manifest.json')
|
||||
manifest = compressed_file.read('manifest.json').decode()
|
||||
manifest = json.loads(manifest)
|
||||
else:
|
||||
raise KeyError("No manifest")
|
||||
|
@ -279,7 +279,7 @@ class AddonManager(object):
|
|||
else:
|
||||
raise IOError('Add-on path is neither an XPI nor a directory: %s' % addon_path)
|
||||
except (IOError, KeyError) as e:
|
||||
reraise(AddonFormatError(str(e)), None, sys.exc_info()[2])
|
||||
reraise(AddonFormatError, AddonFormatError(str(e)), sys.exc_info()[2])
|
||||
|
||||
if is_webext:
|
||||
details['version'] = manifest['version']
|
||||
|
@ -309,7 +309,7 @@ class AddonManager(object):
|
|||
if entry in details.keys():
|
||||
details.update({entry: get_text(node)})
|
||||
except Exception as e:
|
||||
reraise(AddonFormatError(str(e)), None, sys.exc_info()[2])
|
||||
reraise(AddonFormatError, AddonFormatError(str(e)), sys.exc_info()[2])
|
||||
|
||||
# turn unpack into a true/false value
|
||||
if isinstance(details['unpack'], string_types):
|
||||
|
|
|
@ -15,6 +15,7 @@ import sqlite3
|
|||
|
||||
from six import string_types
|
||||
from six.moves.urllib import parse
|
||||
import six
|
||||
|
||||
__all__ = ['MissingPrimaryLocationError', 'MultiplePrimaryLocationsError',
|
||||
'DEFAULT_PORTS', 'DuplicateLocationError', 'BadPortLocationError',
|
||||
|
@ -271,7 +272,7 @@ class Permissions(object):
|
|||
for location in locations:
|
||||
# set the permissions
|
||||
permissions = {'allowXULXBL': 'noxul' not in location.options}
|
||||
for perm, allow in permissions.iteritems():
|
||||
for perm, allow in six.iteritems(permissions):
|
||||
if allow:
|
||||
permission_type = 1
|
||||
else:
|
||||
|
|
|
@ -168,6 +168,9 @@ class Preferences(object):
|
|||
lines = [i.strip() for i in mozfile.load(path).readlines()]
|
||||
_lines = []
|
||||
for line in lines:
|
||||
# decode bytes in case of URL processing
|
||||
if isinstance(line, bytes):
|
||||
line = line.decode()
|
||||
if not line.startswith(pref_setter):
|
||||
continue
|
||||
if '//' in line:
|
||||
|
|
|
@ -14,7 +14,7 @@ from abc import ABCMeta, abstractmethod, abstractproperty
|
|||
from shutil import copytree
|
||||
|
||||
import mozfile
|
||||
from six import string_types
|
||||
from six import string_types, python_2_unicode_compatible
|
||||
|
||||
from .addons import AddonManager
|
||||
from .permissions import Permissions
|
||||
|
@ -150,6 +150,7 @@ class BaseProfile(object):
|
|||
return os.path.exists(self.profile)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Profile(BaseProfile):
|
||||
"""Handles all operations regarding profile.
|
||||
|
||||
|
@ -421,9 +422,6 @@ class Profile(BaseProfile):
|
|||
return retval
|
||||
|
||||
def __str__(self):
|
||||
return unicode(self).encode('utf-8')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.summary()
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
[bdist_wheel]
|
||||
universal=1
|
|
@ -7,7 +7,7 @@ from __future__ import absolute_import
|
|||
from setuptools import setup
|
||||
|
||||
PACKAGE_NAME = 'mozprofile'
|
||||
PACKAGE_VERSION = '1.1.0'
|
||||
PACKAGE_VERSION = '2.0.0'
|
||||
|
||||
deps = [
|
||||
'mozfile==1.*',
|
||||
|
@ -25,7 +25,7 @@ setup(name=PACKAGE_NAME,
|
|||
'Natural Language :: English',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
],
|
||||
keywords='mozilla',
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[DEFAULT]
|
||||
subsuite = mozbase, os == "linux"
|
||||
skip-if = python == 3
|
||||
[test_addonid.py]
|
||||
[test_server_locations.py]
|
||||
[test_preferences.py]
|
||||
|
|
|
@ -72,8 +72,7 @@ def test_basic_prefs(compare_generated):
|
|||
|
||||
_prefs = {"browser.startup.homepage": "http://planet.mozilla.org/"}
|
||||
commandline = []
|
||||
_prefs = _prefs.items()
|
||||
for pref, value in _prefs:
|
||||
for pref, value in _prefs.items():
|
||||
commandline += ["--pref", "%s:%s" % (pref, value)]
|
||||
compare_generated(_prefs, commandline)
|
||||
|
||||
|
@ -100,8 +99,8 @@ browser.startup.homepage = http://planet.mozilla.org/
|
|||
browser.startup.homepage = http://github.com/
|
||||
"""
|
||||
try:
|
||||
fd, name = tempfile.mkstemp(suffix='.ini')
|
||||
os.write(fd, _ini)
|
||||
fd, name = tempfile.mkstemp(suffix='.ini', text=True)
|
||||
os.write(fd, _ini.encode())
|
||||
os.close(fd)
|
||||
commandline = ["--preferences", name]
|
||||
|
||||
|
@ -129,8 +128,8 @@ def test_ini_keep_case(compare_generated):
|
|||
general.warnOnAboutConfig = False
|
||||
"""
|
||||
try:
|
||||
fd, name = tempfile.mkstemp(suffix='.ini')
|
||||
os.write(fd, _ini)
|
||||
fd, name = tempfile.mkstemp(suffix='.ini', text=True)
|
||||
os.write(fd, _ini.encode())
|
||||
os.close(fd)
|
||||
commandline = ["--preferences", name]
|
||||
|
||||
|
@ -294,7 +293,7 @@ def test_can_read_prefs_with_multiline_comments():
|
|||
|
||||
user_pref("webgl.enabled_for_all_sites", true);
|
||||
user_pref("webgl.force-enabled", true);
|
||||
""")
|
||||
""".encode())
|
||||
assert Preferences.read_prefs(user_js.name) == [
|
||||
('webgl.enabled_for_all_sites', True),
|
||||
('webgl.force-enabled', True)
|
||||
|
@ -309,7 +308,7 @@ def test_json(compare_generated):
|
|||
|
||||
# just repr it...could use the json module but we don't need it here
|
||||
with mozfile.NamedTemporaryFile(suffix='.json') as f:
|
||||
f.write(json)
|
||||
f.write(json.encode())
|
||||
f.flush()
|
||||
|
||||
commandline = ["--preferences", f.name]
|
||||
|
@ -321,7 +320,7 @@ def test_json_datatypes():
|
|||
json = """{"zoom.minPercent": 30.1, "zoom.maxPercent": 300}"""
|
||||
|
||||
with mozfile.NamedTemporaryFile(suffix='.json') as f:
|
||||
f.write(json)
|
||||
f.write(json.encode())
|
||||
f.flush()
|
||||
|
||||
with pytest.raises(PreferencesReadError):
|
||||
|
@ -342,7 +341,7 @@ def test_prefs_write():
|
|||
path = None
|
||||
read_prefs = None
|
||||
try:
|
||||
with mozfile.NamedTemporaryFile(suffix='.js', delete=False) as f:
|
||||
with mozfile.NamedTemporaryFile(suffix='.js', delete=False, mode='w+t') as f:
|
||||
path = f.name
|
||||
preferences.write(f, _prefs)
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ from __future__ import absolute_import
|
|||
|
||||
import mozprofile
|
||||
import os
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
import mozunit
|
||||
|
||||
|
@ -37,9 +39,14 @@ def test_profileprint(tmpdir):
|
|||
def test_str_cast():
|
||||
"""Test casting to a string."""
|
||||
profile = mozprofile.Profile()
|
||||
assert str(profile) == profile.summary().encode("utf-8")
|
||||
if sys.version_info[0] >= 3:
|
||||
assert str(profile) == profile.summary()
|
||||
else:
|
||||
assert str(profile) == profile.summary().encode("utf-8")
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] >= 3,
|
||||
reason="no unicode() operator starting from python3")
|
||||
def test_unicode_cast():
|
||||
"""Test casting to a unicode string."""
|
||||
profile = mozprofile.Profile()
|
||||
|
@ -55,14 +62,14 @@ def test_profile_diff():
|
|||
|
||||
# diff two profiles
|
||||
diff = dict(mozprofile.diff(profile1, profile2))
|
||||
assert diff.keys() == ['user.js']
|
||||
assert list(diff.keys()) == ['user.js']
|
||||
lines = [line.strip() for line in diff['user.js'].splitlines()]
|
||||
assert '+foo: bar' in lines
|
||||
|
||||
# diff a blank vs FirefoxProfile
|
||||
ff_profile = mozprofile.FirefoxProfile()
|
||||
diff = dict(mozprofile.diff(profile2, ff_profile))
|
||||
assert diff.keys() == ['user.js']
|
||||
assert list(diff.keys()) == ['user.js']
|
||||
lines = [line.strip() for line in diff['user.js'].splitlines()]
|
||||
assert '-foo: bar' in lines
|
||||
ff_pref_lines = ['+%s: %s' % (key, value)
|
||||
|
|
|
@ -17,7 +17,7 @@ deps = [
|
|||
'mozinfo>=0.7,<2',
|
||||
'mozlog==3.*',
|
||||
'mozprocess>=0.23,<1',
|
||||
'mozprofile>=1.1.0,<2',
|
||||
'mozprofile>=1.1.0,<3',
|
||||
'six>=1.10.0,<2',
|
||||
]
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ deps = ['httplib2 == 0.9.2',
|
|||
'mozinfo >= 0.10',
|
||||
'mozinstall == 1.16',
|
||||
'mozprocess == 0.26',
|
||||
'mozprofile == 1.1.0',
|
||||
'mozprofile == 2.0.0',
|
||||
'mozrunner == 7.0.1',
|
||||
'mozversion == 1.5',
|
||||
]
|
||||
|
|
Загрузка…
Ссылка в новой задаче