Bug 1559975 - convert testing/web-platform to python3 compatible syntax r=jgraham

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edwin Gao 2019-08-30 00:05:00 +00:00
parent 35bcd5dc3f
commit 4cfd9c1064
24 changed files with 57 additions and 57 deletions

View File

@ -199,7 +199,7 @@ def run(src_root, obj_root, logger_=None, **kwargs):
with open(out_path, "w") as f:
json.dump(rv, f)
else:
print json.dumps(rv, indent=2)
print(json.dumps(rv, indent=2))
if kwargs["meta_dir"]:
update_wpt_meta(logger_obj, kwargs["meta_dir"], rv)

View File

@ -31,7 +31,7 @@ def main():
if data != generated_test.data:
logging.error('%s does not match template', generated_test.path)
return -1
except IOError, e:
except IOError as e:
if e.errno == 2:
logging.error('Missing generated test:\n%s\nFor template:\n%s',
generated_test.path,

View File

@ -10,7 +10,7 @@ def main(request, response):
second_level_iframe_code = ""
if "include_second_level_iframe" in request.GET:
if "second_level_iframe_csp" in request.GET and request.GET["second_level_iframe_csp"] <> "":
if "second_level_iframe_csp" in request.GET and request.GET["second_level_iframe_csp"] != "":
second_level_iframe_code = '''<script>
var i2 = document.createElement('iframe');
i2.src = 'echo-required-csp.py';

View File

@ -125,7 +125,7 @@ def makeLookup1():
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
raise NotImplementedError("Unsupported cmap table format: %d" % table.format)
cp += 1
# tag.fail
@ -146,7 +146,7 @@ def makeLookup1():
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
raise NotImplementedError("Unsupported cmap table format: %d" % table.format)
# bump this up so that the sequence is the same as the lookup 3 font
cp += 3
@ -327,7 +327,7 @@ def makeLookup3():
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
raise NotImplementedError("Unsupported cmap table format: %d" % table.format)
cp += 1
# tag.alt1,2,3
@ -348,7 +348,7 @@ def makeLookup3():
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
raise NotImplementedError("Unsupported cmap table format: %d" % table.format)
cp += 1
# set the glyph order

View File

@ -534,7 +534,7 @@ class FileSource:
def unicode(self):
try:
return self.data().decode(self.encoding)
except UnicodeDecodeError, e:
except UnicodeDecodeError:
return None
def parse(self):

View File

@ -86,7 +86,7 @@ def listfiles(path, ext = None):
_,_,files = os.walk(path).next()
if (ext):
files = [fileName for fileName in files if fileName.endswith(ext)]
except StopIteration, e:
except StopIteration:
files = []
return files
@ -95,7 +95,7 @@ def listdirs(path):
"""
try:
_,dirs,_ = os.walk(path).next()
except StopIteration, e:
except StopIteration:
dirs = []
return dirs

View File

@ -527,7 +527,7 @@ class ClientHandshakeProcessor(ClientHandshakeBase):
# Validate
try:
binary_accept = base64.b64decode(accept)
except TypeError, e:
except TypeError:
raise HandshakeError(
'Illegal value for header %s: %r' %
(common.SEC_WEBSOCKET_ACCEPT_HEADER, accept))
@ -947,7 +947,7 @@ class EchoClient(object):
if self._options.verbose:
print('Recv: %s' % received)
except Exception, e:
except Exception as e:
if self._options.verbose:
print('Error: %s' % e)
raise

View File

@ -201,7 +201,7 @@ def headerparserhandler(request):
request.log_error(
'mod_pywebsocket: Fallback to Apache', apache.APLOG_INFO)
return apache.DECLINED
except dispatch.DispatchException, e:
except dispatch.DispatchException as e:
request.log_error(
'mod_pywebsocket: Dispatch failed for error: %s' % e,
apache.APLOG_INFO)
@ -217,14 +217,14 @@ def headerparserhandler(request):
try:
handshake.do_handshake(
request, _dispatcher, allowDraft75=allow_draft75)
except handshake.VersionException, e:
except handshake.VersionException as e:
request.log_error(
'mod_pywebsocket: Handshake failed for version error: %s' % e,
apache.APLOG_INFO)
request.err_headers_out.add(common.SEC_WEBSOCKET_VERSION_HEADER,
e.supported_versions)
return apache.HTTP_BAD_REQUEST
except handshake.HandshakeException, e:
except handshake.HandshakeException as e:
# Handshake for ws/wss failed.
# Send http response with error status.
request.log_error(
@ -235,10 +235,10 @@ def headerparserhandler(request):
handshake_is_done = True
request._dispatcher = _dispatcher
_dispatcher.transfer_data(request)
except handshake.AbortedByUserException, e:
except handshake.AbortedByUserException as e:
request.log_error('mod_pywebsocket: Aborted: %s' % e,
apache.APLOG_INFO)
except Exception, e:
except Exception as e:
# DispatchException can also be thrown if something is wrong in
# pywebsocket code. It's caught here, then.

View File

@ -398,7 +398,7 @@ class WebSocketHandshake(object):
# Validate
try:
decoded_accept = base64.b64decode(accept)
except TypeError, e:
except TypeError as e:
raise HandshakeException(
'Illegal value for header Sec-WebSocket-Accept: ' + accept)
@ -998,7 +998,7 @@ def connect_socket_with_retry(host, port, timeout, use_tls,
if use_tls:
return _TLSSocket(s)
return s
except socket.error, e:
except socket.error as e:
if e.errno != errno.ECONNREFUSED:
raise
else:
@ -1063,7 +1063,7 @@ class Client(object):
def assert_connection_closed(self):
try:
read_data = receive_bytes(self._socket, 1)
except Exception, e:
except Exception as e:
if str(e).find(
'Connection closed before receiving requested length ') == 0:
return

View File

@ -519,7 +519,7 @@ class MuxClient(object):
try:
send_quota = self._channel_slots.popleft()
except IndexError, e:
except IndexError as e:
raise Exception('No channel slots: %r' % e)
# Create AddChannel request
@ -632,7 +632,7 @@ class MuxClient(object):
try:
inner_frame = self._logical_channels[channel_id].queue.get(
timeout=self._timeout)
except Queue.Empty, e:
except Queue.Empty as e:
raise Exception('Cannot receive message from channel id %d' %
channel_id)
@ -666,7 +666,7 @@ class MuxClient(object):
try:
inner_frame = self._logical_channels[channel_id].queue.get(
timeout=self._timeout)
except Queue.Empty, e:
except Queue.Empty as e:
raise Exception('Cannot receive message from channel id %d' %
channel_id)
if inner_frame.opcode != client_for_testing.OPCODE_CLOSE:

View File

@ -155,9 +155,9 @@ class DispatcherTest(unittest.TestCase):
try:
dispatcher.do_extra_handshake(request)
self.fail('Could not catch HandshakeException with 403 status')
except handshake.HandshakeException, e:
except handshake.HandshakeException as e:
self.assertEquals(403, e.status)
except Exception, e:
except Exception as e:
self.fail('Unexpected exception: %r' % e)
def test_abort_extra_handshake(self):
@ -212,7 +212,7 @@ class DispatcherTest(unittest.TestCase):
try:
dispatcher.transfer_data(request)
self.fail()
except dispatch.DispatchException, e:
except dispatch.DispatchException as e:
self.failUnless(str(e).find('No handler') != -1)
except Exception:
self.fail()
@ -225,7 +225,7 @@ class DispatcherTest(unittest.TestCase):
try:
dispatcher.transfer_data(request)
self.fail()
except Exception, e:
except Exception as e:
self.failUnless(str(e).find('Intentional') != -1,
'Unexpected exception: %s' % e)

View File

@ -304,9 +304,9 @@ class EndToEndHyBiTest(EndToEndTestBase):
try:
client.connect()
self.fail('Could not catch HttpStatusException')
except client_for_testing.HttpStatusException, e:
except client_for_testing.HttpStatusException as e:
self.assertEqual(status, e.status)
except Exception, e:
except Exception as e:
self.fail('Catch unexpected exception')
finally:
client.close_socket()

View File

@ -507,10 +507,10 @@ class HandshakerTest(unittest.TestCase):
try:
handshaker.do_handshake()
self.fail('No exception thrown for \'%s\' case' % case_name)
except HandshakeException, e:
except HandshakeException as e:
self.assertTrue(expect_handshake_exception)
self.assertEqual(expected_status, e.status)
except VersionException, e:
except VersionException as e:
self.assertFalse(expect_handshake_exception)

View File

@ -258,9 +258,9 @@ class _MuxMockDispatcher(object):
raise ValueError('Cannot handle path %r' % request.path)
if not request.server_terminated:
request.ws_stream.close_connection()
except ConnectionTerminatedException, e:
except ConnectionTerminatedException as e:
self.channel_events[request.channel_id].exception = e
except Exception, e:
except Exception as e:
self.channel_events[request.channel_id].exception = e
raise

View File

@ -63,7 +63,7 @@ def env_options():
def update_properties():
return ["debug", "os", "processor"], {"os": ["version"], "processor": ["bits"]}
return (["debug", "os", "processor"], {"os": ["version"], "processor": ["bits"]})
def write_hosts_file(config):

View File

@ -498,7 +498,7 @@ class WdspecRun(object):
class ConnectionlessBaseProtocolPart(BaseProtocolPart):
def execute_script(self, script, async=False):
def execute_script(self, script, asynchronous=False):
pass
def set_timeout(self, timeout):

View File

@ -56,8 +56,8 @@ class MarionetteBaseProtocolPart(BaseProtocolPart):
def setup(self):
self.marionette = self.parent.marionette
def execute_script(self, script, async=False):
method = self.marionette.execute_async_script if async else self.marionette.execute_script
def execute_script(self, script, asynchronous=False):
method = self.marionette.execute_async_script if asynchronous else self.marionette.execute_script
return method(script, new_sandbox=False, sandbox=None)
def set_timeout(self, timeout):
@ -738,7 +738,7 @@ class MarionetteTestharnessExecutor(TestharnessExecutor):
protocol.marionette.navigate(url)
while True:
result = protocol.base.execute_script(
self.script_resume % format_map, async=True)
self.script_resume % format_map, asynchronous=True)
if result is None:
# This can happen if we get an content process crash
return None
@ -858,7 +858,7 @@ class MarionetteRefTestExecutor(RefTestExecutor):
def _screenshot(self, protocol, url, timeout):
protocol.marionette.navigate(url)
protocol.base.execute_script(self.wait_script, async=True)
protocol.base.execute_script(self.wait_script, asynchronous=True)
screenshot = protocol.marionette.screenshot(full=False)
# strip off the data:img/png, part of the url

View File

@ -46,8 +46,8 @@ class SeleniumBaseProtocolPart(BaseProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver
def execute_script(self, script, async=False):
method = self.webdriver.execute_async_script if async else self.webdriver.execute_script
def execute_script(self, script, asynchronous=False):
method = self.webdriver.execute_async_script if asynchronous else self.webdriver.execute_script
return method(script)
def set_timeout(self, timeout):
@ -335,7 +335,7 @@ class SeleniumTestharnessExecutor(TestharnessExecutor):
handler = CallbackHandler(self.logger, protocol, test_window)
while True:
result = protocol.base.execute_script(
self.script_resume % format_map, async=True)
self.script_resume % format_map, asynchronous=True)
done, rv = handler(result)
if done:
break

View File

@ -67,7 +67,7 @@ def parse_pref_value(value):
class ServoBaseProtocolPart(BaseProtocolPart):
def execute_script(self, script, async=False):
def execute_script(self, script, asynchronous=False):
pass
def set_timeout(self, timeout):

View File

@ -34,8 +34,8 @@ class WebDriverBaseProtocolPart(BaseProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver
def execute_script(self, script, async=False):
method = self.webdriver.execute_async_script if async else self.webdriver.execute_script
def execute_script(self, script, asynchronous=False):
method = self.webdriver.execute_async_script if asynchronous else self.webdriver.execute_script
return method(script)
def set_timeout(self, timeout):
@ -367,7 +367,7 @@ class WebDriverTestharnessExecutor(TestharnessExecutor):
while True:
result = protocol.base.execute_script(
self.script_resume % format_map, async=True)
self.script_resume % format_map, asynchronous=True)
# As of 2019-03-29, WebDriver does not define expected behavior for
# cases where the browser crashes during script execution:
@ -401,7 +401,7 @@ if (location.href === "about:blank") {
callback(true);
} else {
document.addEventListener("readystatechange", () => {if (document.readyState !== "loading") {callback(true)}});
}""", async=True)
}""", asynchronous=True)
except client.JavascriptErrorException:
# We can get an error here if the script runs in the initial about:blank
# document before it has navigated, with the driver returning an error

View File

@ -109,11 +109,11 @@ class BaseProtocolPart(ProtocolPart):
name = "base"
@abstractmethod
def execute_script(self, script, async=False):
def execute_script(self, script, asynchronous=False):
"""Execute javascript in the current Window.
:param str script: The js source to execute. This is implicitly wrapped in a function.
:param bool async: Whether the script is asynchronous in the webdriver
:param bool asynchronous: Whether the script is asynchronous in the webdriver
sense i.e. whether the return value is the result of
the initial function call or if it waits for some callback.
:returns: The result of the script execution.

View File

@ -1,3 +1,3 @@
# Oops...
def main(request, response
def main(request, response):
return "FAIL"

View File

@ -49,7 +49,7 @@ class GitHub(object):
if 200 <= resp.status_code < 300:
return resp.json()
else:
print method, path, resp.status_code, resp.json()
print(method, path, resp.status_code, resp.json())
raise GitHubError(resp.status_code, resp.json())
def repo(self, owner, name):

View File

@ -171,7 +171,7 @@ class SelectCommits(Step):
while True:
commits = state.source_commits[:]
for i, commit in enumerate(commits):
print "%i:\t%s" % (i, commit.message.summary)
print("{}:\t{}".format(i, commit.message.summary))
remove = raw_input("Provide a space-separated list of any commits numbers to remove from the list to upstream:\n").strip()
remove_idx = set()
@ -186,9 +186,9 @@ class SelectCommits(Step):
keep_commits = [(i,cmt) for i,cmt in enumerate(commits) if i not in remove_idx]
#TODO: consider printed removed commits
print "Selected the following commits to keep:"
print("Selected the following commits to keep:")
for i, commit in keep_commits:
print "%i:\t%s" % (i, commit.message.summary)
print("{}:\t{}".format(i, commit.message.summary))
confirm = raw_input("Keep the above commits? y/n\n").strip().lower()
if confirm == "y":
@ -235,10 +235,10 @@ class MovePatches(Step):
except:
with tempfile.NamedTemporaryFile(delete=False, suffix=".diff") as f:
f.write(stripped_patch.diff)
print """Patch failed to apply. Diff saved in %s
Fix this file so it applies and run with --continue""" % f.name
print("""Patch failed to apply. Diff saved in {}
Fix this file so it applies and run with --continue""".format(f.name))
state.patch = (f.name, stripped_patch)
print state.patch
print(state.patch)
sys.exit(1)
state.commits_loaded = i
raw_input("Check for differences with upstream")