diff options
author | hut <hut@hut.pm> | 2018-01-28 19:12:36 +0100 |
---|---|---|
committer | hut <hut@hut.pm> | 2018-01-28 19:33:36 +0100 |
commit | 8083eb60c4193ffd34a2e5ade9b364e6669e5d7b (patch) | |
tree | 80f57e7e006790e9ccf0d12c48089512feedf64e /ranger | |
parent | 90d1dca8807afbf956f19534ebbdf3ca5c3dfbb9 (diff) | |
download | ranger-8083eb60c4193ffd34a2e5ade9b364e6669e5d7b.tar.gz |
ext.img_display: cleaner catching of OSError/IOError
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 20 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 13 |
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 |