Fix open() and pickle encoding for py3k
This commit is contained in:
parent
8dae070215
commit
784ace189b
|
@ -19,6 +19,7 @@
|
|||
# MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
import mimetypes
|
||||
import urllib
|
||||
|
@ -169,11 +170,18 @@ class Session(lt.session):
|
|||
return
|
||||
|
||||
try:
|
||||
if sys.hexversion >= 0x030000F0:
|
||||
pkl_file = open(torrents_path, 'rb', encoding="utf-8")
|
||||
else:
|
||||
pkl_file = open(torrents_path, 'rb')
|
||||
except IOError:
|
||||
self.log.warning("Could not open the list of torrents.")
|
||||
else:
|
||||
try:
|
||||
if sys.hexversion >= 0x030000F0:
|
||||
torrents = cPickle.load(
|
||||
pkl_file, fix_imports=True, encoding="utf-8")
|
||||
else:
|
||||
torrents = cPickle.load(pkl_file)
|
||||
except EOFError:
|
||||
self.log.exception("Opening the list of torrents failed.")
|
||||
|
@ -245,6 +253,10 @@ class Session(lt.session):
|
|||
self.log.debug("Handle is invalid, skipping")
|
||||
|
||||
path = os.path.join(save_data_path("epour"), "torrents")
|
||||
if sys.hexversion >= 0x030000F0:
|
||||
with open(path, 'wb', encoding="utf-8") as f:
|
||||
cPickle.dump(self.torrents, f, protocol=2)
|
||||
else:
|
||||
with open(path, 'wb') as f:
|
||||
cPickle.dump(self.torrents, f, protocol=2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue