diff --git a/accessible/xpcom/AccEventGen.py b/accessible/xpcom/AccEventGen.py index e30628f21c3a..8f1da0d24f16 100755 --- a/accessible/xpcom/AccEventGen.py +++ b/accessible/xpcom/AccEventGen.py @@ -21,9 +21,7 @@ import xpidl # Load the webidl configuration file. glbl = {} -execfile(mozpath.join(buildconfig.topsrcdir, - 'dom', 'bindings', 'Bindings.conf'), - glbl) +exec(open(mozpath.join(buildconfig.topsrcdir, 'dom', 'bindings', 'Bindings.conf')).read(), glbl) webidlconfig = glbl['DOMInterfaces'] # Instantiate the parser. @@ -51,7 +49,7 @@ def loadEventIDL(parser, includePath, eventname): class Configuration: def __init__(self, filename): config = {} - execfile(filename, config) + exec(open(filename).read(), config) self.simple_events = config.get('simple_events', []) diff --git a/build/win32/autobinscope.py b/build/win32/autobinscope.py index d890df741a60..d89ea7e83513 100644 --- a/build/win32/autobinscope.py +++ b/build/win32/autobinscope.py @@ -74,7 +74,7 @@ try: "/Checks", "WXCheck" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) -except WindowsError, (errno, strerror): +except WindowsError, (errno, strerror): # noqa if errno != 2 and errno != 3: print("TEST-UNEXPECTED-FAIL | autobinscope.py | Unexpected error %d : %s" ( errno, strerror)) diff --git a/js/src/gdb/mozilla/JSString.py b/js/src/gdb/mozilla/JSString.py index 3ad35b6f9423..6717c8f2de4a 100644 --- a/js/src/gdb/mozilla/JSString.py +++ b/js/src/gdb/mozilla/JSString.py @@ -10,7 +10,7 @@ from mozilla.prettyprinters import ptr_pretty_printer try: chr(10000) # UPPER RIGHT PENCIL -except ValueError as exc: # yuck, we are in Python 2.x, so chr() is 8-bit +except ValueError: # yuck, we are in Python 2.x, so chr() is 8-bit chr = unichr # replace with teh unicodes # Forget any printers from previous loads of this module. diff --git a/python/mach_commands.py b/python/mach_commands.py index 794219a879ab..84ce0969e1f2 100644 --- a/python/mach_commands.py +++ b/python/mach_commands.py @@ -61,7 +61,7 @@ class MachCommands(MachCommandBase): python_path = self.virtualenv_manager.python_path if exec_file: - execfile(exec_file) + exec(open(exec_file).read()) return 0 return self.run_process([python_path] + args, diff --git a/python/mozboot/mozboot/archlinux.py b/python/mozboot/mozboot/archlinux.py index 72aeaa710201..77a5bd237715 100644 --- a/python/mozboot/mozboot/archlinux.py +++ b/python/mozboot/mozboot/archlinux.py @@ -22,7 +22,7 @@ from mozboot.linux_common import ( # have to rely on the standard library instead of Python 2+3 helpers like # the six module. if sys.version_info < (3,): - input = raw_input + input = raw_input # noqa class ArchlinuxBootstrapper(NodeInstall, StyloInstall, SccacheInstall, diff --git a/python/mozboot/mozboot/base.py b/python/mozboot/mozboot/base.py index 8ecca71840fc..c206d0c28392 100644 --- a/python/mozboot/mozboot/base.py +++ b/python/mozboot/mozboot/base.py @@ -18,7 +18,7 @@ from mozboot import rust # the six module. if sys.version_info < (3,): from urllib2 import urlopen - input = raw_input + input = raw_input # noqa else: from urllib.request import urlopen diff --git a/python/mozboot/mozboot/bootstrap.py b/python/mozboot/mozboot/bootstrap.py index d0fb378891b7..956ecb826c26 100644 --- a/python/mozboot/mozboot/bootstrap.py +++ b/python/mozboot/mozboot/bootstrap.py @@ -17,7 +17,7 @@ if sys.version_info < (3,): Error as ConfigParserError, RawConfigParser, ) - input = raw_input + input = raw_input # noqa else: from configparser import ( Error as ConfigParserError, diff --git a/python/mozboot/mozboot/solus.py b/python/mozboot/mozboot/solus.py index 5ca4856c79d2..424d1c9c7474 100644 --- a/python/mozboot/mozboot/solus.py +++ b/python/mozboot/mozboot/solus.py @@ -19,7 +19,7 @@ from mozboot.linux_common import ( # have to rely on the standard library instead of Python 2+3 helpers like # the six module. if sys.version_info < (3,): - input = raw_input + input = raw_input # noqa class SolusBootstrapper(NodeInstall, StyloInstall, SccacheInstall, diff --git a/python/mozrelease/mozrelease/update_verify.py b/python/mozrelease/mozrelease/update_verify.py index cdb00144fd10..4cbe8eb8c87e 100644 --- a/python/mozrelease/mozrelease/update_verify.py +++ b/python/mozrelease/mozrelease/update_verify.py @@ -8,6 +8,8 @@ from __future__ import absolute_import, print_function import os import re +from six import string_types + from .chunking import getChunk @@ -128,9 +130,9 @@ class UpdateVerifyConfig(object): raise UpdateVerifyError( "Couldn't add release identified by build_id '%s' and from_path '%s': " "already exists in config" % (build_id, from_path)) - if isinstance(locales, basestring): + if isinstance(locales, string_types): locales = sorted(list(locales.split())) - if isinstance(patch_types, basestring): + if isinstance(patch_types, string_types): patch_types = list(patch_types.split()) self.releases.append({ "release": release, diff --git a/security/sandbox/test/mac_register_font.py b/security/sandbox/test/mac_register_font.py index e26380d098e2..00fa169e638b 100755 --- a/security/sandbox/test/mac_register_font.py +++ b/security/sandbox/test/mac_register_font.py @@ -9,6 +9,8 @@ mac_register_font.py Mac-specific utility command to register a font file with the OS. """ +from __future__ import print_function + import CoreText import Cocoa import argparse @@ -41,13 +43,13 @@ def main(): (result, error) = register_or_unregister_font(fontURL, args.unregister, scope) if result: - print ("%sregistered font %s with %s scope" % - (("un" if args.unregister else ""), fontPath, scopeDesc)) + print("%sregistered font %s with %s scope" % + (("un" if args.unregister else ""), fontPath, scopeDesc)) else: - print ("Failed to %sregister font %s with %s scope" % - (("un" if args.unregister else ""), fontPath, scopeDesc)) + print("Failed to %sregister font %s with %s scope" % + (("un" if args.unregister else ""), fontPath, scopeDesc)) if args.verbose: - print (error) + print(error) failureCount += 1 sys.exit(failureCount) diff --git a/taskcluster/docker/funsize-update-generator/scripts/funsize.py b/taskcluster/docker/funsize-update-generator/scripts/funsize.py index b086d485424f..a9e49100d34e 100755 --- a/taskcluster/docker/funsize-update-generator/scripts/funsize.py +++ b/taskcluster/docker/funsize-update-generator/scripts/funsize.py @@ -15,9 +15,7 @@ import logging import os import shutil import tempfile -import time import requests -import sh from distutils.util import strtobool import redo diff --git a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py index 98ce3c8ce133..e96e3a05a5c7 100644 --- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py +++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py @@ -140,7 +140,7 @@ class CommonTestCase(unittest.TestCase): self.setUp() except SkipTest as e: self._addSkip(result, str(e)) - except (KeyboardInterrupt, UnresponsiveInstanceException) as e: + except (KeyboardInterrupt, UnresponsiveInstanceException): raise except _ExpectedFailure as e: expected_failure(result, e.exc_info) @@ -160,7 +160,7 @@ class CommonTestCase(unittest.TestCase): except self.failureException: self._enter_pm() result.addFailure(self, sys.exc_info()) - except (KeyboardInterrupt, UnresponsiveInstanceException) as e: + except (KeyboardInterrupt, UnresponsiveInstanceException): raise except _ExpectedFailure as e: expected_failure(result, e.exc_info) @@ -188,7 +188,7 @@ class CommonTestCase(unittest.TestCase): raise _ExpectedFailure(sys.exc_info()) else: self.tearDown() - except (KeyboardInterrupt, UnresponsiveInstanceException) as e: + except (KeyboardInterrupt, UnresponsiveInstanceException): raise except _ExpectedFailure as e: expected_failure(result, e.exc_info) diff --git a/testing/mochitest/runtests.py b/testing/mochitest/runtests.py index 0855748a61a3..e907c6f13e49 100644 --- a/testing/mochitest/runtests.py +++ b/testing/mochitest/runtests.py @@ -56,10 +56,10 @@ from manifestparser.filters import ( try: from marionette_driver.addons import Addons from marionette_harness import Marionette -except ImportError as e: +except ImportError as e: # noqa # Defer ImportError until attempt to use Marionette def reraise(*args, **kwargs): - raise(e) + raise(e) # noqa Marionette = reraise from leaks import ShutdownLeaks, LSANLeaks diff --git a/testing/raptor/raptor/output.py b/testing/raptor/raptor/output.py index 08eaafe9c9e6..c3fea71ac07c 100644 --- a/testing/raptor/raptor/output.py +++ b/testing/raptor/raptor/output.py @@ -6,7 +6,7 @@ # some parts of this originally taken from /testing/talos/talos/output.py """output raptor test results""" -from __future__ import absolute_import +from __future__ import absolute_import, print_function import filters @@ -810,7 +810,7 @@ class RaptorOutput(PerftestOutput): ''' _subtests = {} data = test.measurements['wasm-godot'] - print (data) + print(data) for page_cycle in data: for item in page_cycle[0]: # for each pagecycle, build a list of subtests and append all related replicates diff --git a/testing/raptor/raptor/profiler/symFileManager.py b/testing/raptor/raptor/profiler/symFileManager.py index 048de6fd28a8..e46cccf7bb62 100755 --- a/testing/raptor/raptor/profiler/symFileManager.py +++ b/testing/raptor/raptor/profiler/symFileManager.py @@ -169,7 +169,7 @@ class SymFileManager: symbol = line[addressLength + 1:].rstrip() symbolMap[address] = symbol publicCount += 1 - except Exception as e: + except Exception: LogError("Error parsing SYM file " + path) return None diff --git a/testing/talos/talos/profiler/symFileManager.py b/testing/talos/talos/profiler/symFileManager.py index 048de6fd28a8..e46cccf7bb62 100755 --- a/testing/talos/talos/profiler/symFileManager.py +++ b/testing/talos/talos/profiler/symFileManager.py @@ -169,7 +169,7 @@ class SymFileManager: symbol = line[addressLength + 1:].rstrip() symbolMap[address] = symbol publicCount += 1 - except Exception as e: + except Exception: LogError("Error parsing SYM file " + path) return None diff --git a/testing/tools/mach_test_package_bootstrap.py b/testing/tools/mach_test_package_bootstrap.py index e2ad2442738f..f973736156aa 100644 --- a/testing/tools/mach_test_package_bootstrap.py +++ b/testing/tools/mach_test_package_bootstrap.py @@ -82,6 +82,12 @@ CATEGORIES = { IS_WIN = sys.platform in ('win32', 'cygwin') +PY3 = sys.version_info[0] == 3 + +if PY3: + text_type = str +else: + text_type = unicode # noqa def ancestors(path, depth=0): @@ -108,9 +114,9 @@ def activate_mozharness_venv(context): venv_bin = os.path.join(venv, 'Scripts' if IS_WIN else 'bin') activate_path = os.path.join(venv_bin, 'activate_this.py') - execfile(activate_path, dict(__file__=activate_path)) + exec(open(activate_path).read(), dict(__file__=activate_path)) - if isinstance(os.environ['PATH'], unicode): + if isinstance(os.environ['PATH'], text_type): os.environ['PATH'] = os.environ['PATH'].encode('utf-8') # sys.executable is used by mochitest-media to start the websocketprocessbridge, diff --git a/testing/tps/create_venv.py b/testing/tps/create_venv.py index b02bb6b74401..cdd21efffa96 100755 --- a/testing/tps/create_venv.py +++ b/testing/tps/create_venv.py @@ -159,7 +159,7 @@ def main(): # Activate tps environment tps_env = os.path.join(target, activate_env) - execfile(tps_env, dict(__file__=tps_env)) + exec(open(tps_env).read(), dict(__file__=tps_env)) # Install TPS in environment subprocess.check_call([os.path.join(target, python_env), diff --git a/tools/rb/find_leakers.py b/tools/rb/find_leakers.py index 47b4ef62ba04..d164d58b3cbf 100755 --- a/tools/rb/find_leakers.py +++ b/tools/rb/find_leakers.py @@ -9,6 +9,7 @@ # sees if they `Release' or `Dtor'. If not, it reports them as leaks. # Please see README file in the same directory. +from __future__ import print_function import sys @@ -23,9 +24,9 @@ def print_output(allocation, obj_to_class): items.sort(key=lambda item: item[1]) for obj, count, in items: - print "{obj} ({count}) @ {class_name}".format(obj=obj, + print("{obj} ({count}) @ {class_name}".format(obj=obj, count=count, - class_name=obj_to_class[obj]) + class_name=obj_to_class[obj])) def process_log(log_lines): @@ -65,8 +66,8 @@ def process_log(log_lines): # 0x01AFD3B8 1 Release 0 # 0x08880BD0 8 Dtor (20) if obj not in allocation: - print "An object was released that wasn't allocated!", - print obj, "@", class_name + print("An object was released that wasn't allocated!",) + print(obj, "@", class_name) else: allocation.pop(obj) obj_to_class.pop(obj) @@ -76,12 +77,12 @@ def process_log(log_lines): def print_usage(): - print - print "Usage: find-leakers.py [log-file]" - print - print "If `log-file' provided, it will read that as the input log." - print "Else, it will read the stdin as the input log." - print + print('') + print("Usage: find-leakers.py [log-file]") + print('') + print("If `log-file' provided, it will read that as the input log.") + print("Else, it will read the stdin as the input log.") + print('') def main(): @@ -95,7 +96,7 @@ def main(): log_lines = log_file.readlines() process_log(log_lines) else: - print 'ERROR: Invalid number of arguments' + print('ERROR: Invalid number of arguments') print_usage() diff --git a/tools/rb/fix_linux_stack.py b/tools/rb/fix_linux_stack.py index 7915ffe6e7da..4c68271a7792 100755 --- a/tools/rb/fix_linux_stack.py +++ b/tools/rb/fix_linux_stack.py @@ -152,7 +152,7 @@ def separate_debug_file_for(file): def word32(s): if type(s) != str or len(s) != 4: - raise StandardError("expected 4 byte string input") + raise Exception("expected 4 byte string input") s = list(s) if endian == "big": s.reverse() diff --git a/tools/rb/fix_macosx_stack.py b/tools/rb/fix_macosx_stack.py index eb96efdae336..6d45aa40405b 100755 --- a/tools/rb/fix_macosx_stack.py +++ b/tools/rb/fix_macosx_stack.py @@ -8,6 +8,8 @@ # NS_FormatCodeAddress(), which on Mac often lack a file name and a line # number. +from __future__ import print_function + import json import os import pty @@ -45,7 +47,7 @@ class unbufferedLineConverter: def test(): assert unbufferedLineConverter("rev").convert("123") == "321" assert unbufferedLineConverter("cut", ["-c3"]).convert("abcde") == "c" - print "Pass" + print("Pass") def separate_debug_file_for(file): @@ -66,13 +68,13 @@ def address_adjustment(file): if line == " segname __TEXT\n": line = otool.stdout.readline() if not line.startswith(" vmaddr "): - raise StandardError("unexpected otool output") + raise Exception("unexpected otool output") result = int(line[10:], 16) break otool.stdout.close() if result is None: - raise StandardError("unexpected otool output") + raise Exception("unexpected otool output") address_adjustments[file] = result diff --git a/tools/tryselect/templates.py b/tools/tryselect/templates.py index 0a1e9812aac5..862ad6d2338d 100644 --- a/tools/tryselect/templates.py +++ b/tools/tryselect/templates.py @@ -291,7 +291,7 @@ class VisualMetricsJobs(TryConfig): visual_metrics_jobs = json.load(f) visual_metrics_jobs_schema(visual_metrics_jobs) - except (IOError, OSError) as e: + except (IOError, OSError): print('Failed to read file %s: %s' % (file_path, f)) sys.exit(1) except TypeError: diff --git a/xpcom/components/gen_static_components.py b/xpcom/components/gen_static_components.py index 521af8076a7e..b120c4ff3f18 100644 --- a/xpcom/components/gen_static_components.py +++ b/xpcom/components/gen_static_components.py @@ -684,7 +684,7 @@ def read_manifest(filename): glbl = {'buildconfig': buildconfig, 'defined': defined, 'ProcessSelector': ProcessSelector} - execfile(filename, glbl) + exec(open(filename).read(), glbl) return glbl diff --git a/xpcom/idl-parser/xpidl/xpidl.py b/xpcom/idl-parser/xpidl/xpidl.py index 82cc4811dcde..9545f83ef605 100755 --- a/xpcom/idl-parser/xpidl/xpidl.py +++ b/xpcom/idl-parser/xpidl/xpidl.py @@ -1243,7 +1243,7 @@ class Param(object): return self.realtype.nativeType(self.paramtype, **kwargs) except IDLError as e: raise IDLError(e.message, self.location) - except TypeError as e: + except TypeError: raise IDLError("Unexpected parameter attribute", self.location) def rustType(self): @@ -1257,7 +1257,7 @@ class Param(object): return self.realtype.rustType(self.paramtype, **kwargs) except IDLError as e: raise IDLError(e.message, self.location) - except TypeError as e: + except TypeError: raise IDLError("Unexpected parameter attribute", self.location) def toIDL(self):