Convert except X, T to except X as T

This commit is contained in:
JoeLametta
2018-05-02 08:10:00 +00:00
parent 5f75d41c7b
commit 4280dbfafc
12 changed files with 31 additions and 31 deletions

View File

@@ -169,7 +169,7 @@ class _CD(BaseCommand):
try:
self.program.result.cdparanoiaDefeatsCache = \
self.config.getDefeatsCache(*info)
except KeyError, e:
except KeyError as e:
logger.debug('Got key error: %r' % (e, ))
self.program.result.artist = self.program.metadata \
and self.program.metadata.artist \
@@ -409,7 +409,7 @@ Log files will log the path to tracks relative to this directory.
len(self.itable.tracks),
extra))
break
except Exception, e:
except Exception as e:
logger.debug('Got exception %r on try %d',
e, tries)

View File

@@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
def main():
try:
server = config.Config().get_musicbrainz_server()
except KeyError, e:
except KeyError as e:
sys.stderr.write('whipper: %s\n' % e.message)
sys.exit()
@@ -34,20 +34,20 @@ def main():
try:
cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None)
ret = cmd.do()
except SystemError, e:
except SystemError as e:
sys.stderr.write('whipper: error: %s\n' % e)
if (type(e) is common.EjectError and
cmd.options.eject in ('failure', 'always')):
eject_device(e.device)
return 255
except RuntimeError, e:
except RuntimeError as e:
print(e)
return 1
except KeyboardInterrupt:
return 2
except ImportError, e:
except ImportError as e:
raise
except task.TaskException, e:
except task.TaskException as e:
if isinstance(e.exception, ImportError):
raise ImportError(e.exception)
elif isinstance(e.exception, common.MissingDependencyException):

View File

@@ -120,7 +120,7 @@ CD in the AccurateRip database."""
sys.stdout.write('Trying read offset %d ...\n' % offset)
try:
archecksums = self._arcs(runner, table, 1, offset)
except task.TaskException, e:
except task.TaskException as e:
# let MissingDependency fall through
if isinstance(e.exception,
@@ -153,7 +153,7 @@ CD in the AccurateRip database."""
for track in range(2, (len(table.tracks) + 1) - 1):
try:
archecksums = self._arcs(runner, table, track, offset)
except task.TaskException, e:
except task.TaskException as e:
if isinstance(e.exception, cdparanoia.FileSizeError):
sys.stdout.write(
'WARNING: cannot rip with offset %d...\n' %

View File

@@ -156,7 +156,7 @@ def _save_entry(raw_entry, path):
# XXX: os.makedirs(exist_ok=True) in py3
try:
makedirs(dirname(path))
except OSError, e:
except OSError as e:
if e.errno != EEXIST:
logger.error('could not save entry to %s: %r' % (path, str(e)))
return

View File

@@ -127,7 +127,7 @@ class PersistedCache:
self.path = path
try:
os.makedirs(self.path)
except OSError, e:
except OSError as e:
if e.errno != 17: # FIXME
raise

View File

@@ -298,7 +298,7 @@ class VersionGetter(object):
vre = self._regexp.search(output)
if vre:
version = self._expander % vre.groupdict()
except OSError, e:
except OSError as e:
import errno
if e.errno == errno.ENOENT:
raise MissingDependencyException(self._dep)

View File

@@ -277,7 +277,7 @@ def musicbrainz(discid, country=None, record=False):
try:
result = musicbrainzngs.get_releases_by_discid(
discid, includes=["artists", "recordings", "release-groups"])
except musicbrainzngs.ResponseError, e:
except musicbrainzngs.ResponseError as e:
if isinstance(e.cause, urllib2.HTTPError):
if e.cause.code == 404:
raise NotFoundException(e)

View File

@@ -252,7 +252,7 @@ class Program:
if code == 200:
return md['title']
except IOError, e:
except IOError as e:
# FIXME: for some reason errno is a str ?
if e.errno == 'socket error':
self._stdout.write("Warning: network error: %r\n" % (e, ))
@@ -283,13 +283,13 @@ class Program:
country=country,
record=self._record)
break
except mbngs.NotFoundException, e:
except mbngs.NotFoundException as e:
logger.warning("release not found: %r" % (e, ))
break
except musicbrainzngs.NetworkError, e:
except musicbrainzngs.NetworkError as e:
logger.warning("network error: %r" % (e, ))
break
except mbngs.MusicBrainzException, e:
except mbngs.MusicBrainzException as e:
logger.warning("musicbrainz exception: %r" % (e, ))
time.sleep(5)
continue
@@ -424,7 +424,7 @@ class Program:
title = track.title
mbidTrack = track.mbid
mbidTrackArtist = track.mbidArtist
except IndexError, e:
except IndexError as e:
print('ERROR: no track %d found, %r' % (number, e))
raise
else:
@@ -478,7 +478,7 @@ class Program:
try:
runner.run(t)
except task.TaskException, e:
except task.TaskException as e:
if isinstance(e.exception, common.MissingFrames):
logger.warning('missing frames for %r' % trackResult.filename)
return False

View File

@@ -44,7 +44,7 @@ class PopenTask(task.Task):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True, cwd=self.cwd)
except OSError, e:
except OSError as e:
import errno
if e.errno == errno.ENOENT:
self.commandMissing()
@@ -88,7 +88,7 @@ class PopenTask(task.Task):
return
self._done()
except Exception, e:
except Exception as e:
logger.debug('exception during _read(): %r', str(e))
self.setException(e)
self.stop()

View File

@@ -237,7 +237,7 @@ class Task(LogStub):
method = getattr(l, methodName)
try:
method(self, *args, **kwargs)
except Exception, e:
except Exception as e:
self.setException(e)
@@ -349,7 +349,7 @@ class BaseMultiTask(Task, ITaskListener):
task.start(self.runner)
self.debug('BaseMultiTask.next(): started task %d of %d: %r',
self._task, len(self.tasks), task)
except Exception, e:
except Exception as e:
self.setException(e)
self.debug('Got exception during next: %r', self.exceptionMessage)
self.stop()
@@ -502,7 +502,7 @@ class SyncRunner(TaskRunner, ITaskListener):
try:
self.debug('start task %r' % task)
task.start(self)
except Exception, e:
except Exception as e:
# getExceptionMessage uses global exception state that doesn't
# hang around, so store the message
task.setException(e)
@@ -516,7 +516,7 @@ class SyncRunner(TaskRunner, ITaskListener):
callable, args, kwargs)
callable(*args, **kwargs)
return False
except Exception, e:
except Exception as e:
self.debug('exception when calling scheduled callable %r',
callable)
task.setException(e)

View File

@@ -299,7 +299,7 @@ class ReadTrackTask(task.Task):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True)
except OSError, e:
except OSError as e:
import errno
if e.errno == errno.ENOENT:
raise common.MissingDependencyException('cd-paranoia')
@@ -478,7 +478,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
try:
tmpoutpath = path + u'.part'
open(tmpoutpath, 'wb').close()
except IOError, e:
except IOError as e:
if errno.ENAMETOOLONG != e.errno:
raise
path = common.shrinkPath(path)
@@ -540,7 +540,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
try:
logger.debug('Moving to final path %r', self.path)
os.rename(self._tmppath, self.path)
except Exception, e:
except Exception as e:
logger.debug('Exception while moving to final '
'path %r: %r', self.path, str(e))
self.exception = e
@@ -548,7 +548,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
os.unlink(self._tmppath)
else:
logger.debug('stop: exception %r', self.exception)
except Exception, e:
except Exception as e:
print('WARNING: unhandled exception %r' % (e, ))
task.MultiSeparateTask.stop(self)

View File

@@ -49,9 +49,9 @@ class TestCase(unittest.TestCase):
def failUnlessRaises(self, exception, f, *args, **kwargs):
try:
result = f(*args, **kwargs)
except exception, inst:
except exception as inst:
return inst
except exception, e:
except exception as e:
raise Exception('%s raised instead of %s:\n %s' %
(sys.exec_info()[0], exception.__name__, str(e))
)