Skip to content

Commit

Permalink
Bug 1567642 - [lint.flake8] Fix misc flake8 under Python 3 lint issue…
Browse files Browse the repository at this point in the history
…s r=gbrown

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
ahal committed Sep 24, 2019
1 parent 27384ce commit 898dfb9
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 51 deletions.
6 changes: 2 additions & 4 deletions accessible/xpcom/AccEventGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

# 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.
Expand Down Expand Up @@ -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', [])


Expand Down
2 changes: 1 addition & 1 deletion build/win32/autobinscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"/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))
Expand Down
2 changes: 1 addition & 1 deletion js/src/gdb/mozilla/JSString.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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.
Expand Down
2 changes: 1 addition & 1 deletion python/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def python(self, no_virtualenv, exec_file, args):
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,
Expand Down
2 changes: 1 addition & 1 deletion python/mozboot/mozboot/archlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# 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,
Expand Down
2 changes: 1 addition & 1 deletion python/mozboot/mozboot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 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

Expand Down
2 changes: 1 addition & 1 deletion python/mozboot/mozboot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Error as ConfigParserError,
RawConfigParser,
)
input = raw_input
input = raw_input # noqa
else:
from configparser import (
Error as ConfigParserError,
Expand Down
2 changes: 1 addition & 1 deletion python/mozboot/mozboot/solus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 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,
Expand Down
6 changes: 4 additions & 2 deletions python/mozrelease/mozrelease/update_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os
import re

from six import string_types

from .chunking import getChunk


Expand Down Expand Up @@ -128,9 +130,9 @@ def addRelease(self, release=None, build_id=None, locales=[],
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,
Expand Down
12 changes: 7 additions & 5 deletions security/sandbox/test/mac_register_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
Mac-specific utility command to register a font file with the OS.
"""

from __future__ import print_function

import CoreText
import Cocoa
import argparse
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import os
import shutil
import tempfile
import time
import requests
import sh
from distutils.util import strtobool

import redo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def expected_failure(result, exc_info):
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)
Expand All @@ -160,7 +160,7 @@ def expected_failure(result, exc_info):
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)
Expand Down Expand Up @@ -188,7 +188,7 @@ def expected_failure(result, exc_info):
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)
Expand Down
4 changes: 2 additions & 2 deletions testing/mochitest/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
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
Expand Down
4 changes: 2 additions & 2 deletions testing/raptor/raptor/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -810,7 +810,7 @@ def parseWASMGodotOutput(self, test):
'''
_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
Expand Down
2 changes: 1 addition & 1 deletion testing/raptor/raptor/profiler/symFileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def FetchSymbolsFromFile(self, path):
symbol = line[addressLength + 1:].rstrip()
symbolMap[address] = symbol
publicCount += 1
except Exception as e:
except Exception:
LogError("Error parsing SYM file " + path)
return None

Expand Down
2 changes: 1 addition & 1 deletion testing/talos/talos/profiler/symFileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def FetchSymbolsFromFile(self, path):
symbol = line[addressLength + 1:].rstrip()
symbolMap[address] = symbol
publicCount += 1
except Exception as e:
except Exception:
LogError("Error parsing SYM file " + path)
return None

Expand Down
10 changes: 8 additions & 2 deletions testing/tools/mach_test_package_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@


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):
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion testing/tps/create_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
23 changes: 12 additions & 11 deletions tools/rb/find_leakers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion tools/rb/fix_linux_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def have_debug_file(debugfile):

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()
Expand Down
8 changes: 5 additions & 3 deletions tools/rb/fix_macosx_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,7 +47,7 @@ def convert(self, line):
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):
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tools/tryselect/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def try_config(self, **kwargs):
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:
Expand Down
2 changes: 1 addition & 1 deletion xpcom/components/gen_static_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions xpcom/idl-parser/xpidl/xpidl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def nativeType(self):
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):
Expand All @@ -1257,7 +1257,7 @@ def rustType(self):
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):
Expand Down

0 comments on commit 898dfb9

Please sign in to comment.