summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@hut.pm>2018-01-28 19:32:23 +0100
committerhut <hut@hut.pm>2018-01-28 19:32:23 +0100
commit90d1dca8807afbf956f19534ebbdf3ca5c3dfbb9 (patch)
treec332c1e3bb6e9aa7ea141caac65635994d6af25b
parentae9d47ea9284ebd4cec4f30e832ee67c1c7a13b9 (diff)
parent976d4803d7481c2947fafd34aa20213203564c3b (diff)
downloadranger-90d1dca8807afbf956f19534ebbdf3ca5c3dfbb9.tar.gz
Merge remote-tracking branch 'chronzerg/master'
-rwxr-xr-xranger/config/commands.py17
-rw-r--r--ranger/container/file.py3
-rw-r--r--ranger/core/actions.py3
-rw-r--r--ranger/ext/img_display.py7
4 files changed, 28 insertions, 2 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index d426b72e..3d5340dd 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -785,14 +785,23 @@ 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)
+        fobj = None
         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:
             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 +817,19 @@ 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)
+        fobj = None
         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:
             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..0bc9e96e 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -305,6 +305,13 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware):
                 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
         else: