From 8285b226eb6bd511268090ea697a55ceb83c49ed Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Thu, 20 Sep 2018 10:12:23 +0100 Subject: [PATCH] [GTK3] Fix Python 3 issues In Python 3 builtin next function instead of the next method. Unpickling with translated strings in state file causes ascii decode error so ensure UTF-8 encoding is specified. --- deluge/path_chooser_common.py | 7 ++++++- deluge/ui/gtk3/common.py | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/deluge/path_chooser_common.py b/deluge/path_chooser_common.py index b84d78ef9..0f93feef6 100644 --- a/deluge/path_chooser_common.py +++ b/deluge/path_chooser_common.py @@ -12,6 +12,8 @@ from __future__ import unicode_literals import os +from deluge.common import PY2 + def is_hidden(filepath): def has_hidden_attribute(filepath): @@ -52,7 +54,10 @@ def get_completion_paths(args): def get_subdirs(dirname): try: - return os.walk(dirname).next()[1] + if PY2: + return os.walk(dirname).__next__[1] + else: + return next(os.walk(dirname))[1] except StopIteration: # Invalid dirname return [] diff --git a/deluge/ui/gtk3/common.py b/deluge/ui/gtk3/common.py index d05ad5d17..ae26ac85f 100644 --- a/deluge/ui/gtk3/common.py +++ b/deluge/ui/gtk3/common.py @@ -29,7 +29,7 @@ from gi.repository.Gtk import ( SortType, ) -from deluge.common import get_pixmap, osx_check, windows_check +from deluge.common import PY2, get_pixmap, osx_check, windows_check log = logging.getLogger(__name__) @@ -331,7 +331,10 @@ def load_pickled_state_file(filename): log.info('Opening %s for load: %s', filename, _filepath) try: with open(_filepath, 'rb') as _file: - state = pickle.load(_file) + if PY2: + state = pickle.load(_file) + else: + state = pickle.load(_file, encoding='utf8') except (IOError, pickle.UnpicklingError) as ex: log.warning('Unable to load %s: %s', _filepath, ex) else: