diff options
author | toonn <toonn@toonn.io> | 2021-09-01 18:18:11 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2021-09-01 18:40:08 +0200 |
commit | 8ff8a5984fd000179189e7a3f5b8d7d372ed16d4 (patch) | |
tree | 9df1319b1954be72375d70d719d9fd6a6f6931cd /ranger | |
parent | 896475350744d45f25de69c80e690fcddfad8dc2 (diff) | |
download | ranger-8ff8a5984fd000179189e7a3f5b8d7d372ed16d4.tar.gz |
bookmarks: Drop str requirement for bookmarks
In Python 2 they could be unicode objects instead. And if they're not we need to decode them before writing.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/bookmarks.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py index 2287cf25..293bb01a 100644 --- a/ranger/container/bookmarks.py +++ b/ranger/container/bookmarks.py @@ -8,6 +8,7 @@ import re import os from io import open +from ranger import PY3 from ranger.core.shared import FileManagerAware ALLOWED_KEYS = string.ascii_letters + string.digits + "`'" @@ -169,7 +170,8 @@ class Bookmarks(FileManagerAware): def save(self): """Save the bookmarks to the bookmarkfile. - This is done automatically after every modification if autosave is True.""" + This is done automatically after every modification if autosave is True. + """ self.update() if self.path is None: return @@ -178,9 +180,12 @@ class Bookmarks(FileManagerAware): try: with open(path_new, 'w', encoding="utf-8") as fobj: for key, value in self.dct.items(): - if isinstance(key, str) and key in ALLOWED_KEYS \ + if key in ALLOWED_KEYS \ and key not in self.nonpersistent_bookmarks: - fobj.write("{0}:{1}\n".format(str(key), str(value))) + key_value = "{0}:{1}\n".format(key, value) + if not PY3 and isinstance(key_value, str): + key_value = key_value.decode("utf-8") + fobj.write(key_value) except OSError as ex: self.fm.notify('Bookmarks error: {0}'.format(str(ex)), bad=True) return |