From a274b4e73789a7f4d40c8ef69eaf1993a3880277 Mon Sep 17 00:00:00 2001 From: Johnny Robeson Date: Fri, 10 Jun 2016 01:58:27 -0400 Subject: [PATCH] read and write the pickled statefile as binary Pickle files should be treated as binary files --- beets/importer.py | 4 ++-- test/test_importer.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index bfaa21a01..ca035dc7d 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -69,7 +69,7 @@ class ImportAbort(Exception): def _open_state(): """Reads the state file, returning a dictionary.""" try: - with open(config['statefile'].as_filename()) as f: + with open(config['statefile'].as_filename(), 'rb') as f: return pickle.load(f) except Exception as exc: # The `pickle` module can emit all sorts of exceptions during @@ -83,7 +83,7 @@ def _open_state(): def _save_state(state): """Writes the state dictionary out to disk.""" try: - with open(config['statefile'].as_filename(), 'w') as f: + with open(config['statefile'].as_filename(), 'wb') as f: pickle.dump(state, f) except IOError as exc: log.error(u'state file could not be written: {0}', exc) diff --git a/test/test_importer.py b/test/test_importer.py index e83f9e89c..8f372e841 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -1341,8 +1341,8 @@ class IncrementalImportTest(unittest.TestCase, TestHelper): def test_invalid_state_file(self): importer = self.create_importer() - with open(self.config['statefile'].as_filename(), 'w') as f: - f.write('000') + with open(self.config['statefile'].as_filename(), 'wb') as f: + f.write(b'000') importer.run() self.assertEqual(len(self.lib.albums()), 1)