Use modern Python exception syntax

"except Exception as e" instead of "except Exception, e"

This is part of a transition to supporting Python 3.  Python >= 2.6
support "as" syntax.

Note: this removes Python 2.5 support.

Change-Id: I309599f3981bba2b46111c43102bee38ff132803
This commit is contained in:
Sarah Owens 2012-09-09 15:37:57 -07:00
parent 9ed12c5d9c
commit a5be53f9c8
10 changed files with 32 additions and 32 deletions

View File

@ -91,7 +91,7 @@ least one of these before using this command."""
try:
rc = subprocess.Popen(args, shell=shell).wait()
except OSError, e:
except OSError as e:
raise EditorError('editor failed, %s: %s %s'
% (str(e), editor, path))
if rc != 0:

View File

@ -217,7 +217,7 @@ class GitCommand(object):
stdin = stdin,
stdout = stdout,
stderr = stderr)
except Exception, e:
except Exception as e:
raise GitError('%s: %s' % (command[1], e))
if ssh_proxy:

View File

@ -449,7 +449,7 @@ def _open_ssh(host, port=None):
try:
Trace(': %s', ' '.join(command))
p = subprocess.Popen(command)
except Exception, e:
except Exception as e:
_ssh_master = False
print >>sys.stderr, \
'\nwarn: cannot enable ssh control master for %s:%s\n%s' \
@ -592,9 +592,9 @@ class Remote(object):
else:
host, port = info.split()
self._review_url = self._SshReviewUrl(userEmail, host, port)
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
raise UploadError('%s: %s' % (self.review, str(e)))
except urllib2.URLError, e:
except urllib2.URLError as e:
raise UploadError('%s: %s' % (self.review, str(e)))
REVIEW_CACHE[u] = self._review_url

10
main.py
View File

@ -146,13 +146,13 @@ class _Repo(object):
else:
print >>sys.stderr, 'real\t%dh%dm%.3fs' \
% (hours, minutes, seconds)
except DownloadError, e:
except DownloadError as e:
print >>sys.stderr, 'error: %s' % str(e)
return 1
except ManifestInvalidRevisionError, e:
except ManifestInvalidRevisionError as e:
print >>sys.stderr, 'error: %s' % str(e)
return 1
except NoSuchProjectError, e:
except NoSuchProjectError as e:
if e.name:
print >>sys.stderr, 'error: project %s not found' % e.name
else:
@ -390,14 +390,14 @@ def _Main(argv):
close_ssh()
except KeyboardInterrupt:
result = 1
except RepoChangedException, rce:
except RepoChangedException as rce:
# If repo changed, re-exec ourselves.
#
argv = list(sys.argv)
argv.extend(rce.extra_args)
try:
os.execv(__file__, argv)
except OSError, e:
except OSError as e:
print >>sys.stderr, 'fatal: cannot restart repo after upgrade'
print >>sys.stderr, 'fatal: %s' % e
result = 128

View File

@ -336,7 +336,7 @@ class XmlManifest(object):
# tricky. actual parsing implementation may vary.
except (KeyboardInterrupt, RuntimeError, SystemExit):
raise
except Exception, e:
except Exception as e:
raise ManifestParseError(
"failed parsing included manifest %s: %s", (name, e))
else:

View File

@ -1044,7 +1044,7 @@ class Project(object):
try:
self._Checkout(revid, quiet=True)
except GitError, e:
except GitError as e:
syncbuf.fail(self, e)
return
self._CopyFiles()
@ -1066,7 +1066,7 @@ class Project(object):
branch.name)
try:
self._Checkout(revid, quiet=True)
except GitError, e:
except GitError as e:
syncbuf.fail(self, e)
return
self._CopyFiles()
@ -1151,7 +1151,7 @@ class Project(object):
try:
self._ResetHard(revid)
self._CopyFiles()
except GitError, e:
except GitError as e:
syncbuf.fail(self, e)
return
else:
@ -1723,7 +1723,7 @@ class Project(object):
continue
try:
os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
except OSError, e:
except OSError as e:
if e.errno == errno.EPERM:
raise GitError('filesystem must support symlinks')
else:
@ -1786,7 +1786,7 @@ class Project(object):
os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
else:
raise GitError('cannot overwrite a local work tree')
except OSError, e:
except OSError as e:
if e.errno == errno.EPERM:
raise GitError('filesystem must support symlinks')
else:

20
repo
View File

@ -185,7 +185,7 @@ def _Init(args):
if not os.path.isdir(repodir):
try:
os.mkdir(repodir)
except OSError, e:
except OSError as e:
print >>sys.stderr, \
'fatal: cannot make %s directory: %s' % (
repodir, e.strerror)
@ -221,7 +221,7 @@ def _CheckGitVersion():
cmd = [GIT, '--version']
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
except OSError, e:
except OSError as e:
print >>sys.stderr
print >>sys.stderr, "fatal: '%s' is not available" % GIT
print >>sys.stderr, 'fatal: %s' % e
@ -268,7 +268,7 @@ def _SetupGnuPG(quiet):
if not os.path.isdir(home_dot_repo):
try:
os.mkdir(home_dot_repo)
except OSError, e:
except OSError as e:
print >>sys.stderr, \
'fatal: cannot make %s directory: %s' % (
home_dot_repo, e.strerror)
@ -277,7 +277,7 @@ def _SetupGnuPG(quiet):
if not os.path.isdir(gpg_dir):
try:
os.mkdir(gpg_dir, 0700)
except OSError, e:
except OSError as e:
print >>sys.stderr, \
'fatal: cannot make %s directory: %s' % (
gpg_dir, e.strerror)
@ -291,7 +291,7 @@ def _SetupGnuPG(quiet):
proc = subprocess.Popen(cmd,
env = env,
stdin = subprocess.PIPE)
except OSError, e:
except OSError as e:
if not quiet:
print >>sys.stderr, 'warning: gpg (GnuPG) is not available.'
print >>sys.stderr, 'warning: Installing it is strongly encouraged.'
@ -392,13 +392,13 @@ def _DownloadBundle(url, local, quiet):
try:
try:
r = urllib2.urlopen(url)
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if e.code == 404:
return False
print >>sys.stderr, 'fatal: Cannot get %s' % url
print >>sys.stderr, 'fatal: HTTP error %s' % e.code
raise CloneFailure()
except urllib2.URLError, e:
except urllib2.URLError as e:
print >>sys.stderr, 'fatal: Cannot get %s' % url
print >>sys.stderr, 'fatal: error %s' % e.reason
raise CloneFailure()
@ -427,7 +427,7 @@ def _Clone(url, local, quiet):
"""
try:
os.mkdir(local)
except OSError, e:
except OSError as e:
print >>sys.stderr, \
'fatal: cannot make %s directory: %s' \
% (local, e.strerror)
@ -436,7 +436,7 @@ def _Clone(url, local, quiet):
cmd = [GIT, 'init', '--quiet']
try:
proc = subprocess.Popen(cmd, cwd = local)
except OSError, e:
except OSError as e:
print >>sys.stderr
print >>sys.stderr, "fatal: '%s' is not available" % GIT
print >>sys.stderr, 'fatal: %s' % e
@ -699,7 +699,7 @@ def main(orig_args):
me.extend(extra_args)
try:
os.execv(repo_main, me)
except OSError, e:
except OSError as e:
print >>sys.stderr, "fatal: unable to start %s" % repo_main
print >>sys.stderr, "fatal: %s" % e
sys.exit(148)

View File

@ -207,7 +207,7 @@ to update the working directory files.
try:
self.manifest.Link(name)
except ManifestParseError, e:
except ManifestParseError as e:
print >>sys.stderr, "fatal: manifest '%s' not available" % name
print >>sys.stderr, 'fatal: %s' % str(e)
sys.exit(1)

View File

@ -417,7 +417,7 @@ uncommitted changes are present' % project.relpath
# in the .netrc file.
print >>sys.stderr, 'No credentials found for %s in .netrc' % \
parse_result.hostname
except netrc.NetrcParseError, e:
except netrc.NetrcParseError as e:
print >>sys.stderr, 'Error parsing .netrc file: %s' % e
if (username and password):
@ -464,11 +464,11 @@ uncommitted changes are present' % project.relpath
else:
print >>sys.stderr, 'error: %s' % manifest_str
sys.exit(1)
except (socket.error, IOError, xmlrpclib.Fault), e:
except (socket.error, IOError, xmlrpclib.Fault) as e:
print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%s' % (
self.manifest.manifest_server, e)
sys.exit(1)
except xmlrpclib.ProtocolError, e:
except xmlrpclib.ProtocolError as e:
print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%d %s' % (
self.manifest.manifest_server, e.errcode, e.errmsg)
sys.exit(1)

View File

@ -329,7 +329,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft)
branch.uploaded = True
except UploadError, e:
except UploadError as e:
branch.error = e
branch.uploaded = False
have_errors = True
@ -384,7 +384,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
pending_proj_names = [project.name for (project, avail) in pending]
try:
hook.Run(opt.allow_all_hooks, project_list=pending_proj_names)
except HookError, e:
except HookError as e:
print >>sys.stderr, "ERROR: %s" % str(e)
return