diff options
author | Jon Anderson <jon.david.anderson@gmail.com> | 2018-01-27 15:40:33 -0800 |
---|---|---|
committer | Jon Anderson <jon.david.anderson@gmail.com> | 2018-01-27 15:40:33 -0800 |
commit | 623e603481b2516e48c9949218e115968f42c37c (patch) | |
tree | 3209490fdfa4e3018887e3bc836c17589ef14cc9 | |
parent | 43c71f7a938556337bad3ed2ad4b277e730fb969 (diff) | |
download | ranger-623e603481b2516e48c9949218e115968f42c37c.tar.gz |
Added more IOError checks for Python2.
-rwxr-xr-x | ranger/config/commands.py | 17 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 7 |
2 files changed, 24 insertions, 0 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 299f17c2..f11e0e83 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -776,14 +776,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() @@ -799,11 +808,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/ext/img_display.py b/ranger/ext/img_display.py index c55d835e..e4740407 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -306,6 +306,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: |