Changeset 250375 in webkit


Ignore:
Timestamp:
Sep 25, 2019 7:01:53 PM (5 years ago)
Author:
Jonathan Bedard
Message:

Python 3: Add support in webkitpy.common.system
https://bugs.webkit.org/show_bug.cgi?id=201826
<rdar://problem/55452671>

Reviewed by Stephanie Lewis.

Tested compatibility by running 'python3 -m unittest webkitpy.common.system.<_unittest>' on
each of the effected files.

  • Scripts/webkitpy/common/checkout/changelog.py: Import StringIO from io module.

(set_reviewer):
(set_short_description_and_bug_url):

  • Scripts/webkitpy/common/checkout/checkout.py: Import StringIO from io module.

(Checkout._latest_entry_for_changelog_at_revision):

  • Scripts/webkitpy/common/config/committers.py:

(CommitterList.load_json): iteritems -> items.

  • Scripts/webkitpy/common/net/networktransaction.py:

(NetworkTransaction.run): urllib2 is urllib in Python3.

  • Scripts/webkitpy/common/system/abstractexecutive.py:

(AbstractExecutive._stringify_args):
(AbstractExecutive.command_for_printing): The str type is unicode in Python3.

  • Scripts/webkitpy/common/system/crashlogs_unittest.py: Explicitly encode and decode binary crashlogs.
  • Scripts/webkitpy/common/system/environment_unittest.py: Use absolute imports.
  • Scripts/webkitpy/common/system/executive.py:

(ScriptError.message_with_output): The str type is unicode in Python3.
(Executive.WrappedPopen): Python3's Popen object is a context manager. To allow us to use it as one,
our Python2 Popen needs to be one as well.
(Executive.WrappedPopen.init):
(Executive.WrappedPopen.enter):
(Executive.WrappedPopen.exit):
(Executive._run_command_with_teed_output): Simplify loop, decode unicode strings.
(Executive.run_and_throw_if_fail): The child output file should not be unicode strings.
(Executive.running_pids): Use the Popen context manager to guarantee clean-up.
(Executive._compute_stdin):
(Executive.run_command): Use the Popen context manager to guarantee clean-up.
(Executive._stringify_args): The str type is unicode in Python3.
(Executive.popen): Return a context manager if the Popen object is not one.

  • Scripts/webkitpy/common/system/executive_mock.py:

(MockProcess.init): StringIO -> BytesIO.
(MockProcess.enter):
(MockProcess):
(MockProcess.exit):

  • Scripts/webkitpy/common/system/executive_unittest.py:

(ExecutiveTest.test_auto_stringify_args): Use the Popen context manager to guarantee clean-up.
(ExecutiveTest.test_popen_args): Ditto.
(ExecutiveTest.serial_test_kill_process): Ditto.
(ExecutiveTest.serial_test_kill_all): Ditto.

  • Scripts/webkitpy/common/system/filesystem.py:

(FileSystem.read_binary_file): Use 'open' instead of 'file'.
(FileSystem.write_binary_file): Ditto.
(FileSystem.write_text_file): The str type is unicode in Python3.
(FileSystem.relpath):
(FileSystem.remove): The WindowsError is just anther OSError in Python3.
(FileSystem._WindowsError): Deleted.

  • Scripts/webkitpy/common/system/filesystem_mock.py:

(MockFileSystem.glob): filter returns a generator instead of a list.
(WritableBinaryFileObject.init): Binary files are comprised of bytes, not string in Python3.
(WritableBinaryFileObject.write): Ditto.
(ReadableTextFileObject.init): Ditto.

  • Scripts/webkitpy/common/system/filesystem_mock_unittest.py:

(MockFileSystemTest.test_normpath):
(MockFileSystemTest.test_dirs_under): assertEquals -> assertEqual.

  • Scripts/webkitpy/common/system/filesystem_unittest.py:

(RealFileSystemTest.test_read_and_write_file): Explicitly define byte arrays instead of strings.
(RealFileSystemTest.test_remove_file_with_retry.remove_with_exception): The WindowsError is just
anther OSError in Python3.

  • Scripts/webkitpy/common/system/outputcapture.py:
  • Scripts/webkitpy/common/system/outputtee_unittest.py:

(SimpleTeeTest.test_simple_tee):

  • Scripts/webkitpy/common/system/path.py:

(_escape): urllib library has been broken into parts.

  • Scripts/webkitpy/common/system/pemfile.py:

(_parse_pem_format.find_end): Python3 does not define a maxint.

  • Scripts/webkitpy/common/system/pemfile_unittest.py:
  • Scripts/webkitpy/common/system/platforminfo.py:

(PlatformInfo.total_bytes_memory): Not 'long' type in Python3.

  • Scripts/webkitpy/common/system/platforminfo_unittest.py:

(TestPlatformInfo.test_real_code): assertNotEquals -> assertNotEqual.
(TestPlatformInfo.test_display_name): Ditto.

  • Scripts/webkitpy/common/system/profiler.py:

(ProfilerFactory.create_profiler): Manually implement ifilter.

  • Scripts/webkitpy/common/system/profiler_unittest.py: Use absolute imports.
  • Scripts/webkitpy/common/system/stack_utils_unittest.py:

(current_thread_id): items() returns a generator in Python3.

  • Scripts/webkitpy/common/system/systemhost.py: Use absolute imports.
  • Scripts/webkitpy/common/system/urlfetcher.py: Removed.
  • Scripts/webkitpy/common/system/urlfetcher_mock.py: Removed.
  • Scripts/webkitpy/common/system/user.py:

(User.prompt): Use absolute imports, raw_input -> input.
(User.prompt_with_multiple_lists):
(User.prompt_with_list):
(User.confirm):

  • Scripts/webkitpy/common/unicode.py: Tooling to manage compatibility between Python 2

and Python 3 unicode handling.

  • Scripts/webkitpy/common/system/user_mock.py:

(MockUser.prompt): raw_input -> input.
(MockUser.prompt_with_list): Ditto.

  • Scripts/webkitpy/common/version.py:

(Version.from_iterable): xrange -> range.
(Version.from_name): Use absolute import path.
(Version.contains): xrange -> range.
(Version.str): xrange -> range.
(Version.cmp): amp is no longer an operator in Python3, but versions are comprised
Of integers, so subtraction has the same effect.
(Version):
(Version.eq): cmp operator is no longer respected, so we need to implement
each comparison.
(Version.ne): Ditto.
(Version.lt): Ditto.
(Version.le): Ditto.
(Version.gt): Ditto.
(Version.ge): Ditto.

  • Scripts/webkitpy/common/version_name_map.py:

(VersionNameMap._automap_to_major_version):
(VersionNameMap.to_name): xrange -> range.
(VersionNameMap.from_name): iteritems -> items.

  • Scripts/webkitpy/common/version_name_map_unittest.py: Use absolute imports.
  • Scripts/webkitpy/common/version_unittest.py: Ditto.
  • Scripts/webkitpy/common/wavediff.py:

(WaveDiff.init): StringIO -> BytesIO.

  • Scripts/webkitpy/port/init.py:

(outside):

Location:
trunk/Tools
Files:
1 added
2 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r250357 r250375  
     12019-09-25  Jonathan Bedard  <jbedard@apple.com>
     2
     3        Python 3: Add support in webkitpy.common.system
     4        https://bugs.webkit.org/show_bug.cgi?id=201826
     5        <rdar://problem/55452671>
     6
     7        Reviewed by Stephanie Lewis.
     8
     9        Tested compatibility by running 'python3 -m unittest webkitpy.common.system.<_unittest>' on
     10        each of the effected files.
     11
     12        * Scripts/webkitpy/common/checkout/changelog.py: Import StringIO from io module.
     13        (set_reviewer):
     14        (set_short_description_and_bug_url):
     15        * Scripts/webkitpy/common/checkout/checkout.py:  Import StringIO from io module.
     16        (Checkout._latest_entry_for_changelog_at_revision):
     17        * Scripts/webkitpy/common/config/committers.py:
     18        (CommitterList.load_json): iteritems -> items.
     19        * Scripts/webkitpy/common/net/networktransaction.py:
     20        (NetworkTransaction.run): urllib2 is urllib in Python3.
     21        * Scripts/webkitpy/common/system/abstractexecutive.py:
     22        (AbstractExecutive._stringify_args):
     23        (AbstractExecutive.command_for_printing): The str type is unicode in Python3.
     24        * Scripts/webkitpy/common/system/crashlogs_unittest.py: Explicitly encode and decode binary crashlogs.
     25        * Scripts/webkitpy/common/system/environment_unittest.py: Use absolute imports.
     26        * Scripts/webkitpy/common/system/executive.py:
     27        (ScriptError.message_with_output): The str type is unicode in Python3.
     28        (Executive.WrappedPopen): Python3's Popen object is a context manager. To allow us to use it as one,
     29        our Python2 Popen needs to be one as well.
     30        (Executive.WrappedPopen.__init__):
     31        (Executive.WrappedPopen.__enter__):
     32        (Executive.WrappedPopen.__exit__):
     33        (Executive._run_command_with_teed_output): Simplify loop, decode unicode strings.
     34        (Executive.run_and_throw_if_fail): The child output file should not be unicode strings.
     35        (Executive.running_pids): Use the Popen context manager to guarantee clean-up.
     36        (Executive._compute_stdin):
     37        (Executive.run_command): Use the Popen context manager to guarantee clean-up.
     38        (Executive._stringify_args): The str type is unicode in Python3.
     39        (Executive.popen): Return a context manager if the Popen object is not one.
     40        * Scripts/webkitpy/common/system/executive_mock.py:
     41        (MockProcess.__init__): StringIO -> BytesIO.
     42        (MockProcess.__enter__):
     43        (MockProcess):
     44        (MockProcess.__exit__):
     45        * Scripts/webkitpy/common/system/executive_unittest.py:
     46        (ExecutiveTest.test_auto_stringify_args): Use the Popen context manager to guarantee clean-up.
     47        (ExecutiveTest.test_popen_args): Ditto.
     48        (ExecutiveTest.serial_test_kill_process): Ditto.
     49        (ExecutiveTest.serial_test_kill_all): Ditto.
     50        * Scripts/webkitpy/common/system/filesystem.py:
     51        (FileSystem.read_binary_file): Use 'open' instead of 'file'.
     52        (FileSystem.write_binary_file): Ditto.
     53        (FileSystem.write_text_file): The str type is unicode in Python3.
     54        (FileSystem.relpath):
     55        (FileSystem.remove): The WindowsError is just anther OSError in Python3.
     56        (FileSystem._WindowsError): Deleted.
     57        * Scripts/webkitpy/common/system/filesystem_mock.py:
     58        (MockFileSystem.glob): filter returns a generator instead of a list.
     59        (WritableBinaryFileObject.__init__): Binary files are comprised of bytes, not string in Python3.
     60        (WritableBinaryFileObject.write): Ditto.
     61        (ReadableTextFileObject.__init__): Ditto.
     62        * Scripts/webkitpy/common/system/filesystem_mock_unittest.py:
     63        (MockFileSystemTest.test_normpath):
     64        (MockFileSystemTest.test_dirs_under): assertEquals -> assertEqual.
     65        * Scripts/webkitpy/common/system/filesystem_unittest.py:
     66        (RealFileSystemTest.test_read_and_write_file): Explicitly define byte arrays instead of strings.
     67        (RealFileSystemTest.test_remove_file_with_retry.remove_with_exception): The WindowsError is just
     68        anther OSError in Python3.
     69        * Scripts/webkitpy/common/system/outputcapture.py:
     70        * Scripts/webkitpy/common/system/outputtee_unittest.py:
     71        (SimpleTeeTest.test_simple_tee):
     72        * Scripts/webkitpy/common/system/path.py:
     73        (_escape): urllib library has been broken into parts.
     74        * Scripts/webkitpy/common/system/pemfile.py:
     75        (_parse_pem_format.find_end): Python3 does not define a maxint.
     76        * Scripts/webkitpy/common/system/pemfile_unittest.py:
     77        * Scripts/webkitpy/common/system/platforminfo.py:
     78        (PlatformInfo.total_bytes_memory): Not 'long' type in Python3.
     79        * Scripts/webkitpy/common/system/platforminfo_unittest.py:
     80        (TestPlatformInfo.test_real_code): assertNotEquals -> assertNotEqual.
     81        (TestPlatformInfo.test_display_name): Ditto.
     82        * Scripts/webkitpy/common/system/profiler.py:
     83        (ProfilerFactory.create_profiler): Manually implement ifilter.
     84        * Scripts/webkitpy/common/system/profiler_unittest.py: Use absolute imports.
     85        * Scripts/webkitpy/common/system/stack_utils_unittest.py:
     86        (current_thread_id): items() returns a generator in Python3.
     87        * Scripts/webkitpy/common/system/systemhost.py: Use absolute imports.
     88        * Scripts/webkitpy/common/system/urlfetcher.py: Removed.
     89        * Scripts/webkitpy/common/system/urlfetcher_mock.py: Removed.
     90        * Scripts/webkitpy/common/system/user.py:
     91        (User.prompt): Use absolute imports, raw_input -> input.
     92        (User.prompt_with_multiple_lists):
     93        (User.prompt_with_list):
     94        (User.confirm):
     95        * Scripts/webkitpy/common/unicode.py: Tooling to manage compatibility between Python 2
     96        and Python 3 unicode handling.
     97        * Scripts/webkitpy/common/system/user_mock.py:
     98        (MockUser.prompt): raw_input -> input.
     99        (MockUser.prompt_with_list): Ditto.
     100        * Scripts/webkitpy/common/version.py:
     101        (Version.from_iterable): xrange -> range.
     102        (Version.from_name): Use absolute import path.
     103        (Version.__contains__): xrange -> range.
     104        (Version.__str__): xrange -> range.
     105        (Version.__cmp__): amp is no longer an operator in Python3, but versions are comprised
     106        Of integers, so subtraction has the same effect.
     107        (Version):
     108        (Version.__eq__): __cmp__ operator is no longer respected, so we need to implement
     109        each comparison.
     110        (Version.__ne__): Ditto.
     111        (Version.__lt__): Ditto.
     112        (Version.__le__): Ditto.
     113        (Version.__gt__): Ditto.
     114        (Version.__ge__): Ditto.
     115        * Scripts/webkitpy/common/version_name_map.py:
     116        (VersionNameMap._automap_to_major_version):
     117        (VersionNameMap.to_name): xrange -> range.
     118        (VersionNameMap.from_name): iteritems -> items.
     119        * Scripts/webkitpy/common/version_name_map_unittest.py: Use absolute imports.
     120        * Scripts/webkitpy/common/version_unittest.py: Ditto.
     121        * Scripts/webkitpy/common/wavediff.py:
     122        (WaveDiff.__init__): StringIO -> BytesIO.
     123        * Scripts/webkitpy/port/__init__.py:
     124        (outside):
     125
    11262019-09-25  Aakash Jain  <aakash_jain@apple.com>
    2127
  • trunk/Tools/Scripts/webkitpy/common/checkout/changelog.py

    r234663 r250375  
    3131import logging
    3232import re
    33 from StringIO import StringIO
    3433import textwrap
    3534
    3635from webkitpy.common.config.committers import CommitterList
    3736from webkitpy.common.system.filesystem import FileSystem
     37from webkitpy.common.unicode_compatibility import StringIO
    3838import webkitpy.common.config.urls as config_urls
    3939
  • trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py

    r228303 r250375  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 import StringIO
    30 
    3129from webkitpy.common.config import urls
    3230from webkitpy.common.checkout.changelog import ChangeLog, parse_bug_id_from_changelog
     
    3533from webkitpy.common.memoized import memoized
    3634from webkitpy.common.system.executive import ScriptError
     35from webkitpy.common.unicode_compatibility import StringIO
    3736
    3837
     
    6261        # expects a file-like object which vends unicode(), so we decode here.
    6362        # Old revisions of Sources/WebKit/wx/ChangeLog have some invalid utf8 characters.
    64         changelog_file = StringIO.StringIO(changelog_contents.decode("utf-8", "ignore"))
     63        changelog_file = StringIO(changelog_contents.decode("utf-8", "ignore"))
    6564        return ChangeLog.parse_latest_entry_from_file(changelog_file)
    6665
  • trunk/Tools/Scripts/webkitpy/common/config/committers.py

    r225733 r250375  
    202202        self._reviewers = []
    203203
    204         for name, data in contributors.iteritems():
     204        for name, data in contributors.items():
    205205            contributor = None
    206206            status = data.get('status')
  • trunk/Tools/Scripts/webkitpy/common/net/networktransaction.py

    r229627 r250375  
    2828
    2929import logging
     30import sys
    3031import time
    31 import urllib2
     32
     33if sys.version_info > (3, 0):
     34    from urllib.error import HTTPError, URLError
     35else:
     36    from urllib2 import HTTPError, URLError
    3237
    3338_log = logging.getLogger(__name__)
     
    5257            try:
    5358                return request()
    54             except urllib2.HTTPError as e:
     59            except HTTPError as e:
    5560                if self._convert_404_to_None and e.code == 404:
    5661                    return None
     
    5863                _log.warn("Received HTTP status %s loading \"%s\".  Retrying in %s seconds..." % (e.code, e.filename, self._backoff_seconds))
    5964                self._sleep()
    60             except urllib2.URLError as e:
     65            except URLError as e:
    6166                self._check_for_timeout()
    6267                _log.warn('Received URLError: "{}" while loading {}. Retrying in {} seconds...'.format(e.reason, url, self._backoff_seconds))
  • trunk/Tools/Scripts/webkitpy/common/system/abstractexecutive.py

    r243373 r250375  
    2525
    2626from webkitpy.common.system.filesystem import FileSystem
    27 
     27from webkitpy.common import unicode_compatibility
    2828
    2929class AbstractExecutive(object):
     
    102102
    103103    def _stringify_args(self, args):
    104         return map(unicode, args)
     104        return map(unicode_compatibility.unicode, args)
    105105
    106106    def command_for_printing(self, args):
     
    108108        The string should be copy/paste ready for execution in a shell."""
    109109        args = self._stringify_args(args)
    110         escaped_args = []
    111         for arg in args:
    112             if isinstance(arg, unicode):
    113                 # Escape any non-ascii characters for easy copy/paste
    114                 arg = arg.encode("unicode_escape")
    115             # FIXME: Do we need to fix quotes here?
    116             escaped_args.append(arg)
    117         return " ".join(escaped_args)
     110        return unicode_compatibility.decode_if_necessary(unicode_compatibility.encode_if_necessary(' '.join(args), 'unicode_escape'))
    118111
    119112    def run_command(self, args, cwd=None, env=None, input=None, error_handler=None, ignore_errors=False,
  • trunk/Tools/Scripts/webkitpy/common/system/crashlogs.py

    r245544 r250375  
    3131import logging
    3232import re
     33
     34from webkitpy.common import unicode_compatibility
    3335
    3436
     
    110112            try:
    111113                if not newer_than or self._host.filesystem.mtime(path) > newer_than:
    112                     log_file = self._host.filesystem.read_binary_file(path).decode('ascii', 'ignore')
     114                    log_file = unicode_compatibility.decode_if_necessary(self._host.filesystem.read_binary_file(path), 'ascii', 'ignore')
    113115                    match = self.GLOBAL_PID_REGEX.search(log_file)
    114116                    if match:
  • trunk/Tools/Scripts/webkitpy/common/system/crashlogs_unittest.py

    r220708 r250375  
    2828from webkitpy.common.system.systemhost import SystemHost
    2929from webkitpy.common.system.systemhost_mock import MockSystemHost
    30 from webkitpy.thirdparty.mock import Mock
     30from webkitpy.common import unicode_compatibility
    3131
    3232# Needed to support Windows port tests
     
    299299        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = self.other_process_mock_crash_report
    300300        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = self.misformatted_mock_crash_report
     301
     302        self.files = {key: unicode_compatibility.encode_if_necessary(value) for key, value in self.files.items()}
     303
    301304        self.filesystem = MockFileSystem(self.files)
    302305        crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem), CrashLogsTest.DARWIN_MOCK_CRASH_DIRECTORY)
     
    314317        self.assertEqual(len(all_logs), 8)
    315318
    316         for test, crash_log in all_logs.iteritems():
    317             self.assertTrue(crash_log in self.files.values())
     319        for test, crash_log in all_logs.items():
     320            self.assertTrue(crash_log in [unicode_compatibility.decode_if_necessary(value) for value in self.files.values()])
    318321            if test.split('-')[0] != 'Sandbox':
    319322                self.assertTrue(test == "Unknown" or int(test.split("-")[1]) in range(28527, 28531))
  • trunk/Tools/Scripts/webkitpy/common/system/environment_unittest.py

    r221926 r250375  
    2929import unittest
    3030
    31 from .environment import Environment
     31from webkitpy.common.system.environment import Environment
    3232
    3333
  • trunk/Tools/Scripts/webkitpy/common/system/executive.py

    r243373 r250375  
    2828# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2929
    30 import StringIO
    3130import errno
    3231import logging
     
    4039from webkitpy.common.system.abstractexecutive import AbstractExecutive
    4140from webkitpy.common.system.outputtee import Tee
     41from webkitpy.common import unicode_compatibility
    4242
    4343
     
    7272                    (self, output_limit, self.output[-output_limit:])
    7373            return u"%s\n\n%s" % (self, self.output)
    74         return unicode(self)
     74        return unicode_compatibility.unicode(self)
    7575
    7676    def command_name(self):
     
    8484    PIPE = subprocess.PIPE
    8585    STDOUT = subprocess.STDOUT
     86
     87    class WrappedPopen(object):
     88        def __init__(self, popen):
     89            for attribute in dir(popen):
     90                if attribute.startswith('__'):
     91                    continue
     92                setattr(self, attribute, getattr(popen, attribute))
     93
     94        def __enter__(self):
     95            return self
     96
     97        def __exit__(self, *args):
     98            self.wait()
    8699
    87100    def __init__(self):
     
    109122                                   **kwargs)
    110123
    111         # Use our own custom wait loop because Popen ignores a tee'd
    112         # stderr/stdout.
    113         # FIXME: This could be improved not to flatten output to stdout.
    114         while True:
    115             output_line = child_process.stdout.readline()
    116             if output_line == "" and child_process.poll() != None:
    117                 # poll() is not threadsafe and can throw OSError due to:
    118                 # http://bugs.python.org/issue1731717
    119                 return child_process.poll()
    120             # We assume that the child process wrote to us in utf-8,
    121             # so no re-encoding is necessary before writing here.
    122             teed_output.write(output_line)
     124        with child_process:
     125            # Use our own custom wait loop because Popen ignores a tee'd
     126            # stderr/stdout.
     127            # FIXME: This could be improved not to flatten output to stdout.
     128            while child_process.poll() is None:
     129                output_line = child_process.stdout.readline()
     130                teed_output.write(unicode_compatibility.decode_for(output_line, str))
    123131
    124132    # FIXME: Remove this deprecated method and move callers to run_command.
     
    129137    def run_and_throw_if_fail(self, args, quiet=False, decode_output=True, **kwargs):
    130138        # Cache the child's output locally so it can be used for error reports.
    131         child_out_file = StringIO.StringIO()
     139        child_out_file = unicode_compatibility.StringIO()
    132140        tee_stdout = sys.stdout
    133         if quiet:
    134             dev_null = open(os.devnull, "w")  # FIXME: Does this need an encoding?
    135             tee_stdout = dev_null
    136         child_stdout = Tee(child_out_file, tee_stdout)
    137         exit_code = self._run_command_with_teed_output(args, child_stdout, **kwargs)
    138         if quiet:
    139             dev_null.close()
     141        try:
     142            if quiet:
     143                dev_null = open(os.devnull, "w")  # FIXME: Does this need an encoding?
     144                tee_stdout = dev_null
     145            child_stdout = Tee(child_out_file, tee_stdout)
     146            exit_code = self._run_command_with_teed_output(args, child_stdout, **kwargs)
     147        finally:
     148            if quiet:
     149                dev_null.close()
    140150
    141151        child_output = child_out_file.getvalue()
     
    143153
    144154        if decode_output:
    145             child_output = child_output.decode(self._child_process_encoding())
     155            child_output = unicode_compatibility.decode_if_necessary(child_output, self._child_process_encoding())
     156        else:
     157            child_output = unicode_compatibility.encode_if_necessary(child_output, self._child_process_encoding())
    146158
    147159        if exit_code:
     
    287299                    pass
    288300        else:
    289             ps_process = self.popen(['ps', '-eo', 'pid,comm'], stdout=self.PIPE, stderr=self.PIPE)
    290             stdout, _ = ps_process.communicate()
    291             for line in stdout.splitlines():
    292                 try:
    293                     # In some cases the line can contain one or more
    294                     # leading white-spaces, so strip it before split.
    295                     pid, process_name = line.strip().split(' ', 1)
    296                     if process_name_filter(process_name):
    297                         running_pids.append(int(pid))
    298                 except ValueError as e:
    299                     pass
     301            with self.popen(['ps', '-eo', 'pid,comm'], stdout=self.PIPE, stderr=self.PIPE) as ps_process:
     302                stdout, _ = ps_process.communicate()
     303                for line in stdout.splitlines():
     304                    try:
     305                        # In some cases the line can contain one or more
     306                        # leading white-spaces, so strip it before split.
     307                        pid, process_name = line.strip().split(' ', 1)
     308                        if process_name_filter(process_name):
     309                            running_pids.append(int(pid))
     310                    except ValueError as e:
     311                        pass
    300312
    301313        return sorted(running_pids)
     
    356368        # for an example of a regresion caused by passing a unicode string directly.
    357369        # FIXME: We may need to encode differently on different platforms.
    358         if isinstance(input, unicode):
    359             input = input.encode(self._child_process_encoding())
     370        input = unicode_compatibility.encode_if_necessary(input, self._child_process_encoding())
    360371        return (self.PIPE, input)
    361372
     
    385396                             env=env,
    386397                             close_fds=self._should_close_fds())
    387         output = process.communicate(string_to_communicate)[0]
    388 
    389         # run_command automatically decodes to unicode() and converts CRLF to LF unless explicitly told not to.
    390         if decode_output:
    391             output = output.decode(self._child_process_encoding()).replace('\r\n', '\n')
    392 
    393         # wait() is not threadsafe and can throw OSError due to:
    394         # http://bugs.python.org/issue1731717
    395         exit_code = process.wait()
    396 
    397         _log.debug('"%s" took %.2fs' % (self.command_for_printing(args), time.time() - start_time))
    398 
    399         if return_exit_code:
    400             return exit_code
    401 
    402         if exit_code:
    403             script_error = ScriptError(script_args=args,
    404                                        exit_code=exit_code,
    405                                        output=output,
    406                                        cwd=cwd)
    407 
    408             if ignore_errors:
    409                 assert error_handler is None, "don't specify error_handler if ignore_errors is True"
    410                 error_handler = Executive.ignore_error
    411 
    412             (error_handler or self.default_error_handler)(script_error)
    413         return output
     398        with process:
     399            if not string_to_communicate:
     400                output = process.communicate()[0]
     401            else:
     402                output = process.communicate(unicode_compatibility.encode_if_necessary(string_to_communicate, 'utf-8'))[0]
     403
     404            # run_command automatically decodes to unicode() and converts CRLF to LF unless explicitly told not to.
     405            if decode_output:
     406                output = unicode_compatibility.decode_if_necessary(output, self._child_process_encoding()).replace('\r\n', '\n')
     407
     408            # wait() is not threadsafe and can throw OSError due to:
     409            # http://bugs.python.org/issue1731717
     410            exit_code = process.wait()
     411
     412            _log.debug('"%s" took %.2fs' % (self.command_for_printing(args), time.time() - start_time))
     413
     414            if return_exit_code:
     415                return exit_code
     416
     417            if exit_code:
     418                script_error = ScriptError(script_args=args,
     419                                           exit_code=exit_code,
     420                                           output=output,
     421                                           cwd=cwd)
     422
     423                if ignore_errors:
     424                    assert error_handler is None, "don't specify error_handler if ignore_errors is True"
     425                    error_handler = Executive.ignore_error
     426
     427                (error_handler or self.default_error_handler)(script_error)
     428            return output
    414429
    415430    def _child_process_encoding(self):
     
    442457        if not self._should_encode_child_process_arguments():
    443458            return argument
    444         return argument.encode(self._child_process_encoding())
     459        return unicode_compatibility.encode_if_necessary(argument, self._child_process_encoding())
    445460
    446461    def _stringify_args(self, args):
    447462        # Popen will throw an exception if args are non-strings (like int())
    448         string_args = map(unicode, args)
     463        string_args = map(unicode_compatibility.unicode, args)
    449464        # The Windows implementation of Popen cannot handle unicode strings. :(
    450465        return map(self._encode_argument_if_needed, string_args)
     
    479494        else:
    480495            string_args = self._stringify_args(args)
    481         return subprocess.Popen(string_args, **kwargs)
     496
     497        # Python 3 treats Popen as a context manager, we should allow this in Python 2
     498        result = subprocess.Popen(string_args, **kwargs)
     499        if not callable(getattr(result, "__enter__", None)) and not callable(getattr(result, "__exit__", None)):
     500            return self.WrappedPopen(result)
     501        return result
    482502
    483503    def run_in_parallel(self, command_lines_and_cwds, processes=None):
  • trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py

    r243373 r250375  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 import StringIO
    3029import logging
    3130import os
    3231
     32from webkitpy.common.unicode_compatibility import BytesIO, unicode
    3333from webkitpy.common.system.executive import ScriptError
    3434
     
    3939    def __init__(self, stdout='MOCK STDOUT\n', stderr=''):
    4040        self.pid = 42
    41         self.stdout = StringIO.StringIO(stdout)
    42         self.stderr = StringIO.StringIO(stderr)
    43         self.stdin = StringIO.StringIO()
     41        self.stdout = BytesIO(stdout)
     42        self.stderr = BytesIO(stderr)
     43        self.stdin = BytesIO()
    4444        self.returncode = 0
    4545        self._is_running = False
     
    5757            return None
    5858        return self.returncode
     59
     60    def __enter__(self):
     61        return self
     62
     63    def __exit__(self, *args):
     64        self.wait()
    5965
    6066
  • trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py

    r243373 r250375  
    4747from webkitpy.common.system.executive import Executive, ScriptError
    4848from webkitpy.common.system.filesystem_mock import MockFileSystem
     49from webkitpy.common import unicode_compatibility
    4950
    5051
     
    119120        executive = Executive()
    120121        executive.run_command(command_line('echo', 1))
    121         executive.popen(command_line('echo', 1), stdout=executive.PIPE).wait()
    122         self.assertEqual('echo 1', executive.command_for_printing(['echo', 1]))
     122        with executive.popen(command_line('echo', 1), stdout=executive.PIPE) as process:
     123            process.wait()
     124            self.assertEqual('echo 1', executive.command_for_printing(['echo', 1]))
    123125
    124126    def test_popen_args(self):
    125127        executive = Executive()
    126128        # Explicitly naming the 'args' argument should not thow an exception.
    127         executive.popen(args=command_line('echo', 1), stdout=executive.PIPE).wait()
     129        with executive.popen(args=command_line('echo', 1), stdout=executive.PIPE) as process:
     130            process.wait()
    128131
    129132    def test_run_command_with_unicode(self):
     
    136139        else:
    137140            encoding = 'utf-8'
    138         encoded_tor = unicode_tor_input.encode(encoding)
     141        encoded_tor = unicode_compatibility.encode_if_necessary(unicode_tor_input, encoding)
    139142        # On Windows, we expect the unicode->mbcs->unicode roundtrip to be
    140143        # lossy. On other platforms, we expect a lossless roundtrip.
    141144        if sys.platform.startswith('win'):
    142             unicode_tor_output = encoded_tor.decode(encoding)
     145            unicode_tor_output = unicode_compatibility.decode_if_necessary(encoded_tor, encoding)
    143146        else:
    144147            unicode_tor_output = unicode_tor_input
     
    168171    def serial_test_kill_process(self):
    169172        executive = Executive()
    170         process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIPE)
    171         self.assertEqual(process.poll(), None)  # Process is running
    172         executive.kill_process(process.pid)
    173         # Note: Can't use a ternary since signal.SIGKILL is undefined for sys.platform == "win32"
    174         if sys.platform.startswith('win'):
    175             # FIXME: https://bugs.webkit.org/show_bug.cgi?id=54790
    176             # We seem to get either 0 or 1 here for some reason.
    177             self.assertIn(process.wait(), (0, 1))
    178         elif sys.platform == "cygwin":
    179             # FIXME: https://bugs.webkit.org/show_bug.cgi?id=98196
    180             # cygwin seems to give us either SIGABRT or SIGKILL
    181             # Native Windows (via Cygwin) returns ENOTBLK (-15)
    182             self.assertIn(process.wait(), (-signal.SIGABRT, -signal.SIGKILL, -15))
    183         else:
    184             expected_exit_code = -signal.SIGTERM
    185             self.assertEqual(process.wait(), expected_exit_code)
    186 
    187         # Killing again should fail silently.
    188         executive.kill_process(process.pid)
     173        with executive.popen(never_ending_command(), stdout=subprocess.PIPE) as process:
     174            self.assertEqual(process.poll(), None)  # Process is running
     175            executive.kill_process(process.pid)
     176            # Note: Can't use a ternary since signal.SIGKILL is undefined for sys.platform == "win32"
     177            if sys.platform.startswith('win'):
     178                # FIXME: https://bugs.webkit.org/show_bug.cgi?id=54790
     179                # We seem to get either 0 or 1 here for some reason.
     180                self.assertIn(process.wait(), (0, 1))
     181            elif sys.platform == "cygwin":
     182                # FIXME: https://bugs.webkit.org/show_bug.cgi?id=98196
     183                # cygwin seems to give us either SIGABRT or SIGKILL
     184                # Native Windows (via Cygwin) returns ENOTBLK (-15)
     185                self.assertIn(process.wait(), (-signal.SIGABRT, -signal.SIGKILL, -15))
     186            else:
     187                expected_exit_code = -signal.SIGTERM
     188                self.assertEqual(process.wait(), expected_exit_code)
     189
     190            # Killing again should fail silently.
     191            executive.kill_process(process.pid)
    189192
    190193    def serial_test_kill_all(self):
    191194        executive = Executive()
    192         process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIPE)
    193         self.assertIsNone(process.poll())  # Process is running
    194         executive.kill_all(never_ending_command()[0])
    195         # Note: Can't use a ternary since signal.SIGTERM is undefined for sys.platform == "win32"
    196         if sys.platform == "cygwin":
    197             expected_exit_code = 0  # os.kill results in exit(0) for this process.
    198             self.assertEqual(process.wait(), expected_exit_code)
    199         elif sys.platform.startswith('win'):
    200             # FIXME: https://bugs.webkit.org/show_bug.cgi?id=54790
    201             # We seem to get either 0 or 1 here for some reason.
    202             self.assertIn(process.wait(), (0, 1))
    203         else:
    204             expected_exit_code = -signal.SIGTERM
    205             self.assertEqual(process.wait(), expected_exit_code)
    206         # Killing again should fail silently.
    207         executive.kill_all(never_ending_command()[0])
     195        with executive.popen(never_ending_command(), stdout=subprocess.PIPE) as process:
     196            self.assertIsNone(process.poll())  # Process is running
     197            executive.kill_all(never_ending_command()[0])
     198            # Note: Can't use a ternary since signal.SIGTERM is undefined for sys.platform == "win32"
     199            if sys.platform == "cygwin":
     200                expected_exit_code = 0  # os.kill results in exit(0) for this process.
     201                self.assertEqual(process.wait(), expected_exit_code)
     202            elif sys.platform.startswith('win'):
     203                # FIXME: https://bugs.webkit.org/show_bug.cgi?id=54790
     204                # We seem to get either 0 or 1 here for some reason.
     205                self.assertIn(process.wait(), (0, 1))
     206            else:
     207                expected_exit_code = -signal.SIGTERM
     208                self.assertEqual(process.wait(), expected_exit_code)
     209            # Killing again should fail silently.
     210            executive.kill_all(never_ending_command()[0])
    208211
    209212    def _assert_windows_image_name(self, name, expected_windows_name):
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem.py

    r229781 r250375  
    3131import codecs
    3232import errno
    33 import exceptions
    3433import filecmp
    3534import glob
     
    4039import tempfile
    4140import time
     41
     42from webkitpy.common.unicode_compatibility import decode_if_necessary
    4243
    4344
     
    222223    def read_binary_file(self, path):
    223224        """Return the contents of the file at the given path as a byte string."""
    224         with file(path, 'rb') as f:
     225        with open(path, 'rb') as f:
    225226            return f.read()
    226227
    227228    def write_binary_file(self, path, contents):
    228         with file(path, 'wb') as f:
     229        with open(path, 'wb') as f:
    229230            f.write(contents)
    230231
     
    257258        The file is written encoded as UTF-8 with no BOM."""
    258259        with codecs.open(path, 'w', 'utf-8', errors=errors) as f:
    259             f.write(contents.decode('utf-8', errors=errors) if type(contents) == str else contents)
     260            f.write(decode_if_necessary(contents, errors=errors))
    260261
    261262    def sha1(self, path):
     
    265266    def relpath(self, path, start='.'):
    266267        return os.path.relpath(path, start)
    267 
    268     class _WindowsError(exceptions.OSError):
    269         """Fake exception for Linux and Mac."""
    270         pass
    271268
    272269    def remove(self, path, osremove=os.remove):
     
    276273        will retry for a few seconds until Windows is done with the file."""
    277274        try:
    278             exceptions.WindowsError
    279         except AttributeError:
    280             exceptions.WindowsError = FileSystem._WindowsError
     275            WinOSError = WindowsError
     276        except NameError:
     277            WinOSError = OSError
    281278
    282279        retry_timeout_sec = 3.0
     
    286283                osremove(path)
    287284                return True
    288             except exceptions.WindowsError as e:
     285            except WinOSError as e:
    289286                time.sleep(sleep_interval)
    290287                retry_timeout_sec -= sleep_interval
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py

    r220150 r250375  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 import StringIO
    3029import errno
    3130import hashlib
    3231import os
    3332import re
    34 
     33import sys
     34
     35from webkitpy.common import unicode_compatibility
    3536from webkitpy.common.system import path
    36 
    3737
    3838class MockFileSystem(object):
     
    187187        # We could use fnmatch.fnmatch, but that might not do the right thing on windows.
    188188        existing_files = [path for path, contents in self.files.items() if contents is not None]
    189         return filter(path_filter, existing_files) + filter(path_filter, self.dirs)
     189        return list(filter(path_filter, existing_files)) + list(filter(path_filter, self.dirs))
    190190
    191191    def isabs(self, path):
     
    345345
    346346    def write_text_file(self, path, contents, errors='strict'):
    347         return self.write_binary_file(path, contents.encode('utf-8', errors=errors))
     347        return self.write_binary_file(path, unicode_compatibility.encode_if_necessary(contents, 'utf-8', errors=errors))
    348348
    349349    def sha1(self, path):
     
    442442        self.path = path
    443443        self.closed = False
    444         self.fs.files[path] = ""
     444        self.fs.files[path] = b''
    445445
    446446    def __enter__(self):
     
    453453        self.closed = True
    454454
    455     def write(self, str):
    456         self.fs.files[self.path] += str
     455    def write(self, string):
     456        self.fs.files[self.path] += unicode_compatibility.encode_if_necessary(string, 'utf-8')
    457457        self.fs.written_files[self.path] = self.fs.files[self.path]
    458458
     
    460460class WritableTextFileObject(WritableBinaryFileObject):
    461461    def write(self, str):
    462         WritableBinaryFileObject.write(self, str.encode('utf-8'))
     462        WritableBinaryFileObject.write(self, unicode_compatibility.encode_if_necessary(str, 'utf-8'))
    463463
    464464
     
    490490class ReadableTextFileObject(ReadableBinaryFileObject):
    491491    def __init__(self, fs, path, data):
    492         super(ReadableTextFileObject, self).__init__(fs, path, StringIO.StringIO(data.decode("utf-8")))
     492        super(ReadableTextFileObject, self).__init__(fs, path, unicode_compatibility.UnicodeIO(unicode_compatibility.decode_for(data, unicode_compatibility.unicode)))
    493493
    494494    def close(self):
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock_unittest.py

    r181014 r250375  
    7171        self.quick_check(self.fs.normpath,
    7272                         self.fs._slow_but_correct_normpath,
    73                          '',
    74                          '/',
    75                          '.',
    76                          '/.',
    77                          'foo',
    78                          'foo/',
    79                          'foo/.',
    80                          'foo/bar',
    81                          '/foo',
    82                          'foo/../bar',
    83                          'foo/../bar/baz',
    84                          '../foo')
     73                         ('',),
     74                         ('/',),
     75                         ('.',),
     76                         ('/.',),
     77                         ('foo',),
     78                         ('foo/',),
     79                         ('foo/.',),
     80                         ('foo/bar',),
     81                         ('/foo',),
     82                         ('foo/../bar',),
     83                         ('foo/../bar/baz',),
     84                         ('../foo',))
    8585
    8686    def test_dirs_under(self):
     
    9191        fs = filesystem_mock.MockFileSystem(files=FAKE_FILES)
    9292
    93         self.assertEquals(fs.dirs_under('/tests'), ['/tests', '/tests/test2', '/tests/test3', '/tests/test3/test2'])
     93        self.assertEqual(fs.dirs_under('/tests'), ['/tests', '/tests/test2', '/tests/test3', '/tests/test3/test2'])
    9494
    9595        def filter_dir(fs, dirpath):
    9696            return fs.basename(dirpath) != 'test2'
    9797
    98         self.assertEquals(fs.dirs_under('/tests', filter_dir), ['/tests', '/tests/test3'])
     98        self.assertEqual(fs.dirs_under('/tests', filter_dir), ['/tests', '/tests/test3'])
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py

    r220150 r250375  
    3838import unittest
    3939
    40 from filesystem import FileSystem
     40from webkitpy.common.system.filesystem import FileSystem
    4141
    4242
     
    268268
    269269        unicode_text_string = u'\u016An\u012Dc\u014Dde\u033D'
    270         hex_equivalent = '\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD'
    271         malformed_text_hex = '\x4D\x69\x63\x72\x6F\x73\x6F\x66\x74\xAE\x20\x56\x69\x73\x75\x61\x6C\x20\x53\x74\x75\x64\x69\x6F\xAE\x20\x32\x30\x31\x30\x0D\x0A'
    272         malformed_ignored_text_hex = '\x4D\x69\x63\x72\x6F\x73\x6F\x66\x74\x20\x56\x69\x73\x75\x61\x6C\x20\x53\x74\x75\x64\x69\x6F\x20\x32\x30\x31\x30\x0D\x0A'
     270        hex_equivalent = b'\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD'
     271        malformed_text_hex = b'\x4D\x69\x63\x72\x6F\x73\x6F\x66\x74\xAE\x20\x56\x69\x73\x75\x61\x6C\x20\x53\x74\x75\x64\x69\x6F\xAE\x20\x32\x30\x31\x30\x0D\x0A'
     272        malformed_ignored_text_hex = b'\x4D\x69\x63\x72\x6F\x73\x6F\x66\x74\x20\x56\x69\x73\x75\x61\x6C\x20\x53\x74\x75\x64\x69\x6F\x20\x32\x30\x31\x30\x0D\x0A'
    273273        try:
    274274            text_path = tempfile.mktemp(prefix='tree_unittest_')
     
    286286            self.assertRaises(ValueError, fs.read_text_file, binary_path)
    287287            text_contents = fs.read_binary_file(binary_path).decode('utf8', 'ignore')
    288             self.assertEquals(text_contents, malformed_ignored_text_hex)
    289             fs.open_text_file_for_reading(binary_path, 'replace').readline()
     288            self.assertEqual(text_contents, malformed_ignored_text_hex.decode('utf8', 'ignore'))
     289            with fs.open_text_file_for_reading(binary_path, 'replace') as file:
     290                file.readline()
    290291
    291292        finally:
     
    312313                    raise WindowsError
    313314                except NameError:
    314                     raise FileSystem._WindowsError
     315                    raise OSError
    315316
    316317        fs = FileSystem()
  • trunk/Tools/Scripts/webkitpy/common/system/outputcapture.py

    r226736 r250375  
    3232import sys
    3333import unittest
    34 from StringIO import StringIO
     34
     35from webkitpy.common.unicode_compatibility import StringIO
    3536
    3637
  • trunk/Tools/Scripts/webkitpy/common/system/outputtee_unittest.py

    r174136 r250375  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 import StringIO
    3029import unittest
    3130
    3231from webkitpy.common.system.outputtee import Tee, OutputTee
     32from webkitpy.common.unicode_compatibility import StringIO
    3333
    3434
    3535class SimpleTeeTest(unittest.TestCase):
    3636    def test_simple_tee(self):
    37         file1, file2 = StringIO.StringIO(), StringIO.StringIO()
     37        file1, file2 = StringIO(), StringIO()
    3838        tee = Tee(file1, file2)
    3939        tee.write("foo bar\n")
  • trunk/Tools/Scripts/webkitpy/common/system/path.py

    r204408 r250375  
    3636import logging
    3737import threading
    38 import urllib
     38
     39if sys.version_info > (3, 0):
     40    from urllib.parse import quote as urllib_quote
     41else:
     42    from urllib import quote as urllib_quote
    3943
    4044_log = logging.getLogger(__name__)
     
    147151    # rules, we allow a small list of other characters through un-escaped.
    148152    # It's unclear if this is the best possible solution.
    149     return urllib.quote(path, safe='/+:')
     153    return urllib_quote(path, safe='/+:')
    150154
    151155
  • trunk/Tools/Scripts/webkitpy/common/system/pemfile.py

    r237727 r250375  
    123123        try:
    124124            index = lines.index(end_marker)
    125         except ValueError, e:
     125        except ValueError:
    126126            raise BadFormatError("Cannot find section end: {}".format(end_marker))
    127127
  • trunk/Tools/Scripts/webkitpy/common/system/pemfile_unittest.py

    r237727 r250375  
    2424
    2525import unittest
    26 import sys
    2726
    2827from webkitpy.common.system.pemfile import Pem, BadFormatError
     28from webkitpy.common.system.platforminfo import PlatformInfo
    2929
    3030
     
    158158    lines = docstring.expandtabs().splitlines()
    159159    # Determine minimum indentation (first line doesn't count):
    160     indent = sys.maxint
     160    indent = PlatformInfo.MAX
    161161    for line in lines[1:]:
    162162        stripped = line.lstrip()
     
    165165    # Remove indentation (first line is special):
    166166    trimmed = [lines[0].strip()]
    167     if indent < sys.maxint:
     167    if indent < PlatformInfo.MAX:
    168168        for line in lines[1:]:
    169169            trimmed.append(line[indent:].rstrip())
  • trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py

    r243030 r250375  
    3737
    3838class PlatformInfo(object):
     39    MAX = 2147483647
     40
    3941    """This class provides a consistent (and mockable) interpretation of
    4042    system-specific values (like sys.platform and platform.mac_ver())
     
    119121    def total_bytes_memory(self):
    120122        if self.is_mac():
    121             return long(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
     123            return int(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
    122124        return None
    123125
    124126    def terminal_width(self):
    125         """Returns sys.maxint if the width cannot be determined."""
     127        """Returns MAX if the width cannot be determined."""
    126128        try:
    127129            if self.is_win():
     
    136138                    # automatically performs a line feed.
    137139                    return right - left
    138                 return sys.maxint
     140                return self.MAX
    139141            else:
    140142                import fcntl
     
    145147                return columns
    146148        except:
    147             return sys.maxint
     149            return self.MAX
    148150
    149151    def build_version(self):
  • trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py

    r237836 r250375  
    7777        # This test makes sure the real (unmocked) code actually works.
    7878        info = PlatformInfo(sys, platform, Executive())
    79         self.assertNotEquals(info.os_name, '')
     79        self.assertNotEqual(info.os_name, '')
    8080        if info.is_mac() or info.is_win():
    8181            self.assertIsNotNone(info.os_version)
    82         self.assertNotEquals(info.display_name(), '')
     82        self.assertNotEqual(info.display_name(), '')
    8383        self.assertTrue(info.is_mac() or info.is_win() or info.is_linux() or info.is_freebsd())
    8484        self.assertIsNotNone(info.terminal_width())
     
    136136    def test_display_name(self):
    137137        info = self.make_info(fake_sys('darwin'))
    138         self.assertNotEquals(info.display_name(), '')
     138        self.assertNotEqual(info.display_name(), '')
    139139
    140140        info = self.make_info(fake_sys('win32'), fake_platform(win_version_string='6.1.7600'))
    141         self.assertNotEquals(info.display_name(), '')
     141        self.assertNotEqual(info.display_name(), '')
    142142
    143143        info = self.make_info(fake_sys('linux2'), fake_platform('', '10.4'))
    144         self.assertNotEquals(info.display_name(), '')
     144        self.assertNotEqual(info.display_name(), '')
    145145
    146146        info = self.make_info(fake_sys('freebsd9'), fake_platform('', '9.0-RELEASE'))
    147         self.assertNotEquals(info.display_name(), '')
     147        self.assertNotEqual(info.display_name(), '')
    148148
    149149    def test_total_bytes_memory(self):
  • trunk/Tools/Scripts/webkitpy/common/system/profiler.py

    r225724 r250375  
    3030import logging
    3131import re
    32 import itertools
     32import sys
     33
     34if sys.version_info < (3, 0):
     35    from itertools import ifilter  as filter
    3336
    3437_log = logging.getLogger(__name__)
     
    4245            return None
    4346        profiler_name = profiler_name or cls.default_profiler_name(host.platform)
    44         profiler_class = next(itertools.ifilter(lambda profiler: profiler.name == profiler_name, profilers), None)
     47        profiler_class = next(filter(lambda profiler: profiler.name == profiler_name, profilers), None)
    4548        if not profiler_class:
    4649            return None
  • trunk/Tools/Scripts/webkitpy/common/system/profiler_unittest.py

    r174136 r250375  
    3232from webkitpy.common.system.systemhost_mock import MockSystemHost
    3333
    34 from .profiler import ProfilerFactory, GooglePProf
     34from webkitpy.common.system.profiler import ProfilerFactory, GooglePProf
    3535
    3636
  • trunk/Tools/Scripts/webkitpy/common/system/stack_utils_unittest.py

    r174136 r250375  
    3535
    3636def current_thread_id():
    37     thread_id, _ = sys._current_frames().items()[0]
    38     return thread_id
     37    for thread_id in sys._current_frames().keys():
     38        return thread_id
     39    return None
    3940
    4041
  • trunk/Tools/Scripts/webkitpy/common/system/systemhost.py

    r247228 r250375  
    3232import sys
    3333
    34 from . import environment, executive, file_lock, filesystem, platforminfo, user, workspace
     34from webkitpy.common.system import environment, executive, file_lock, filesystem, platforminfo, user, workspace
    3535
    3636
  • trunk/Tools/Scripts/webkitpy/common/system/user.py

    r233332 r250375  
    3737import webbrowser
    3838
    39 from .executive import Executive
    40 from .platforminfo import PlatformInfo
     39from webkitpy.common.system.executive import Executive
     40from webkitpy.common.system.platforminfo import PlatformInfo
    4141
    4242
     
    5050        # There is no readline module for win32, not much to do except cry.
    5151        _log.warn("Unable to import readline.")
     52
     53if sys.version_info > (3, 0):
     54    input_func = input
     55else:
     56    input_func = raw_input
    5257
    5358
     
    6368    # FIXME: These are @classmethods because bugzilla.py doesn't have a Tool object (thus no User instance).
    6469    @classmethod
    65     def prompt(cls, message, repeat=1, raw_input=raw_input):
     70    def prompt(cls, message, repeat=1, raw_input=input_func):
    6671        response = None
    6772        while (repeat and not response):
     
    7580
    7681    @classmethod
    77     def prompt_with_multiple_lists(cls, list_title, subtitles, lists, can_choose_multiple=False, raw_input=raw_input):
     82    def prompt_with_multiple_lists(cls, list_title, subtitles, lists, can_choose_multiple=False, raw_input=input_func):
    7883        item_index = 0
    7984        cumulated_list = []
     
    115120
    116121    @classmethod
    117     def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=raw_input):
     122    def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=input_func):
    118123        print(list_title)
    119124        i = 0
     
    157162            pass
    158163
    159     def confirm(self, message=None, default=DEFAULT_YES, raw_input=raw_input):
     164    def confirm(self, message=None, default=DEFAULT_YES, raw_input=input_func):
    160165        if not message:
    161166            message = "Continue?"
  • trunk/Tools/Scripts/webkitpy/common/system/user_mock.py

    r135912 r250375  
    2828
    2929import logging
     30import sys
    3031
    3132_log = logging.getLogger(__name__)
     33
     34if sys.version_info < (3, 0):
     35    input = raw_input
    3236
    3337
     
    3539
    3640    @classmethod
    37     def prompt(cls, message, repeat=1, raw_input=raw_input):
     41    def prompt(cls, message, repeat=1, raw_input=input):
    3842        return "Mock user response"
    3943
    4044    @classmethod
    41     def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=raw_input):
     45    def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=input):
    4246        pass
    4347
  • trunk/Tools/Scripts/webkitpy/common/version.py

    r225953 r250375  
    3434    def from_iterable(val):
    3535        result = Version()
    36         for i in xrange(len(val)):
     36        for i in range(len(val)):
    3737            result[i] = int(val[i])
    3838        return result
     
    4040    @staticmethod
    4141    def from_name(name):
    42         from version_name_map import VersionNameMap
     42        from webkitpy.common.version_name_map import VersionNameMap
    4343        return VersionNameMap.map().from_name(name)[1]
    4444
     
    100100        assert isinstance(version, Version)
    101101        does_match = True
    102         for i in xrange(len(version)):
     102        for i in range(len(version)):
    103103            if self[i] != version[i]:
    104104                does_match = False
     
    109109    def __str__(self):
    110110        len_to_print = 1
    111         for i in xrange(len(self)):
     111        for i in range(len(self)):
    112112            if self[i]:
    113113                len_to_print = i + 1
    114114        result = str(self.major)
    115         for i in xrange(len_to_print - 1):
     115        for i in range(len_to_print - 1):
    116116            result += '.{}'.format(self[i + 1])
    117117        return result
     
    120120        if other is None:
    121121            return 1
    122         for i in xrange(len(self)):
    123             if cmp(self[i], other[i]):
    124                 return cmp(self[i], other[i])
     122        for i in range(len(self)):
     123            diff = self[i] - other[i]
     124            if diff:
     125                return diff
    125126        return 0
     127
     128    def __eq__(self, other):
     129        return self.__cmp__(other) == 0
     130
     131    def __ne__(self, other):
     132        return self.__cmp__(other) != 0
     133
     134    def __lt__(self, other):
     135        return self.__cmp__(other) < 0
     136
     137    def __le__(self, other):
     138        return self.__cmp__(other) <= 0
     139
     140    def __gt__(self, other):
     141        return self.__cmp__(other) > 0
     142
     143    def __ge__(self, other):
     144        return self.__cmp__(other) >= 0
  • trunk/Tools/Scripts/webkitpy/common/version_name_map.py

    r250121 r250375  
    9191        result = {}
    9292        assert minimum <= maximum
    93         for i in xrange((maximum.major + 1) - minimum.major):
     93        for i in range((maximum.major + 1) - minimum.major):
    9494            result['{} {}'.format(prefix, str(Version(minimum.major + i)))] = Version(minimum.major + i)
    9595        return result
     
    9797    def to_name(self, version, platform=None, table=PUBLIC_TABLE):
    9898        closest_match = (None, None)
    99         for os_name, os_version in self.mapping_for_platform(platform, table).iteritems():
     99        for os_name, os_version in self.mapping_for_platform(platform, table).items():
    100100            if version == os_version:
    101101                return os_name
     
    127127    def from_name(self, name):
    128128        # Exact match
    129         for _, map in self.mapping.iteritems():
    130             for os_name, os_map in map.iteritems():
     129        for _, map in self.mapping.items():
     130            for os_name, os_map in map.items():
    131131                if name in os_map:
    132132                    return (os_name, os_map[name])
     
    134134        # It's not an exact match, let's try unifying formatting
    135135        unformatted = self.strip_name_formatting(name)
    136         for _, map in self.mapping.iteritems():
    137             for os_name, os_map in map.iteritems():
    138                 for version_name, version in os_map.iteritems():
     136        for _, map in self.mapping.items():
     137            for os_name, os_map in map.items():
     138                for version_name, version in os_map.items():
    139139                    if self.strip_name_formatting(version_name) == unformatted:
    140140                        return (os_name, version)
  • trunk/Tools/Scripts/webkitpy/common/version_name_map_unittest.py

    r246497 r250375  
    2525from webkitpy.common.system.systemhost import SystemHost
    2626from webkitpy.common.version import Version
    27 from version_name_map import VersionNameMap
     27from webkitpy.common.version_name_map import VersionNameMap
    2828
    2929
  • trunk/Tools/Scripts/webkitpy/common/version_unittest.py

    r225953 r250375  
    2323import unittest
    2424
    25 from version import Version
     25from webkitpy.common.version import Version
    2626
    2727
  • trunk/Tools/Scripts/webkitpy/common/wavediff.py

    r181579 r250375  
    2121# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 import StringIO
    2423import struct
    2524import sys
    2625import tempfile
    2726import wave
     27
     28from io import BytesIO
    2829
    2930
     
    3839            waveFile1 = wave.open(in1, 'rb')
    3940        else:
    40             waveFile1 = wave.open(StringIO.StringIO(in1), 'rb')
     41            waveFile1 = wave.open(BytesIO(in1), 'rb')
    4142        if isinstance(in2, file):
    4243            waveFile1 = wave.open(in2, 'rb')
    4344        else:
    44             waveFile2 = wave.open(StringIO.StringIO(in2), 'rb')
     45            waveFile2 = wave.open(BytesIO(in2), 'rb')
    4546
    4647        params1 = waveFile1.getparams()
  • trunk/Tools/Scripts/webkitpy/port/__init__.py

    r136545 r250375  
    2929"""Port-specific entrypoints for the layout tests test infrastructure."""
    3030
    31 import builders  # Why is this in port?
     31import webkitpy.port.builders  # Why is this in port?
    3232
    33 from base import Port  # It's possible we don't need to export this virtual baseclass outside the module.
    34 from driver import Driver, DriverInput, DriverOutput
    35 from factory import platform_options, configuration_options
     33from webkitpy.port.base import Port  # It's possible we don't need to export this virtual baseclass outside the module.
     34from webkitpy.port.driver import Driver, DriverInput, DriverOutput
     35from webkitpy.port.factory import platform_options, configuration_options
Note: See TracChangeset for help on using the changeset viewer.