summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xranger/config/commands.py20
-rw-r--r--ranger/ext/img_display.py13
2 files changed, 7 insertions, 26 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 3d5340dd..a3837d8e 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -789,16 +789,10 @@ class load_copy_buffer(Command):
         from ranger.container.file import File
         from os.path import exists
         fname = self.fm.datapath(self.copy_buffer_filename)
-        fobj = None
+        unreadable = IOError if sys.version_info[0] < 3 else OSError
         try:
             fobj = open(fname, 'r')
-        except OSError:
-            if sys.version_info[0] < 3:
-                raise
-        except IOError:
-            if sys.version_info[0] >= 3:
-                raise
-        if fobj is None:
+        except unreadable:
             return self.fm.notify(
                 "Cannot open %s" % (fname or self.copy_buffer_filename), bad=True)
 
@@ -820,16 +814,10 @@ class save_copy_buffer(Command):
         import sys
         fname = None
         fname = self.fm.datapath(self.copy_buffer_filename)
-        fobj = None
+        unwritable = IOError if sys.version_info[0] < 3 else OSError
         try:
             fobj = open(fname, 'w')
-        except OSError:
-            if sys.version_info[0] < 3:
-                raise
-        except IOError:
-            if sys.version_info[0] >= 3:
-                raise
-        if fobj is None:
+        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/ext/img_display.py b/ranger/ext/img_display.py
index 0bc9e96e..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,16 +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:
-                if sys.version_info[0] < 3:
-                    raise
-                file_handle.close()
-                return 0, 0
-            except IOError:
-                if sys.version_info[0] >= 3:
-                    raise
-                file_handle.close()
-                return 0, 0
+            except unreadable:
+                height, width = 0, 0
         else:
             file_handle.close()
             return 0, 0