mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-22 11:57:19 +00:00
Bug 780329 - Part 1: Python 3 compatibility; r=jhammel
This makes existing mozbuild code compatible with Python 2.7 and Python 3.2. Future additions to this package will be compatible with both Python versions.
This commit is contained in:
parent
93caa9fc7e
commit
a909f8d0c2
@ -4,6 +4,8 @@
|
||||
|
||||
# This modules provides functionality for dealing with compiler warnings.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
@ -6,6 +6,8 @@
|
||||
# could likely be split out of mozbuild. For now, mozbuild is the only
|
||||
# consumer and thus it lives here.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
try:
|
||||
import blessings
|
||||
except ImportError:
|
||||
@ -59,7 +61,7 @@ class StructuredHumanFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
elapsed = self._time(record)
|
||||
|
||||
return u'%4.2f %s' % (elapsed, record.msg.format(**record.params))
|
||||
return '%4.2f %s' % (elapsed, record.msg.format(**record.params))
|
||||
|
||||
def _time(self, record):
|
||||
t = record.created - self.start_time
|
||||
@ -82,7 +84,7 @@ class StructuredTerminalFormatter(StructuredHumanFormatter):
|
||||
t = self.terminal.blue('%4.2f' % self._time(record))
|
||||
f = record.msg.format(**record.params)
|
||||
|
||||
return u'%s %s' % (t, self._colorize(f))
|
||||
return '%s %s' % (t, self._colorize(f))
|
||||
|
||||
def _colorize(self, s):
|
||||
if not self.terminal:
|
||||
|
@ -2,7 +2,7 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import os.path
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
@ -108,7 +108,7 @@ class TestWarningsDatabase(unittest.TestCase):
|
||||
|
||||
self.assertEqual(len(db), 0)
|
||||
|
||||
for i in xrange(10):
|
||||
for i in range(10):
|
||||
db.insert(get_warning(), compute_hash=False)
|
||||
|
||||
self.assertEqual(len(db), 10)
|
||||
@ -120,7 +120,7 @@ class TestWarningsDatabase(unittest.TestCase):
|
||||
"""Ensure that hashing files on insert works."""
|
||||
db = WarningsDatabase()
|
||||
|
||||
temp = NamedTemporaryFile()
|
||||
temp = NamedTemporaryFile(mode='wt')
|
||||
temp.write('x' * 100)
|
||||
temp.flush()
|
||||
|
||||
@ -143,8 +143,8 @@ class TestWarningsDatabase(unittest.TestCase):
|
||||
db = WarningsDatabase()
|
||||
|
||||
source_files = []
|
||||
for i in xrange(1, 21):
|
||||
temp = NamedTemporaryFile()
|
||||
for i in range(1, 21):
|
||||
temp = NamedTemporaryFile(mode='wt')
|
||||
temp.write('x' * (100 * i))
|
||||
temp.flush()
|
||||
|
||||
@ -183,7 +183,7 @@ class TestWarningsDatabase(unittest.TestCase):
|
||||
# If we delete the source file, calling prune should call the warnings
|
||||
# to go away.
|
||||
old_filename = source_files[0].name
|
||||
del source_files[0]
|
||||
source_files[0].close()
|
||||
|
||||
self.assertFalse(os.path.exists(old_filename))
|
||||
|
||||
|
@ -2,10 +2,11 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import unittest
|
||||
|
||||
from StringIO import StringIO
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from mozbuild.util import hash_file
|
||||
@ -14,7 +15,7 @@ from mozbuild.util import hash_file
|
||||
class TestHashing(unittest.TestCase):
|
||||
def test_hash_file_known_hash(self):
|
||||
"""Ensure a known hash value is recreated."""
|
||||
data = 'The quick brown fox jumps over the lazy cog'
|
||||
data = b'The quick brown fox jumps over the lazy cog'
|
||||
expected = 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'
|
||||
|
||||
temp = NamedTemporaryFile()
|
||||
@ -27,7 +28,7 @@ class TestHashing(unittest.TestCase):
|
||||
|
||||
def test_hash_file_large(self):
|
||||
"""Ensure that hash_file seems to work with a large file."""
|
||||
data = 'x' * 1048576
|
||||
data = b'x' * 1048576
|
||||
|
||||
hasher = hashlib.sha1()
|
||||
hasher.update(data)
|
||||
|
@ -5,6 +5,8 @@
|
||||
# This file contains miscellaneous utility functions that don't belong anywhere
|
||||
# in particular.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user