diff --git a/whipper/common/accurip.py b/whipper/common/accurip.py index 7ddfb41..47b9932 100644 --- a/whipper/common/accurip.py +++ b/whipper/common/accurip.py @@ -193,7 +193,8 @@ def _match_responses(tracks, responses): for i, track in enumerate(tracks): for v in ('v1', 'v2'): if track.AR[v]['CRC'] == r.checksums[i]: - if r.confidences[i] > track.AR[v]['DBConfidence']: + if (track.AR[v]['DBConfidence'] is None or + r.confidences[i] > track.AR[v]['DBConfidence']): track.AR[v]['DBCRC'] = r.checksums[i] track.AR[v]['DBConfidence'] = r.confidences[i] logger.debug( @@ -242,7 +243,8 @@ def print_report(result): track.AR['v2']['DBCRC'] ) if _f]) max_conf = max( - [track.AR[v]['DBConfidence'] for v in ('v1', 'v2')] + [track.AR[v]['DBConfidence'] for v in ('v1', 'v2') + if track.AR[v]['DBConfidence'] is not None], default=None ) if max_conf: if max_conf < track.AR['DBMaxConfidence']: diff --git a/whipper/common/cache.py b/whipper/common/cache.py index 2f94830..d413398 100644 --- a/whipper/common/cache.py +++ b/whipper/common/cache.py @@ -98,7 +98,7 @@ class Persister: if not os.path.exists(self._path): return - handle = open(self._path) + handle = open(self._path, 'rb') import pickle try: diff --git a/whipper/common/config.py b/whipper/common/config.py index 44a701a..8774c86 100644 --- a/whipper/common/config.py +++ b/whipper/common/config.py @@ -44,7 +44,7 @@ class Config: # Open the file with the correct encoding if os.path.exists(self._path): with codecs.open(self._path, 'r', encoding='utf-8') as f: - self._parser.readfp(f) + self._parser.read_file(f) logger.debug('loaded %d sections from config file', len(self._parser.sections())) diff --git a/whipper/common/renamer.py b/whipper/common/renamer.py index d2af230..941b018 100644 --- a/whipper/common/renamer.py +++ b/whipper/common/renamer.py @@ -91,7 +91,7 @@ class Operator: Execute the operations """ - def next(self): + def __next__(self): operation = self._todo[len(self._done)] if self._resuming: operation.redo() @@ -199,7 +199,8 @@ class RenameInFile(Operation): (fd, name) = tempfile.mkstemp(suffix='.whipper') for s in handle: - os.write(fd, s.replace(self._source, self._destination)) + os.write(fd, + s.replace(self._source, self._destination).encode()) os.close(fd) os.rename(name, self._path) diff --git a/whipper/image/table.py b/whipper/image/table.py index cbb2711..131cc47 100644 --- a/whipper/image/table.py +++ b/whipper/image/table.py @@ -220,10 +220,12 @@ class Table: # if on a session border, subtract the session leadin thisTrack = self.tracks[number - 1] nextTrack = self.tracks[number] - if None not in [thisTrack.session, nextTrack.session]: - if nextTrack.session > thisTrack.session: - gap = self._getSessionGap(nextTrack.session) - end -= gap + # The session attribute of a track is None by default (session 1) + # with value > 1 if the track is in another session. Py3 doesn't + # allow NoneType comparisons so we compare against 1 in that case + if int(nextTrack.session or 1) > int(thisTrack.session or 1): + gap = self._getSessionGap(nextTrack.session) + end -= gap return end @@ -286,7 +288,7 @@ class Table: offset = self.getTrackStart(track.number) + delta offsets.append(offset) debug.append(str(offset)) - seconds = offset / common.FRAMES_PER_SECOND + seconds = offset // common.FRAMES_PER_SECOND n += self._cddbSum(seconds) # the 'real' leadout, not offset by 150 frames @@ -389,11 +391,11 @@ class Table: discid = self.getMusicBrainzDiscId() values = self._getMusicBrainzValues() - query = urlencode({ - 'id': discid, - 'toc': ' '.join([str(v) for v in values]), - 'tracks': self.getAudioTracks(), - }) + query = urlencode([ + ('toc', ' '.join([str(v) for v in values])), + ('tracks', self.getAudioTracks()), + ('id', discid), + ]) return urlunparse(( 'https', host, '/cdtoc/attach', '', query, '')) diff --git a/whipper/test/common.py b/whipper/test/common.py index b1ba2e7..a55ee14 100644 --- a/whipper/test/common.py +++ b/whipper/test/common.py @@ -70,7 +70,7 @@ class TestCase(unittest.TestCase): version so we can use it in comparisons. """ cuefile = os.path.join(os.path.dirname(__file__), name) - ret = open(cuefile).read().decode('utf-8') + ret = open(cuefile).read() ret = re.sub( 'REM COMMENT "whipper.*', 'REM COMMENT "whipper %s"' % whipper.__version__, diff --git a/whipper/test/test_command_mblookup.py b/whipper/test/test_command_mblookup.py index ee8d664..c13cb93 100644 --- a/whipper/test/test_command_mblookup.py +++ b/whipper/test/test_command_mblookup.py @@ -16,7 +16,7 @@ class MBLookupTestCase(unittest.TestCase): """Mock function for whipper.common.mbngs.musicbrainz function.""" filename = "whipper.discid.{}.pickle".format(discid) path = os.path.join(os.path.dirname(__file__), filename) - with open(path) as p: + with open(path, "rb") as p: return pickle.load(p) def testMissingReleaseType(self): diff --git a/whipper/test/test_common_accurip.py b/whipper/test/test_common_accurip.py index 9cb1ef2..4b5378b 100644 --- a/whipper/test/test_common_accurip.py +++ b/whipper/test/test_common_accurip.py @@ -2,7 +2,7 @@ # vi:si:et:sw=4:sts=4:ts=4 import sys -from StringIO import StringIO +from io import StringIO from os import chmod, makedirs from os.path import dirname, exists, join from shutil import copy, rmtree @@ -22,7 +22,7 @@ class TestAccurateRipResponse(TestCase): def setUpClass(cls): cls.path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin' cls.entry = _split_responses( - open(join(dirname(__file__), cls.path[6:])).read() + open(join(dirname(__file__), cls.path[6:]), "rb").read() ) cls.other_path = '4/8/2/dBAR-011-0010e284-009228a3-9809ff0b.bin' @@ -101,7 +101,7 @@ class TestVerifyResult(TestCase): def setUpClass(cls): path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin' cls.responses = _split_responses( - open(join(dirname(__file__), path[6:])).read() + open(join(dirname(__file__), path[6:]), "rb").read() ) cls.checksums = { 'v1': ['284fc705', '9cc1f32e'], diff --git a/whipper/test/test_common_mbngs.py b/whipper/test/test_common_mbngs.py index b99a1bc..492f466 100644 --- a/whipper/test/test_common_mbngs.py +++ b/whipper/test/test_common_mbngs.py @@ -18,7 +18,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.c56ff16e-1d81-47de-926f-ba22891bd2bd.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "b.yqPuCBdsV5hrzDvYrw52iK_jE-" @@ -31,7 +31,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.a76714e0-32b1-4ed4-b28e-f86d99642193.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "f7XO36a7n1LCCskkCiulReWbwZA-" @@ -59,7 +59,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.e32ae79a-336e-4d33-945c-8c5e8206dbd3.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "xAq8L4ELMW14.6wI6tt7QAcxiDI-" @@ -93,7 +93,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.61c6fd9b-18f8-4a45-963a-ba3c5d990cae.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "u0aKVpO.59JBy6eQRX2vYcoqQZ0-" @@ -130,7 +130,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.8478d4da-0cda-4e46-ae8c-1eeacfa5cf37.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "RhrwgVb0hZNkabQCw1dZIhdbMFg-" @@ -167,7 +167,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.f484a9fc-db21-4106-9408-bcd105c90047.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "X2c2IQ5vUy5x6Jh7Xi_DGHtA1X8-" @@ -214,7 +214,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.d8e6153a-2c47-4804-9d73-0aac1081c3b1.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "xu338_M8WukSRi0J.KTlDoflB8Y-" # disc 4 @@ -228,7 +228,7 @@ class MetadataTestCase(unittest.TestCase): filename = 'whipper.release.6109ceed-7e21-490b-b5ad-3a66b4e4cfbb.json' path = os.path.join(os.path.dirname(__file__), filename) handle = open(path, "rb") - response = json.loads(handle.read()) + response = json.loads(handle.read().decode('utf-8')) handle.close() discid = "cHW1Uutl_kyWNaLJsLmTGTe4rnE-" diff --git a/whipper/test/test_common_renamer.py b/whipper/test/test_common_renamer.py index bcfb7dc..c33ca07 100644 --- a/whipper/test/test_common_renamer.py +++ b/whipper/test/test_common_renamer.py @@ -13,7 +13,7 @@ class RenameInFileTestcase(unittest.TestCase): def setUp(self): (fd, self._path) = tempfile.mkstemp(suffix='.whipper.renamer.infile') - os.write(fd, 'This is a test\nThis is another\n') + os.write(fd, 'This is a test\nThis is another\n'.encode()) os.close(fd) def testVerify(self): @@ -43,7 +43,7 @@ class RenameFileTestcase(unittest.TestCase): def setUp(self): (fd, self._source) = tempfile.mkstemp(suffix='.whipper.renamer.file') - os.write(fd, 'This is a test\nThis is another\n') + os.write(fd, 'This is a test\nThis is another\n'.encode()) os.close(fd) (fd, self._destination) = tempfile.mkstemp( suffix='.whipper.renamer.file') @@ -87,7 +87,7 @@ class OperatorTestCase(unittest.TestCase): (fd, self._source) = tempfile.mkstemp( suffix='.whipper.renamer.operator') - os.write(fd, 'This is a test\nThis is another\n') + os.write(fd, 'This is a test\nThis is another\n'.encode()) os.close(fd) (fd, self._destination) = tempfile.mkstemp( suffix='.whipper.renamer.operator') diff --git a/whipper/test/test_image_toc.py b/whipper/test/test_image_toc.py index 34293d1..04bf04a 100644 --- a/whipper/test/test_image_toc.py +++ b/whipper/test/test_image_toc.py @@ -364,7 +364,7 @@ class StrokesTestCase(common.TestCase): ref = self._filterCue( open(os.path.join( os.path.dirname(__file__), - 'strokes-someday.eac.cue')).read()).decode('utf-8') + 'strokes-someday.eac.cue')).read()) common.diffStrings(ref, cue) @staticmethod