diff options
-rwxr-xr-x | ranger/config/commands.py | 9 | ||||
-rw-r--r-- | ranger/container/file.py | 3 | ||||
-rw-r--r-- | ranger/core/actions.py | 3 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 6 |
4 files changed, 14 insertions, 7 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index d426b72e..a3837d8e 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -785,14 +785,17 @@ class load_copy_buffer(Command): copy_buffer_filename = 'copy_buffer' def execute(self): + import sys from ranger.container.file import File from os.path import exists fname = self.fm.datapath(self.copy_buffer_filename) + unreadable = IOError if sys.version_info[0] < 3 else OSError try: fobj = open(fname, 'r') - except OSError: + except unreadable: return self.fm.notify( "Cannot open %s" % (fname or self.copy_buffer_filename), bad=True) + self.fm.copy_buffer = set(File(g) for g in fobj.read().split("\n") if exists(g)) fobj.close() @@ -808,11 +811,13 @@ class save_copy_buffer(Command): copy_buffer_filename = 'copy_buffer' def execute(self): + import sys fname = None fname = self.fm.datapath(self.copy_buffer_filename) + unwritable = IOError if sys.version_info[0] < 3 else OSError try: fobj = open(fname, 'w') - except OSError: + except unwritable: return self.fm.notify("Cannot open %s" % (fname or self.copy_buffer_filename), bad=True) fobj.write("\n".join(fobj.path for fobj in self.fm.copy_buffer)) diff --git a/ranger/container/file.py b/ranger/container/file.py index d2daa169..6450cfe6 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -57,7 +57,8 @@ class File(FileSystemObject): try: with open(self.path, 'rb') as fobj: self._firstbytes = set(fobj.read(N_FIRST_BYTES)) - except OSError: + # IOError for Python2, OSError for Python3 + except (IOError, OSError): return None return self._firstbytes diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 0298af19..aef0d205 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -978,7 +978,8 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if not self.settings.preview_script or not self.settings.use_preview_script: try: return codecs.open(path, 'r', errors='ignore') - except OSError: + # IOError for Python2, OSError for Python3 + except (IOError, OSError): return None # self.previews is a 2 dimensional dict: diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index 01c739d3..67941e27 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -291,6 +291,7 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): elif image_type == 'gif': width, height = struct.unpack('<HH', file_header[6:10]) elif image_type == 'jpeg': + unreadable = IOError if sys.version_info[0] < 3 else OSError try: file_handle.seek(0) size = 2 @@ -304,9 +305,8 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): size = struct.unpack('>H', file_handle.read(2))[0] - 2 file_handle.seek(1, 1) height, width = struct.unpack('>HH', file_handle.read(4)) - except OSError: - file_handle.close() - return 0, 0 + except unreadable: + height, width = 0, 0 else: file_handle.close() return 0, 0 |