Skip to content

Commit

Permalink
Use 'except Exception:' instead of 'except:'
Browse files Browse the repository at this point in the history
  • Loading branch information
stepshal committed Jun 21, 2016
1 parent 5348e12 commit bedfed3
Show file tree
Hide file tree
Showing 38 changed files with 120 additions and 120 deletions.
4 changes: 2 additions & 2 deletions doc/tools/print_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def print_all_colors(attr):
for c in range(-1, curses.COLORS):
try:
init_pair(c, c, 0)
except:
except Exception:
pass
else:
win.addstr(str(c) + ' ', color_pair(c) | attr)
start_color()
try:
use_default_colors()
except:
except Exception:
pass
win.addstr("available colors: %d\n\n" % curses.COLORS)
print_all_colors(0)
Expand Down
6 changes: 3 additions & 3 deletions ranger/api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def alias(self, name, full_command):
cmd._line = full_command
self.commands[name] = cmd

except:
except Exception:
pass

def load_commands_from_module(self, module):
Expand Down Expand Up @@ -394,13 +394,13 @@ def execute(self):
value = arg if (equal_sign is -1) else arg[equal_sign + 1:]
try:
value = int(value)
except:
except Exception:
if value in ('True', 'False'):
value = (value == 'True')
else:
try:
value = float(value)
except:
except Exception:
pass

if equal_sign == -1:
Expand Down
10 changes: 5 additions & 5 deletions ranger/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def execute(self):
try:
position = int(self.arg(1)[2:])
self.shift()
except:
except Exception:
pass
self.fm.open_console(self.rest(1), position=position)

Expand All @@ -616,7 +616,7 @@ def execute(self):
try:
fname = self.fm.confpath(self.copy_buffer_filename)
f = open(fname, 'r')
except:
except Exception:
return self.fm.notify("Cannot open %s" %
(fname or self.copy_buffer_filename), bad=True)
self.fm.copy_buffer = set(File(g)
Expand All @@ -637,7 +637,7 @@ def execute(self):
try:
fname = self.fm.confpath(self.copy_buffer_filename)
f = open(fname, 'w')
except:
except Exception:
return self.fm.notify("Cannot open %s" %
(fname or self.copy_buffer_filename), bad=True)
f.write("\n".join(f.path for f in self.fm.copy_buffer))
Expand Down Expand Up @@ -846,7 +846,7 @@ def execute(self):
# reloading directory. maybe its better to reload the selected
# files only.
self.fm.thisdir.load_content()
except:
except Exception:
pass


Expand Down Expand Up @@ -1262,7 +1262,7 @@ def _build_regex(self):
options |= re.IGNORECASE
try:
self._regex = re.compile(regex, options)
except:
except Exception:
self._regex = re.compile("")
return self._regex

Expand Down
4 changes: 2 additions & 2 deletions ranger/container/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def save(self):
and key in ALLOWED_KEYS:
try:
f.write("{0}:{1}\n".format(str(key), str(value)))
except:
except Exception:
pass

f.close()
Expand All @@ -179,7 +179,7 @@ def _load_dict(self):
if not os.path.exists(self.path):
try:
f = open(self.path, 'w')
except:
except Exception:
raise OSError('Cannot read the given path')
f.close()

Expand Down
12 changes: 6 additions & 6 deletions ranger/container/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ def load_bit_by_bit(self):
file_stat = file_lstat
stats = (file_stat, file_lstat)
is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
except:
except Exception:
stats = None
is_a_dir = False
if is_a_dir:
try:
item = self.fm.get_directory(name)
item.load_if_outdated()
except:
except Exception:
item = Directory(name, preload=stats, path_is_abs=True,
basename_is_rel_to=basename_is_rel_to)
item.load()
Expand Down Expand Up @@ -442,7 +442,7 @@ def sort(self):

try:
sort_func = self.sort_dict[self.settings.sort]
except:
except Exception:
sort_func = sort_by_basename

if self.settings.sort_case_insensitive and \
Expand Down Expand Up @@ -484,7 +484,7 @@ def _get_cumulative_size(self):
else:
stat = os_stat(dirpath + "/" + file)
cum += stat.st_size
except:
except Exception:
pass
return cum

Expand Down Expand Up @@ -538,7 +538,7 @@ def sort_if_outdated(self):
def move_to_obj(self, arg):
try:
arg = arg.path
except:
except Exception:
pass
self.load_content_once(schedule=False)
if self.empty():
Expand Down Expand Up @@ -587,7 +587,7 @@ def correct_pointer(self):
try:
if self == self.fm.thisdir:
self.fm.thisfile = self.pointed_obj
except:
except Exception:
pass

def load_content_once(self, *a, **k):
Expand Down
4 changes: 2 additions & 2 deletions ranger/container/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ class File(FileSystemObject):
def firstbytes(self):
try:
return self._firstbytes
except:
except Exception:
try:
f = open(self.path, 'r')
self._firstbytes = f.read(N_FIRST_BYTES)
f.close()
return self._firstbytes
except:
except Exception:
pass

def is_binary(self):
Expand Down
12 changes: 6 additions & 6 deletions ranger/container/fsobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ def safe_basename(self):
def user(self):
try:
return getpwuid(self.stat.st_uid)[0]
except:
except Exception:
return str(self.stat.st_uid)

@lazy_property
def group(self):
try:
return getgrgid(self.stat.st_gid)[0]
except:
except Exception:
return str(self.stat.st_gid)

for attr in ('video', 'audio', 'image', 'media', 'document', 'container'):
Expand Down Expand Up @@ -205,15 +205,15 @@ def set_mimetype(self):
def mimetype(self):
try:
return self._mimetype
except:
except Exception:
self.set_mimetype()
return self._mimetype

@property
def mimetype_tuple(self):
try:
return self._mimetype_tuple
except:
except Exception:
self.set_mimetype()
return self._mimetype_tuple

Expand All @@ -230,7 +230,7 @@ def realpath(self):
if self.is_link:
try:
return realpath(self.path)
except:
except Exception:
return None # it is impossible to get the link destination
return self.path

Expand Down Expand Up @@ -264,7 +264,7 @@ def load(self):
if self.is_link:
new_stat = stat(path)
self.exists = True
except:
except Exception:
self.exists = False

# Set some attributes
Expand Down
4 changes: 2 additions & 2 deletions ranger/container/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add(self, item):
if self.unique:
try:
self._history.remove(item)
except:
except Exception:
pass
else:
if self._history and self._history[-1] == item:
Expand All @@ -47,7 +47,7 @@ def modify(self, item, unique=False):
try:
self._history.remove(item)
self._index -= 1
except:
except Exception:
pass
try:
self._history[self._index] = item
Expand Down
4 changes: 2 additions & 2 deletions ranger/container/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get(self, name, path=None):
else:
try:
localpath = self.fm.thisdir.path
except:
except Exception:
localpath = path

if localpath:
Expand Down Expand Up @@ -222,7 +222,7 @@ def _raw_set(self, name, value, path=None, tags=None):
if path not in self._localsettings:
try:
regex = re.compile(path)
except:
except Exception:
# Bad regular expression
return
self._localregexes[path] = regex
Expand Down
26 changes: 13 additions & 13 deletions ranger/core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def reload_cwd(self):
"""
try:
cwd = self.thisdir
except:
except Exception:
pass
else:
cwd.unload()
Expand Down Expand Up @@ -166,7 +166,7 @@ def abort(self):
"""
try:
item = self.loader.queue[0]
except:
except Exception:
self.notify("Type Q or :quit<Enter> to exit ranger")
else:
self.notify("Aborting: " + item.get_description())
Expand Down Expand Up @@ -283,7 +283,7 @@ def _get_macros(self):
for i in range(1, 10):
try:
tab = self.fm.tabs[i]
except:
except Exception:
continue
tabdir = tab.thisdir
if not tabdir:
Expand Down Expand Up @@ -429,7 +429,7 @@ def move(self, narg=None, **kw):
steps *= narg
try:
directory = os.path.join(*(['..'] * steps))
except:
except Exception:
return
self.thistab.enter_dir(directory)
self.change_mode('normal')
Expand All @@ -455,7 +455,7 @@ def move(self, narg=None, **kw):
if self.mode == 'visual':
try:
startpos = cwd.index(self._visual_start)
except:
except Exception:
self._visual_start = None
startpos = min(self._visual_start_pos, len(cwd))
# The files between here and _visual_start_pos
Expand Down Expand Up @@ -690,7 +690,7 @@ def search_file(self, text, offset=1, regexp=True):
if isinstance(text, str) and regexp:
try:
text = re.compile(text, re.L | re.U | re.I)
except:
except Exception:
return False
self.thistab.last_search = text
self.search_next(order='search', offset=offset)
Expand Down Expand Up @@ -819,7 +819,7 @@ def hide_bookmarks(self):
def draw_possible_programs(self):
try:
target = self.thistab.get_selection()[0]
except:
except Exception:
self.ui.browser.draw_info = []
return
programs = [program for program in self.rifle.list_commands([target.path],
Expand All @@ -841,7 +841,7 @@ def hide_console_info(self):
def display_command_help(self, console_widget):
try:
command = console_widget._get_cmd_class()
except:
except Exception:
self.notify("Feature not available!", bad=True)
return

Expand Down Expand Up @@ -893,7 +893,7 @@ def update_preview(self, path):
try:
del self.previews[path]
self.ui.need_redraw = True
except:
except Exception:
return False

if version_info[0] == 3:
Expand Down Expand Up @@ -924,7 +924,7 @@ def get_preview(self, file, width, height):
# PDF file.
try:
data = self.previews[path]
except:
except Exception:
data = self.previews[path] = {'loading': False}
else:
if data['loading']:
Expand All @@ -935,7 +935,7 @@ def get_preview(self, file, width, height):
if found is False:
try:
stat_ = os.stat(self.settings.preview_script)
except:
except Exception:
self.fm.notify("Preview Script `%s' doesn't exist!" %
self.settings.preview_script, bad=True)
return None
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def on_after(signal):
def on_destroy(signal):
try:
del self.previews[path]
except:
except Exception:
pass
loadable.signal_bind('after', on_after)
loadable.signal_bind('destroy', on_destroy)
Expand All @@ -1027,7 +1027,7 @@ def on_destroy(signal):
else:
try:
return codecs.open(path, 'r', errors='ignore')
except:
except Exception:
return None

# --------------------------
Expand Down
Loading

0 comments on commit bedfed3

Please sign in to comment.