Commit 7c938463 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

Convert except statements to be Python 3 compatible

Ran "2to3 -w -n -f except ./".

The scripts still work with Python 2.
There are no intended behaviour changes.

Bug: 942522
Change-Id: Ifa274cb83f74cfa8ce092fffbb88f3ab5309e72c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1607841
Commit-Queue: Raul Tambre <raul@tambre.ee>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
parent 7d1300b8
......@@ -292,9 +292,9 @@ class GitCheckout(CheckoutBase):
if verbose:
print(p.filename)
print(align_stdout(stdout))
except OSError, e:
except OSError as e:
errors.append((p, '%s%s' % (align_stdout(stdout), e)))
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
errors.append((p,
'While running %s;\n%s%s' % (
' '.join(e.cmd),
......
......@@ -57,7 +57,7 @@ def main():
stdin=input_file)
with open(fpath, 'wb') as output_file:
output_file.write(output)
except clang_format.NotFoundError, e:
except clang_format.NotFoundError as e:
print(e)
print('Failed to find clang-format. Falling-back on standard 3-way merge')
......
......@@ -43,7 +43,7 @@ def FindDartFmtToolInChromiumTree():
def main(args):
try:
tool = FindDartFmtToolInChromiumTree()
except NotFoundError, e:
except NotFoundError as e:
print(e, file=sys.stderr)
sys.exit(1)
......
......@@ -377,7 +377,7 @@ class MyActivity(object):
return list(gerrit_util.GenerateAllChanges(instance['url'], req,
o_params=['MESSAGES', 'LABELS', 'DETAILED_ACCOUNTS',
'CURRENT_REVISION', 'CURRENT_COMMIT']))
except gerrit_util.GerritError, e:
except gerrit_util.GerritError as e:
error_message = 'Looking up %r: %s' % (instance['url'], e)
if error_message not in self.access_errors:
self.access_errors.add(error_message)
......
......@@ -1220,7 +1220,7 @@ class GetTryMastersExecuter(object):
try:
exec(compile(script_text, 'PRESUBMIT.py', 'exec', dont_inherit=True),
context)
except Exception, e:
except Exception as e:
raise PresubmitFailure('"%s" had an exception.\n%s'
% (presubmit_path, e))
......@@ -1252,7 +1252,7 @@ class GetPostUploadExecuter(object):
try:
exec(compile(script_text, 'PRESUBMIT.py', 'exec', dont_inherit=True),
context)
except Exception, e:
except Exception as e:
raise PresubmitFailure('"%s" had an exception.\n%s'
% (presubmit_path, e))
......@@ -1418,7 +1418,7 @@ class PresubmitExecuter(object):
try:
exec(compile(script_text, 'PRESUBMIT.py', 'exec', dont_inherit=True),
context)
except Exception, e:
except Exception as e:
raise PresubmitFailure('"%s" had an exception.\n%s' % (presubmit_path, e))
# These function names must change if we make substantial changes to
......@@ -1719,7 +1719,7 @@ def main(argv=None):
options.dry_run,
options.parallel)
return not results.should_continue()
except PresubmitFailure, e:
except PresubmitFailure as e:
print(e, file=sys.stderr)
print('Maybe your depot_tools is out of date?', file=sys.stderr)
return 2
......
......@@ -167,7 +167,7 @@ class Rietveld(object):
try:
diff = self.get_file_diff(issue, patchset, state['id'])
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if e.code == 404:
raise patch.UnsupportedPatchFormat(
filename, 'File doesn\'t have a diff.')
......@@ -433,7 +433,7 @@ class Rietveld(object):
try:
logging.debug('%s' % request_path)
return self.rpc_server.Send(request_path, **kwargs)
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if retry >= (self._maxtries - 1):
raise
flake_codes = {500, 502, 503}
......@@ -441,7 +441,7 @@ class Rietveld(object):
flake_codes.add(404)
if e.code not in flake_codes:
raise
except urllib2.URLError, e:
except urllib2.URLError as e:
if retry >= (self._maxtries - 1):
raise
......@@ -468,7 +468,7 @@ class Rietveld(object):
logging.error('Caught urllib2.URLError %s which wasn\'t deemed '
'transient', e.reason)
raise
except socket.error, e:
except socket.error as e:
if retry >= (self._maxtries - 1):
raise
if not 'timed out' in str(e):
......
......@@ -140,7 +140,7 @@ class SuperMoxTestBase(TestCaseUtils, StdoutCheck, mox.MoxTestBase):
if hasattr(parent, item):
try:
self.mox.StubOutWithMock(parent, item)
except TypeError, e:
except TypeError as e:
raise TypeError(
'Couldn\'t mock %s in %s: %s' % (item, parent.__name__, e))
......
......@@ -131,7 +131,7 @@ class BaseTest(fake_repos.FakeReposTestBase):
try:
co.apply_patch([patch.FilePatchDiff('chrome/file.cc', BAD_PATCH, [])])
self.fail()
except checkout.PatchApplicationFailed, e:
except checkout.PatchApplicationFailed as e:
self.assertEquals(e.filename, 'chrome/file.cc')
self.assertEquals(e.status, err_msg)
......
......@@ -50,7 +50,7 @@ class GCBaseTestCase(object):
"""Like unittest's assertRaises() but checks for Gclient.Error."""
try:
fn(*args, **kwargs)
except gclient_scm.gclient_utils.Error, e:
except gclient_scm.gclient_utils.Error as e:
self.assertEquals(e.args[0], msg)
else:
self.fail('%s not raised' % msg)
......
......@@ -1105,7 +1105,7 @@ class GclientTest(trial_dir.TestCase):
try:
obj.RunOnDeps('None', [])
self.fail()
except gclient_utils.Error, e:
except gclient_utils.Error as e:
self.assertIn('allowed_hosts must be', str(e))
finally:
self._get_processed()
......@@ -1130,7 +1130,7 @@ class GclientTest(trial_dir.TestCase):
try:
obj.RunOnDeps('None', [])
self.fail()
except gclient_utils.Error, e:
except gclient_utils.Error as e:
self.assertIn('allowed_hosts must be', str(e))
finally:
self._get_processed()
......
......@@ -318,7 +318,7 @@ class OwnersDatabaseTest(_BaseTestCase):
try:
self.db().reviewers_for(['ipc/ipc_message_utils.h'], None)
self.fail() # pragma: no cover
except owners.SyntaxErrorInOwnersFile, e:
except owners.SyntaxErrorInOwnersFile as e:
self.assertTrue(str(e).startswith('/ipc/OWNERS:1'))
def assert_syntax_error(self, owners_file_contents):
......@@ -328,7 +328,7 @@ class OwnersDatabaseTest(_BaseTestCase):
try:
db.reviewers_for(['foo/DEPS'], None)
self.fail() # pragma: no cover
except owners.SyntaxErrorInOwnersFile, e:
except owners.SyntaxErrorInOwnersFile as e:
self.assertTrue(str(e).startswith('/foo/OWNERS:1'))
def test_syntax_error__unknown_token(self):
......
......@@ -416,7 +416,7 @@ class PatchTestFail(unittest.TestCase):
try:
patch.FilePatchDiff('foo', RAW.PATCH, [])
self.fail()
except patch.UnsupportedPatchFormat, e:
except patch.UnsupportedPatchFormat as e:
self.assertEquals(
"Can't process patch for file foo.\nUnexpected diff: chrome/file.cc.",
str(e))
......
......@@ -920,7 +920,7 @@ def CheckChangeOnCommit(input_api, output_api):
try:
presubmit.main(['--root', self.fake_root_dir])
self.fail()
except SystemExit, e:
except SystemExit as e:
self.assertEquals(2, e.code)
......
......@@ -28,7 +28,7 @@ class BaseTestCase(SuperMoxTestBase):
def assertRaisesError(self, msg, fn, *args, **kwargs):
try:
fn(*args, **kwargs)
except scm.gclient_utils.Error, e:
except scm.gclient_utils.Error as e:
self.assertEquals(e.args[0], msg)
else:
self.fail('%s not raised' % msg)
......
......@@ -254,7 +254,7 @@ class RegressionTest(BaseTestCase):
subp.check_output(
e + ['--fail', '--stdout'], universal_newlines=un)
self.fail()
except subp.CalledProcessError, exception:
except subp.CalledProcessError as exception:
self._check_exception(subp, exception, c('A\nBB\nCCC\n'), None, 64)
self._run_test(fn)
......@@ -266,7 +266,7 @@ class RegressionTest(BaseTestCase):
subp.check_output(
e + ['--fail', '--stderr'], universal_newlines=un)
self.fail()
except subp.CalledProcessError, exception:
except subp.CalledProcessError as exception:
self._check_exception(subp, exception, c(''), None, 64)
self._run_test(fn)
......@@ -280,7 +280,7 @@ class RegressionTest(BaseTestCase):
stderr=subp.PIPE,
universal_newlines=un)
self.fail()
except subp.CalledProcessError, exception:
except subp.CalledProcessError as exception:
self._check_exception(subp, exception, '', c('a\nbb\nccc\n'), 64)
self._run_test(fn)
......@@ -294,7 +294,7 @@ class RegressionTest(BaseTestCase):
stderr=subp.STDOUT,
universal_newlines=un)
self.fail()
except subp.CalledProcessError, exception:
except subp.CalledProcessError as exception:
self._check_exception(subp, exception, c('a\nbb\nccc\n'), None, 64)
self._run_test(fn)
......@@ -303,7 +303,7 @@ class RegressionTest(BaseTestCase):
try:
subp.check_call(self.exe + ['--fail', '--stderr'])
self.fail()
except subp.CalledProcessError, exception:
except subp.CalledProcessError as exception:
self._check_exception(subp, exception, None, None, 64)
def test_redirect_stderr_to_stdout_pipe(self):
......@@ -515,7 +515,7 @@ class S2Test(BaseTestCase):
stderr=stderr.append,
universal_newlines=un)
self.fail()
except subprocess2.CalledProcessError, exception:
except subprocess2.CalledProcessError as exception:
self._check_exception(exception, '', None, 64)
self.assertEquals(c('a\nbb\nccc\n'), ''.join(stderr))
self._run_test(fn)
......
......@@ -159,7 +159,7 @@ class UploadTests(unittest.TestCase):
try:
upload_to_google_storage.get_targets([], self.parser, False)
self.fail()
except SystemExit, e:
except SystemExit as e:
self.assertEqual(e.code, 2)
def test_get_targets_passthrough(self):
......
......@@ -62,7 +62,7 @@ class Watchlists(object):
contents = watchlists_file.read()
watchlists_file.close()
return contents
except IOError, e:
except IOError as e:
logging.error("Cannot read %s: %s" % (self._GetRulesFilePath(), e))
return ''
......@@ -75,7 +75,7 @@ class Watchlists(object):
watchlists_data = None
try:
watchlists_data = eval(contents, {'__builtins__': None}, None)
except SyntaxError, e:
except SyntaxError as e:
logging.error("Cannot parse %s. %s" % (self._GetRulesFilePath(), e))
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment