git cl upload: stop using deprecated except syntax

The newer form works with python2 and python3.

Review-Url: https://codereview.chromium.org/2076643002
changes/90/365990/1
vapier 9 years ago committed by Commit bot
parent 62d045ce9e
commit 2cc483c1d2

@ -146,7 +146,7 @@ def GetEmail(prompt):
last_email = last_email_file.readline().strip("\n") last_email = last_email_file.readline().strip("\n")
last_email_file.close() last_email_file.close()
prompt += " [%s]" % last_email prompt += " [%s]" % last_email
except IOError, e: except IOError as e:
pass pass
email = raw_input(prompt + ": ").strip() email = raw_input(prompt + ": ").strip()
if email: if email:
@ -154,7 +154,7 @@ def GetEmail(prompt):
last_email_file = open(last_email_file_name, "w") last_email_file = open(last_email_file_name, "w")
last_email_file.write(email) last_email_file.write(email)
last_email_file.close() last_email_file.close()
except IOError, e: except IOError as e:
pass pass
else: else:
email = last_email email = last_email
@ -288,7 +288,7 @@ class AbstractRpcServer(object):
response_dict = dict(x.split("=") response_dict = dict(x.split("=")
for x in response_body.split("\n") if x) for x in response_body.split("\n") if x)
return response_dict["Auth"] return response_dict["Auth"]
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
if e.code == 403: if e.code == 403:
body = e.read() body = e.read()
response_dict = dict(x.split("=", 1) for x in body.split("\n") if x) response_dict = dict(x.split("=", 1) for x in body.split("\n") if x)
@ -313,7 +313,7 @@ class AbstractRpcServer(object):
(self.host, urllib.urlencode(args))) (self.host, urllib.urlencode(args)))
try: try:
response = self.opener.open(req) response = self.opener.open(req)
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
response = e response = e
if (response.code != 302 or if (response.code != 302 or
response.info()["location"] != continue_location): response.info()["location"] != continue_location):
@ -357,7 +357,7 @@ class AbstractRpcServer(object):
} }
auth_token = self._GetAuthToken(credentials[0], credentials[1], auth_token = self._GetAuthToken(credentials[0], credentials[1],
internal=True) internal=True)
except ClientLoginError, exc: except ClientLoginError as exc:
e = exc e = exc
if e: if e:
print('', file=sys.stderr) print('', file=sys.stderr)
@ -450,7 +450,7 @@ class AbstractRpcServer(object):
response = f.read() response = f.read()
f.close() f.close()
return response return response
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
if tries > 3: if tries > 3:
raise raise
elif e.code in (302, 401, 403): elif e.code in (302, 401, 403):
@ -999,7 +999,7 @@ class VersionControlSystem(object):
[("data", filename, content)]) [("data", filename, content)])
try: try:
response_body = rpc_server.Send(url, body, content_type=ctype) response_body = rpc_server.Send(url, body, content_type=ctype)
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
response_body = ("Failed to upload file for %s. Got %d status code." % response_body = ("Failed to upload file for %s. Got %d status code." %
(filename, e.code)) (filename, e.code))
@ -2069,7 +2069,7 @@ def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
try: try:
response_body = rpc_server.Send(url, body, content_type=ctype) response_body = rpc_server.Send(url, body, content_type=ctype)
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
response_body = ("Failed to upload patch for %s. Got %d status code." % response_body = ("Failed to upload patch for %s. Got %d status code." %
(filename, e.code)) (filename, e.code))
@ -2133,8 +2133,8 @@ def GuessVCSName(options):
out, returncode = RunShellWithReturnCode(command) out, returncode = RunShellWithReturnCode(command)
if returncode == 0: if returncode == 0:
return (vcs_type, out.strip()) return (vcs_type, out.strip())
except OSError, (errcode, message): except OSError as e:
if errcode != errno.ENOENT: # command not found code if e.errno != errno.ENOENT: # command not found code
raise raise
# Mercurial has a command to get the base directory of a repository # Mercurial has a command to get the base directory of a repository

Loading…
Cancel
Save