mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[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.
This commit is contained in:
parent
194129c027
commit
8285b226eb
2 changed files with 11 additions and 3 deletions
|
@ -12,6 +12,8 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from deluge.common import PY2
|
||||||
|
|
||||||
|
|
||||||
def is_hidden(filepath):
|
def is_hidden(filepath):
|
||||||
def has_hidden_attribute(filepath):
|
def has_hidden_attribute(filepath):
|
||||||
|
@ -52,7 +54,10 @@ def get_completion_paths(args):
|
||||||
|
|
||||||
def get_subdirs(dirname):
|
def get_subdirs(dirname):
|
||||||
try:
|
try:
|
||||||
return os.walk(dirname).next()[1]
|
if PY2:
|
||||||
|
return os.walk(dirname).__next__[1]
|
||||||
|
else:
|
||||||
|
return next(os.walk(dirname))[1]
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# Invalid dirname
|
# Invalid dirname
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -29,7 +29,7 @@ from gi.repository.Gtk import (
|
||||||
SortType,
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -331,7 +331,10 @@ def load_pickled_state_file(filename):
|
||||||
log.info('Opening %s for load: %s', filename, _filepath)
|
log.info('Opening %s for load: %s', filename, _filepath)
|
||||||
try:
|
try:
|
||||||
with open(_filepath, 'rb') as _file:
|
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:
|
except (IOError, pickle.UnpicklingError) as ex:
|
||||||
log.warning('Unable to load %s: %s', _filepath, ex)
|
log.warning('Unable to load %s: %s', _filepath, ex)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue