From 75a3d4bce173b6c37ca7674f6c3f05b4bd852a8f Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Thu, 4 Jan 2018 20:57:24 +0100 Subject: [PATCH] Fix two PEP8 errors --- misc/offsets.py | 14 +++++--------- whipper/common/cache.py | 4 +++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/misc/offsets.py b/misc/offsets.py index d325bd1..53b36ea 100644 --- a/misc/offsets.py +++ b/misc/offsets.py @@ -16,7 +16,8 @@ soup = BeautifulSoup.BeautifulSoup(doc) offsets = {} # offset -> total count -rows = soup.findAll('tr') +# skip first two spurious elements +rows = soup.findAll('tr')[2:] for row in rows: columns = row.findAll('td') if len(columns) == 4: @@ -25,20 +26,15 @@ for row in rows: offset = second.find(text=True) count = third.find(text=True) - # only use sensible offsets + # only use numeric offsets try: int(offset) - except: + except ValueError: continue if offset not in offsets.keys(): offsets[offset] = 0 - # first line is text, so int will fail with ValueError - # purged entries will have None as count, so TypeError - try: - offsets[offset] += int(count) - except (ValueError, TypeError): - pass + offsets[offset] += int(count) # now sort offsets by count counts = [] diff --git a/whipper/common/cache.py b/whipper/common/cache.py index 0c5743c..4159df0 100644 --- a/whipper/common/cache.py +++ b/whipper/common/cache.py @@ -104,9 +104,11 @@ class Persister: try: self.object = pickle.load(handle) logger.debug('loaded persisted object from %r' % self._path) - except: + except Exception as e: + # TODO: restrict kind of caught exceptions? # can fail for various reasons; in that case, pretend we didn't # load it + logger.debug(e) pass def delete(self):