diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 5699b02..8f10bf8 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -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) diff --git a/whipper/command/main.py b/whipper/command/main.py index b419548..b879435 100644 --- a/whipper/command/main.py +++ b/whipper/command/main.py @@ -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): diff --git a/whipper/command/offset.py b/whipper/command/offset.py index 0b30eb7..39f5844 100644 --- a/whipper/command/offset.py +++ b/whipper/command/offset.py @@ -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' % diff --git a/whipper/common/accurip.py b/whipper/common/accurip.py index ce23758..fea5e4a 100644 --- a/whipper/common/accurip.py +++ b/whipper/common/accurip.py @@ -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 diff --git a/whipper/common/cache.py b/whipper/common/cache.py index 4159df0..d57cb04 100644 --- a/whipper/common/cache.py +++ b/whipper/common/cache.py @@ -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 diff --git a/whipper/common/common.py b/whipper/common/common.py index 51181c1..cb288e7 100644 --- a/whipper/common/common.py +++ b/whipper/common/common.py @@ -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) diff --git a/whipper/common/mbngs.py b/whipper/common/mbngs.py index ed0098c..d0d18e0 100644 --- a/whipper/common/mbngs.py +++ b/whipper/common/mbngs.py @@ -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) diff --git a/whipper/common/program.py b/whipper/common/program.py index d32afc3..42325bd 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -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 diff --git a/whipper/common/task.py b/whipper/common/task.py index 50766b0..f9c39cc 100644 --- a/whipper/common/task.py +++ b/whipper/common/task.py @@ -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() diff --git a/whipper/extern/task/task.py b/whipper/extern/task/task.py index ac5be7a..60c4c85 100644 --- a/whipper/extern/task/task.py +++ b/whipper/extern/task/task.py @@ -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) diff --git a/whipper/program/cdparanoia.py b/whipper/program/cdparanoia.py index 2331ac2..7c72bd7 100644 --- a/whipper/program/cdparanoia.py +++ b/whipper/program/cdparanoia.py @@ -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) diff --git a/whipper/test/common.py b/whipper/test/common.py index 1c3ef20..4e9a43f 100644 --- a/whipper/test/common.py +++ b/whipper/test/common.py @@ -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)) )