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:50:54 -0800 |
commit | 65b8a3817fe988bc00f530d6859dbb39f1ce99eb (patch) | |
tree | 1b5937a85a2a1d2e6412e636f9b7533deaf2e673 | |
parent | 8e24016afb0c12cfb181dbec11ccbaa5986cd9e9 (diff) | |
download | ranger-65b8a3817fe988bc00f530d6859dbb39f1ce99eb.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 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/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: |