From f359662cf3101c5c3ca7ea4b05d8a823a352eb5b Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 24 Apr 2022 19:41:55 +0200 Subject: [PATCH] No longer catching BaseExceptions --- maloja/__main__.py | 6 +++--- maloja/apis/_base.py | 6 +++--- maloja/apis/audioscrobbler.py | 2 +- maloja/apis/audioscrobbler_legacy.py | 2 +- maloja/apis/listenbrainz.py | 10 +++++----- maloja/database/__init__.py | 8 ++++---- maloja/database/dbcache.py | 4 ++-- maloja/dev/profiler.py | 2 +- maloja/images.py | 4 ++-- maloja/jinjaenv/filters.py | 2 +- maloja/malojatime.py | 4 ++-- maloja/malojauri.py | 2 +- maloja/pkg_global/conf.py | 2 +- maloja/pkg_global/monkey.py | 8 ++++---- maloja/thirdparty/__init__.py | 2 +- maloja/thirdparty/musicbrainz.py | 2 +- maloja/upgrade.py | 2 +- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/maloja/__main__.py b/maloja/__main__.py index ff24c60..11d84c6 100644 --- a/maloja/__main__.py +++ b/maloja/__main__.py @@ -30,13 +30,13 @@ def print_header_info(): def get_instance(): try: return int(subprocess.check_output(["pidof","maloja"])) - except: + except Exception: return None def get_instance_supervisor(): try: return int(subprocess.check_output(["pidof","maloja_supervisor"])) - except: + except Exception: return None def restart(): @@ -62,7 +62,7 @@ def start(): print("\t" + col["blue"]("http://localhost:" + str(port))) print("\t" + col["blue"]("http://localhost:" + str(port) + "/admin_setup")) return True - except: + except Exception: print("Error while starting Maloja.") return False diff --git a/maloja/apis/_base.py b/maloja/apis/_base.py index 938c701..d81232e 100644 --- a/maloja/apis/_base.py +++ b/maloja/apis/_base.py @@ -62,7 +62,7 @@ class APIHandler: try: response.status,result = self.handle(path,keys) - except: + except Exception: exceptiontype = sys.exc_info()[0] if exceptiontype in self.errors: response.status,result = self.errors[exceptiontype] @@ -82,7 +82,7 @@ class APIHandler: try: methodname = self.get_method(path,keys) method = self.methods[methodname] - except: + except Exception: log("Could not find a handler for method " + str(methodname) + " in API " + self.__apiname__,module="debug") log("Keys: " + str(keys),module="debug") raise InvalidMethodException() @@ -94,5 +94,5 @@ class APIHandler: # fixing etc is handled by the main scrobble function try: return database.incoming_scrobble(rawscrobble,api=self.__apiname__,client=client) - except: + except Exception: raise ScrobblingException() diff --git a/maloja/apis/audioscrobbler.py b/maloja/apis/audioscrobbler.py index 586f2c5..6699618 100644 --- a/maloja/apis/audioscrobbler.py +++ b/maloja/apis/audioscrobbler.py @@ -76,7 +76,7 @@ class Audioscrobbler(APIHandler): #(artists,title) = cla.fullclean(artiststr,titlestr) try: timestamp = int(keys["timestamp"]) - except: + except Exception: timestamp = None #database.createScrobble(artists,title,timestamp) self.scrobble({'track_artists':[artiststr],'track_title':titlestr,'scrobble_time':timestamp},client=client) diff --git a/maloja/apis/audioscrobbler_legacy.py b/maloja/apis/audioscrobbler_legacy.py index 322fe78..2a3ac33 100644 --- a/maloja/apis/audioscrobbler_legacy.py +++ b/maloja/apis/audioscrobbler_legacy.py @@ -80,7 +80,7 @@ class AudioscrobblerLegacy(APIHandler): artiststr,titlestr = keys[artist_key], keys[track_key] try: timestamp = int(keys[time_key]) - except: + except Exception: timestamp = None #database.createScrobble(artists,title,timestamp) self.scrobble({ diff --git a/maloja/apis/listenbrainz.py b/maloja/apis/listenbrainz.py index 3ba5fa9..129b581 100644 --- a/maloja/apis/listenbrainz.py +++ b/maloja/apis/listenbrainz.py @@ -34,7 +34,7 @@ class Listenbrainz(APIHandler): def submit(self,pathnodes,keys): try: token = self.get_token_from_request_keys(keys) - except: + except Exception: raise BadAuthException() client = apikeystore.check_and_identify_key(token) @@ -45,7 +45,7 @@ class Listenbrainz(APIHandler): try: listentype = keys["listen_type"] payload = keys["payload"] - except: + except Exception: raise MalformedJSONException() if listentype == "playing_now": @@ -57,9 +57,9 @@ class Listenbrainz(APIHandler): artiststr, titlestr = metadata["artist_name"], metadata["track_name"] try: timestamp = int(listen["listened_at"]) - except: + except Exception: timestamp = None - except: + except Exception: raise MalformedJSONException() self.scrobble({ @@ -74,7 +74,7 @@ class Listenbrainz(APIHandler): def validate_token(self,pathnodes,keys): try: token = self.get_token_from_request_keys(keys) - except: + except Exception: raise BadAuthException() if not apikeystore.check_key(token): raise InvalidAuthException() diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index bc64584..27c8cf0 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -319,7 +319,7 @@ def get_top_artists(dbconn=None,**keys): try: res = get_charts_artists(timerange=rng,dbconn=dbconn)[0] results.append({"range":rng,"artist":res["artist"],"scrobbles":res["scrobbles"]}) - except: + except Exception: results.append({"range":rng,"artist":None,"scrobbles":0}) return results @@ -335,7 +335,7 @@ def get_top_tracks(dbconn=None,**keys): try: res = get_charts_tracks(timerange=rng,dbconn=dbconn)[0] results.append({"range":rng,"track":res["track"],"scrobbles":res["scrobbles"]}) - except: + except Exception: results.append({"range":rng,"track":None,"scrobbles":0}) return results @@ -367,7 +367,7 @@ def artist_info(dbconn=None,**keys): "topweeks":len([e for e in cached.weekly_topartists if e == artist_id]), "id":artist_id } - except: + except Exception: # if the artist isnt in the charts, they are not being credited and we # need to show information about the credited one replaceartist = sqldb.get_credited_artists(artist)[0] @@ -443,7 +443,7 @@ def get_predefined_rulesets(dbconn=None): else: name = rawf.split("_")[1] desc = line2.replace("# DESC: ","") if "# DESC: " in line2 else "" author = rawf.split("_")[0] - except: + except Exception: continue ruleset = {"file":rawf} diff --git a/maloja/database/dbcache.py b/maloja/database/dbcache.py index 812daaa..02399f8 100644 --- a/maloja/database/dbcache.py +++ b/maloja/database/dbcache.py @@ -147,10 +147,10 @@ else: def serialize(obj): try: return serialize(obj.hashable()) - except: + except Exception: try: return json.dumps(obj) - except: + except Exception: if isinstance(obj, (list, tuple, set)): return "[" + ",".join(serialize(o) for o in obj) + "]" elif isinstance(obj,dict): diff --git a/maloja/dev/profiler.py b/maloja/dev/profiler.py index 7fb3355..8d41455 100644 --- a/maloja/dev/profiler.py +++ b/maloja/dev/profiler.py @@ -32,7 +32,7 @@ def profile(func): if FULL_PROFILE: try: pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats")) - except: + except Exception: pass return result diff --git a/maloja/images.py b/maloja/images.py index 99c40a4..80802ed 100644 --- a/maloja/images.py +++ b/maloja/images.py @@ -94,7 +94,7 @@ def dl_image(url): uri = datauri.DataURI.make(mime,charset='ascii',base64=True,data=data) log(f"Downloaded {url} for local caching") return uri - except: + except Exception: log(f"Image {url} could not be downloaded for local caching") return None @@ -260,7 +260,7 @@ def local_files(artist=None,artists=None,title=None): for f in os.listdir(data_dir['images'](purename)): if f.split(".")[-1] in ["png","jpg","jpeg","gif"]: images.append("/images/" + purename + "/" + f) - except: + except Exception: pass return images diff --git a/maloja/jinjaenv/filters.py b/maloja/jinjaenv/filters.py index 0e94c25..8119178 100644 --- a/maloja/jinjaenv/filters.py +++ b/maloja/jinjaenv/filters.py @@ -13,7 +13,7 @@ def find_representative(sequence,attribute_id,attribute_count): newsequence = [e for e in newsequence if e[attribute_count] == max(el[attribute_count] for el in newsequence)] return newsequence[0] - except: + except Exception: return None finally: for e in newsequence: diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 2a53527..c28e744 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -430,7 +430,7 @@ def time_fix(t): try: t = [int(p) for p in t] return MTRangeGregorian(t[:3]) - except: + except Exception: pass if isinstance(t[1],str) and t[1].startswith("w"): @@ -438,7 +438,7 @@ def time_fix(t): year = int(t[0]) weeknum = int(t[1][1:]) return MTRangeWeek(year=year,week=weeknum) - except: + except Exception: raise diff --git a/maloja/malojauri.py b/maloja/malojauri.py index d93caeb..6b1af6d 100644 --- a/maloja/malojauri.py +++ b/maloja/malojauri.py @@ -146,7 +146,7 @@ def remove_identical(*dicts): try: #multidicts for v in d.getall(k): keys.append(k,v) - except: #normaldicts + except Exception: #normaldicts v = d.get(k) keys.append(k,v) diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index d6746de..d29fadc 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -28,7 +28,7 @@ def is_dir_usable(pth): os.mknod(pthj(pth,".test")) os.remove(pthj(pth,".test")) return True - except: + except Exception: return False def get_env_vars(key,pathsuffix=[]): diff --git a/maloja/pkg_global/monkey.py b/maloja/pkg_global/monkey.py index f4780b4..78a68b4 100644 --- a/maloja/pkg_global/monkey.py +++ b/maloja/pkg_global/monkey.py @@ -11,21 +11,21 @@ try: from simplejson import JSONEncoder JSONEncoder._olddefault = JSONEncoder.default JSONEncoder.default = newdefault -except: +except Exception: pass try: from json import JSONEncoder JSONEncoder._olddefault = JSONEncoder.default JSONEncoder.default = newdefault -except: +except Exception: pass try: from ujson import JSONEncoder JSONEncoder._olddefault = JSONEncoder.default JSONEncoder.default = newdefault -except: +except Exception: pass @@ -51,7 +51,7 @@ class expandeddate(date): def fromchrcalendar(cls,y,w,d): try: return datetime.date.fromisocalendar(y,w,d) - timedelta(days=1) #sunday instead of monday - except: + except Exception: # pre python3.8 compatibility firstdayofyear = datetime.date(y,1,1) diff --git a/maloja/thirdparty/__init__.py b/maloja/thirdparty/__init__.py index 311b076..135d792 100644 --- a/maloja/thirdparty/__init__.py +++ b/maloja/thirdparty/__init__.py @@ -230,7 +230,7 @@ class MetadataInterface(GenericInterface,abstract=True): for node in self.metadata[resp]: try: res = res[node] - except: + except Exception: return None return res diff --git a/maloja/thirdparty/musicbrainz.py b/maloja/thirdparty/musicbrainz.py index c100d3f..3dde429 100644 --- a/maloja/thirdparty/musicbrainz.py +++ b/maloja/thirdparty/musicbrainz.py @@ -57,7 +57,7 @@ class MusicBrainz(MetadataInterface): if imgurl is not None: imgurl = self.postprocess_url(imgurl) return imgurl - except: + except Exception: return None finally: time.sleep(2) diff --git a/maloja/upgrade.py b/maloja/upgrade.py index 75213da..67d1176 100644 --- a/maloja/upgrade.py +++ b/maloja/upgrade.py @@ -37,7 +37,7 @@ def upgrade_apikeys(): for key,identifier in entries: _apikeys.apikeystore[identifier] = key os.remove(oldfile) - except: + except Exception: pass