summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@hut.pm>2018-01-28 19:34:23 +0100
committerhut <hut@hut.pm>2018-01-28 19:34:23 +0100
commit6d2b6ea9055d0b566a3604b906fbd84c65d0bc15 (patch)
tree1ae74dbd2d284cc2514ed4a5a0b4dbe1779c1d0b
parent949dba9c31d8f424f931674762ce005a2606b7f8 (diff)
parent8083eb60c4193ffd34a2e5ade9b364e6669e5d7b (diff)
downloadranger-6d2b6ea9055d0b566a3604b906fbd84c65d0bc15.tar.gz
Merge branch 'master' into v1.9.0
-rwxr-xr-xranger/config/commands.py9
-rw-r--r--ranger/container/file.py3
-rw-r--r--ranger/core/actions.py3
-rw-r--r--ranger/ext/img_display.py6
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