Bug 1567642 - [lint.flake8] Fix misc flake8 under Python 3 lint issues r=gbrown

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Halberstadt 2019-09-24 14:44:01 +00:00
parent 27384ce378
commit 898dfb96b4
24 changed files with 60 additions and 51 deletions

View File

@ -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', [])

View File

@ -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))

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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),

View File

@ -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):
# <nsStringBuffer> 0x01AFD3B8 1 Release 0
# <PStreamNotifyParent> 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()

View File

@ -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()

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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):