diff --git a/examples/01-web/04-twitter.py b/examples/01-web/04-twitter.py index 9ff29bdc..20e81894 100644 --- a/examples/01-web/04-twitter.py +++ b/examples/01-web/04-twitter.py @@ -22,7 +22,7 @@ # The pd() function returns the parent directory of this script + any given path. table = Datasheet.load(pd("cool.csv")) index = set(table.columns[0]) -except: +except Exception: table = Datasheet() index = set() diff --git a/examples/01-web/11-facebook.py b/examples/01-web/11-facebook.py index eb774313..2cd6b873 100644 --- a/examples/01-web/11-facebook.py +++ b/examples/01-web/11-facebook.py @@ -30,7 +30,7 @@ # With an index on the first column we can quickly check if an id already exists. table = Datasheet.load(pd("opinions.csv")) index = set(table.columns[0]) -except: +except Exception: table = Datasheet() index = set() diff --git a/examples/06-graph/05-trends.py b/examples/06-graph/05-trends.py index e05f7319..b4e41de8 100644 --- a/examples/06-graph/05-trends.py +++ b/examples/06-graph/05-trends.py @@ -33,7 +33,7 @@ # Exclude common phrases such as "this is the new thing". if A and B and A not in ("it", "this", "here", "what", "why", "where"): comparisons.append((A, B)) - except: + except Exception: pass g = Graph() diff --git a/pattern/__init__.py b/pattern/__init__.py index 2cef34ee..f7c8cf0d 100644 --- a/pattern/__init__.py +++ b/pattern/__init__.py @@ -56,5 +56,5 @@ # (instead of pattern.text.en, pattern.text.es, ...) try: __path__.append(os.path.join(__path__[0], "text")) -except: +except Exception: pass diff --git a/pattern/db/__init__.py b/pattern/db/__init__.py index a6fd0afe..03e999aa 100644 --- a/pattern/db/__init__.py +++ b/pattern/db/__init__.py @@ -49,7 +49,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" from pattern.helpers import encode_string, decode_string @@ -259,12 +259,12 @@ def date(*args, **kwargs): args = (args[0].decode("utf-8"),) try: d = Date.fromtimestamp(mktime_tz(parsedate_tz(args[0]))) - except: + except Exception: for format in ("format" in kwargs and [kwargs["format"]] or []) + date_formats: try: d = Date.strptime(args[0], format) break - except: + except Exception: pass if d is None: raise DateError("unknown date format for %s" % repr(args[0])) @@ -334,7 +334,7 @@ def encrypt_string(s, key=""): for i in range(len(s)): try: a.append(chr(ord(s[i]) + ord(key[i % len(key)]) % 256).encode("latin-1")) - except: + except Exception: raise EncryptionError() s = b"".join(a) s = base64.urlsafe_b64encode(s) @@ -351,7 +351,7 @@ def decrypt_string(s, key=""): for i in range(len(s)): try: a.append(chr(ord(s[i]) - ord(key[i % len(key)]) % 256)) - except: + except Exception: raise DecryptionError() s = "".join(a) s = decode_utf8(s) @@ -456,7 +456,7 @@ def cast(x, f, default=None): f = lambda x: int(round(float(x))) try: return f(x) - except: + except Exception: return default #### LIST FUNCTIONS ################################################################################ @@ -864,7 +864,7 @@ def _delete(self): def __delete__(self): try: self.disconnect() - except: + except Exception: pass #### FIELD ######################################################################################### @@ -2154,7 +2154,7 @@ def insert(self, i, row, default=None, **kwargs): try: # Copy the row (fast + safe for generators and DatasheetColumns). row = [v for v in row] - except: + except Exception: raise TypeError("Datasheet.insert(x): x must be list") list.insert(self, i, row) m = max((len(self) > 1 and self._m or 0, len(row))) @@ -2461,7 +2461,7 @@ def insert(self, j, column, default=None, field=None): """ try: column = [v for v in column] - except: + except Exception: raise TypeError("Datasheet.columns.insert(x): x must be list") column = column + [default] * (len(self._datasheet) - len(column)) if len(column) > len(self._datasheet): diff --git a/pattern/graph/__init__.py b/pattern/graph/__init__.py index 85411b8e..e383b02b 100644 --- a/pattern/graph/__init__.py +++ b/pattern/graph/__init__.py @@ -29,7 +29,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" # float("inf") doesn't work on windows. diff --git a/pattern/graph/commonsense.py b/pattern/graph/commonsense.py index a603e664..c4ee4257 100644 --- a/pattern/graph/commonsense.py +++ b/pattern/graph/commonsense.py @@ -36,7 +36,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" if sys.version > "3": diff --git a/pattern/helpers.py b/pattern/helpers.py index 3d1f04d4..ffa2d136 100644 --- a/pattern/helpers.py +++ b/pattern/helpers.py @@ -21,7 +21,7 @@ def decode_string(v, encoding="utf-8"): for e in encoding: try: return v.decode(*e) - except: + except Exception: pass return v return str(v) @@ -36,7 +36,7 @@ def encode_string(v, encoding="utf-8"): for e in encoding: try: return v.encode(*e) - except: + except Exception: pass return v return bytes(v) diff --git a/pattern/metrics.py b/pattern/metrics.py index d3abca0a..69f0d7e9 100644 --- a/pattern/metrics.py +++ b/pattern/metrics.py @@ -93,7 +93,7 @@ def run(): raise TypeError("%s is not a function" % type(function)) try: import cProfile as profile - except: + except Exception: import profile import pstats import os diff --git a/pattern/server/__init__.py b/pattern/server/__init__.py index d310556b..c7d490f7 100644 --- a/pattern/server/__init__.py +++ b/pattern/server/__init__.py @@ -69,7 +69,7 @@ try: # Folder that contains pattern.server. MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" try: @@ -79,7 +79,7 @@ f = inspect.getouterframes(f)[-1][0] f = f.f_globals["__file__"] SCRIPT = os.path.dirname(os.path.abspath(f)) -except: +except Exception: SCRIPT = os.getcwd() @@ -95,7 +95,7 @@ def chown(path, owner=None): grp.getgrnam(y).gr_gid if not isinstance(y, int) else y) os.chown(path, x, y) return True - except: + except Exception: return False # On Linux + Apache mod_wsgi, the user that executes the Python script is "www-data". @@ -339,7 +339,7 @@ def __repr__(self): def __del__(self): try: self.disconnect() - except: + except Exception: pass @property @@ -1019,7 +1019,7 @@ def _cast(self, v): return "" try: # (bool, int, float, object.__unicode__) return str(v) - except: + except Exception: return encode_entities(repr(v)) @cp.expose @@ -1327,7 +1327,7 @@ def stop(self): """ try: atexit._exithandlers.remove((self.stop, (), {})) - except: + except Exception: pass cp.engine.exit() sys.stdout = sys.__stdout__ diff --git a/pattern/text/__init__.py b/pattern/text/__init__.py index aa77af0b..81afdb38 100644 --- a/pattern/text/__init__.py +++ b/pattern/text/__init__.py @@ -36,7 +36,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" from pattern.text.tree import Tree, Text, Sentence, Slice, Chunk, PNPChunk, Chink, Word, table diff --git a/pattern/text/de/__init__.py b/pattern/text/de/__init__.py index 4d4f073b..f1240412 100644 --- a/pattern/text/de/__init__.py +++ b/pattern/text/de/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/de/inflect.py b/pattern/text/de/inflect.py index b5c76b34..b388b986 100644 --- a/pattern/text/de/inflect.py +++ b/pattern/text/de/inflect.py @@ -32,7 +32,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/en/__init__.py b/pattern/text/en/__init__.py index 31d548f7..abece17d 100644 --- a/pattern/text/en/__init__.py +++ b/pattern/text/en/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/en/inflect.py b/pattern/text/en/inflect.py index e4d81469..16b9a2e8 100644 --- a/pattern/text/en/inflect.py +++ b/pattern/text/en/inflect.py @@ -29,7 +29,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/en/inflect_quantify.py b/pattern/text/en/inflect_quantify.py index 6aa9483d..94c5bb18 100644 --- a/pattern/text/en/inflect_quantify.py +++ b/pattern/text/en/inflect_quantify.py @@ -22,7 +22,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) @@ -155,7 +155,7 @@ def number(s): # Words that are not in any dicionary may be numbers (e.g. "2.5" => 2.5). try: i += "." in x and float(x) or int(x) - except: + except Exception: pass return n + i + f @@ -267,7 +267,7 @@ def approximate(word, amount=1, plural={}): """ try: p = pluralize(word, custom=plural) - except: + except Exception: raise TypeError("can't pluralize %s (not a string)" % word.__class__.__name__) # Anything up to 200. if amount == 0: @@ -331,7 +331,7 @@ def count(*args, **kwargs): try: count.setdefault(word, 0) count[word] += 1 - except: + except Exception: raise TypeError("can't count %s (not a string)" % word.__class__.__name__) # Create an iterator of (count, item) tuples, sorted highest-first. s = [(count[word], word) for word in count] @@ -394,7 +394,7 @@ def reflect(object, quantify=True, replace=readable_types): for v in object.__dict__.values(): try: types.append(str(v.__classname__)) - except: + except Exception: # Not a class after all (some stuff like ufunc in Numeric). types.append(_type(v)) # Lists and tuples can consist of several types of objects. diff --git a/pattern/text/en/wordlist/__init__.py b/pattern/text/en/wordlist/__init__.py index 047a805f..91cb6dfa 100644 --- a/pattern/text/en/wordlist/__init__.py +++ b/pattern/text/en/wordlist/__init__.py @@ -19,7 +19,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" diff --git a/pattern/text/en/wordnet/__init__.py b/pattern/text/en/wordnet/__init__.py index 022285fd..e84ecf9d 100644 --- a/pattern/text/en/wordnet/__init__.py +++ b/pattern/text/en/wordnet/__init__.py @@ -37,7 +37,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" # Path to WordNet /dict folder. @@ -98,7 +98,7 @@ def normalize(word): if not isinstance(word, str): try: word = word.encode("utf-8", "ignore") - except: + except Exception: pass for k, v in DIACRITICS.items(): for v in v: @@ -154,7 +154,7 @@ def __getitem__(self, k): for pos in ("n", "v", "a", "r"): try: synset = wn._synset_from_pos_and_offset(pos, k) - except: + except Exception: pass if synset: return synset @@ -429,7 +429,7 @@ def map32(id, pos=NOUN): try: from pattern.text import Sentiment -except: +except Exception: class Sentiment(object): PLACEHOLDER = True @@ -455,7 +455,7 @@ def synset(self, id, pos=ADJECTIVE): s = wn._synset_from_pos_and_offset(pos, id) lemma = s.lemma_names()[0] return self[lemma] - except: + except Exception: pass return None diff --git a/pattern/text/es/__init__.py b/pattern/text/es/__init__.py index e0d2e70f..68757def 100644 --- a/pattern/text/es/__init__.py +++ b/pattern/text/es/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/es/inflect.py b/pattern/text/es/inflect.py index a07c230c..cac1e86f 100644 --- a/pattern/text/es/inflect.py +++ b/pattern/text/es/inflect.py @@ -30,7 +30,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/fr/__init__.py b/pattern/text/fr/__init__.py index fd1e5bbf..4bca4729 100644 --- a/pattern/text/fr/__init__.py +++ b/pattern/text/fr/__init__.py @@ -21,7 +21,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/fr/inflect.py b/pattern/text/fr/inflect.py index f49c01f6..730ecd1c 100644 --- a/pattern/text/fr/inflect.py +++ b/pattern/text/fr/inflect.py @@ -30,7 +30,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/it/__init__.py b/pattern/text/it/__init__.py index 1e4bfc3a..a4c18cb8 100644 --- a/pattern/text/it/__init__.py +++ b/pattern/text/it/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/it/inflect.py b/pattern/text/it/inflect.py index 0e17ec5c..62c70d97 100644 --- a/pattern/text/it/inflect.py +++ b/pattern/text/it/inflect.py @@ -32,7 +32,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/nl/__init__.py b/pattern/text/nl/__init__.py index 869923f0..3fd13a23 100644 --- a/pattern/text/nl/__init__.py +++ b/pattern/text/nl/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/nl/inflect.py b/pattern/text/nl/inflect.py index ea02e139..8b3117f3 100644 --- a/pattern/text/nl/inflect.py +++ b/pattern/text/nl/inflect.py @@ -31,7 +31,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/ru/__init__.py b/pattern/text/ru/__init__.py index 51c5604e..6b26e012 100644 --- a/pattern/text/ru/__init__.py +++ b/pattern/text/ru/__init__.py @@ -20,7 +20,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/ru/wordlist/__init__.py b/pattern/text/ru/wordlist/__init__.py index 01e5b6dc..84a2cd44 100644 --- a/pattern/text/ru/wordlist/__init__.py +++ b/pattern/text/ru/wordlist/__init__.py @@ -19,7 +19,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" diff --git a/pattern/text/search.py b/pattern/text/search.py index 6efd5199..bd70ae00 100644 --- a/pattern/text/search.py +++ b/pattern/text/search.py @@ -124,7 +124,7 @@ def _match(string, pattern): if WILDCARD in p[1:-1]: p = p.split(WILDCARD) return string.startswith(p[0]) and string.endswith(p[-1]) - except: + except Exception: # For performance, calling isinstance() last is 10% faster for plain strings. if isinstance(p, regexp): return p.search(string) is not None @@ -176,7 +176,7 @@ def product(*args, **kwargs): try: from itertools import product -except: +except Exception: pass @@ -450,10 +450,10 @@ def __init__(self, wordnet=None): if wordnet is None: try: from pattern.en import wordnet - except: + except Exception: try: from .en import wordnet - except: + except Exception: pass Classifier.__init__(self, self._parents, self._children) self.wordnet = wordnet @@ -461,13 +461,13 @@ def __init__(self, wordnet=None): def _children(self, word, pos="NN"): try: return [w.synonyms[0] for w in self.wordnet.synsets(word, pos[:2])[0].hyponyms()] - except: + except Exception: pass def _parents(self, word, pos="NN"): try: return [w.synonyms[0] for w in self.wordnet.synsets(word, pos[:2])[0].hypernyms()] - except: + except Exception: pass #from en import wordnet diff --git a/pattern/text/tree.py b/pattern/text/tree.py index 21e75ec7..3be869e0 100644 --- a/pattern/text/tree.py +++ b/pattern/text/tree.py @@ -46,7 +46,7 @@ from config import SLASH from config import WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA MBSP = True # Memory-Based Shallow Parser for Python. -except: +except Exception: SLASH, WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA = \ "&slash;", "word", "part-of-speech", "chunk", "preposition", "relation", "anchor", "lemma" MBSP = False @@ -155,7 +155,7 @@ def __init__(self, sentence, string, lemma=None, type=None, index=0): if not isinstance(string, str): try: string = string.decode("utf-8") # ensure Unicode - except: + except Exception: pass self.sentence = sentence self.index = index @@ -659,7 +659,7 @@ def __init__(self, string="", token=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA], for encoding in (("utf-8",), ("windows-1252",), ("utf-8", "ignore")): try: string = string.decode(*encoding) - except: + except Exception: pass self.parent = None # A Slice refers to the Sentence it is part of. self.text = None # A Sentence refers to the Text it is part of. @@ -1586,7 +1586,7 @@ def parse_string(xml): if MBSP: from mbsp import TokenString return TokenString(string.strip(), tags=format, language=language) - except: + except Exception: return TaggedString(string.strip(), tags=format, language=language) diff --git a/pattern/text/xx/__init__.py b/pattern/text/xx/__init__.py index 721a6b8a..eabe10eb 100644 --- a/pattern/text/xx/__init__.py +++ b/pattern/text/xx/__init__.py @@ -31,7 +31,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/text/xx/inflect.py b/pattern/text/xx/inflect.py index 8e3b7c3b..1e0dc6ec 100644 --- a/pattern/text/xx/inflect.py +++ b/pattern/text/xx/inflect.py @@ -26,7 +26,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" sys.path.insert(0, os.path.join(MODULE, "..", "..", "..", "..")) diff --git a/pattern/vector/__init__.py b/pattern/vector/__init__.py index 76a368ab..0c44765d 100644 --- a/pattern/vector/__init__.py +++ b/pattern/vector/__init__.py @@ -67,17 +67,17 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" try: from pattern.text import singularize, predicative, conjugate, tokenize -except: +except Exception: try: import sys sys.path.insert(0, os.path.join(MODULE, "..")) from text import singularize, predicative, conjugate, tokenize - except: + except Exception: singularize = lambda w, **k: w predicative = lambda w, **k: w conjugate = lambda w, t, **k: w @@ -2427,7 +2427,7 @@ def max(self): if self[b] < m: return choice([x for x in self if self[x] == m > 0]), m return b, m - except: + except Exception: return b, 0.0 #--- CLASSIFIER EVALUATION ------------------------------------------------------------------------- @@ -2716,7 +2716,7 @@ def classify(self, document, discrete=True): p = sorted((self._classes[type], type) for type, g in p.items() if g == m > 0) p = [type for frequency, type in p if frequency == p[0][0]] return choice(p) - except: + except Exception: return self.baseline Bayes = NaiveBayes = NB @@ -2768,7 +2768,7 @@ def classify(self, document, discrete=True): p = sorted((self._classes[type], type) for type, w in p.items() if w == m > 0) p = [type for frequency, type in p if frequency == p[0][0]] return choice(p) - except: + except Exception: return self.baseline NearestNeighbor = kNN = KNN @@ -3104,7 +3104,7 @@ def classify(self, document, discrete=True): p = sorted((self._classes[type], type) for type, w in p.items() if w == m > 0) p = [type for frequency, type in p if frequency == p[0][0]] return choice(p) - except: + except Exception: return self.baseline def finalize(self): @@ -3757,7 +3757,7 @@ def _train(self): x = scipy.sparse.csr_matrix(x) # faster dot y = scipy.array([H1[type] for type, v in self._vectors]) t = self._gradient_descent(x, y, l=0.1, iterations=self._iterations) - except: + except Exception: t = None self._model = (t, H1, H2, H3, H4) @@ -3842,7 +3842,7 @@ def classify(self, document, discrete=True): p = sorted((self._classes[type], type) for type, w in p.items() if w == m > 0) p = [type for frequency, type in p if frequency == p[0][0]] return choice(p) - except: + except Exception: return self.baseline def save(self, path, final=False): diff --git a/pattern/vector/svm/__init__.py b/pattern/vector/svm/__init__.py index e3c53d1f..a37082f1 100644 --- a/pattern/vector/svm/__init__.py +++ b/pattern/vector/svm/__init__.py @@ -13,5 +13,5 @@ try: from . import liblinear from . import liblinearutil -except: +except Exception: LIBLINEAR = False diff --git a/pattern/vector/svm/liblinear.py b/pattern/vector/svm/liblinear.py index 00ee4d24..2af8c222 100644 --- a/pattern/vector/svm/liblinear.py +++ b/pattern/vector/svm/liblinear.py @@ -16,7 +16,7 @@ try: import scipy from scipy import sparse -except: +except Exception: scipy = None sparse = None @@ -32,7 +32,7 @@ liblinear = CDLL(path.join(dirname, 'windows\liblinear-2.20\liblinear.dll')) else: liblinear = CDLL(path.join(dirname, 'macos/liblinear-2.20/liblinear.so.3')) -except: +except Exception: # For unix the prefix 'lib' is not considered. if find_library('linear'): liblinear = CDLL(find_library('linear')) @@ -129,7 +129,7 @@ def gen_feature_nodearray(xi, feature_max=None): try: from numba import jit jit_enabled = True -except: +except Exception: jit = lambda x: x jit_enabled = False diff --git a/pattern/vector/svm/liblinearutil.py b/pattern/vector/svm/liblinearutil.py index e705460b..0fbf3a2d 100644 --- a/pattern/vector/svm/liblinearutil.py +++ b/pattern/vector/svm/liblinearutil.py @@ -112,7 +112,7 @@ def evaluations_scipy(ty, pv): with scipy.errstate(all = 'raise'): try: SCC = ((l * sumvy - sumv * sumy) * (l * sumvy - sumv * sumy)) / ((l * sumvv - sumv * sumv) * (l * sumyy - sumy * sumy)) - except: + except Exception: SCC = float('nan') return (float(ACC), float(MSE), float(SCC)) @@ -146,7 +146,7 @@ def evaluations(ty, pv, useScipy = True): MSE = total_error / l try: SCC = ((l * sumvy - sumv * sumy) * (l * sumvy - sumv * sumy)) / ((l * sumvv - sumv * sumv) * (l * sumyy - sumy * sumy)) - except: + except Exception: SCC = float('nan') return (float(ACC), float(MSE), float(SCC)) diff --git a/pattern/vector/svm/libsvm.py b/pattern/vector/svm/libsvm.py index ac992d2b..fe4e05e6 100644 --- a/pattern/vector/svm/libsvm.py +++ b/pattern/vector/svm/libsvm.py @@ -26,7 +26,7 @@ else: libsvm = CDLL(path.join(dirname, 'macos/libsvm-3.22/libsvm.so.2')) -except: +except Exception: # For unix the prefix 'lib' is not considered. if find_library('svm'): libsvm = CDLL(find_library('svm')) diff --git a/pattern/vector/svm/libsvmutil.py b/pattern/vector/svm/libsvmutil.py index 29110b00..722d2e03 100644 --- a/pattern/vector/svm/libsvmutil.py +++ b/pattern/vector/svm/libsvmutil.py @@ -92,7 +92,7 @@ def evaluations(ty, pv): MSE = total_error / l try: SCC = ((l * sumvy - sumv * sumy) * (l * sumvy - sumv * sumy)) / ((l * sumvv - sumv * sumv) * (l * sumyy - sumy * sumy)) - except: + except Exception: SCC = float('nan') return (ACC, MSE, SCC) diff --git a/pattern/web/__init__.py b/pattern/web/__init__.py index c76cea88..ba9fc778 100644 --- a/pattern/web/__init__.py +++ b/pattern/web/__init__.py @@ -95,19 +95,19 @@ # If this module is used separately, # a dict is used (i.e. this Python session only). from .cache import Cache, cache, TMP -except: +except Exception: cache = {} try: from .imap import Mail, MailFolder, Message, GMAIL from .imap import MailError, MailServiceError, MailLoginError, MailNotLoggedIn from .imap import FROM, SUBJECT, DATE, BODY, ATTACHMENTS -except: +except Exception: pass try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" #### UNICODE ####################################################################################### @@ -149,7 +149,7 @@ def fix(s, ignore=""): else: try: ch = ch.encode("latin-1") - except: + except Exception: ch = ch.encode("utf-8") u.append(s[i:j].encode("utf-8")) u.append(ch) @@ -292,7 +292,7 @@ def _format(s): return int(s) try: return float(s) - except: + except Exception: return s if query: query = query.lstrip("?").split("&") @@ -628,7 +628,7 @@ def exists(self, timeout=10): return True except URLError: return False - except: + except Exception: return True return True @@ -4453,5 +4453,5 @@ def parsedoc(path, format=None): for f in (parsepdf, parsedocx, parsehtml): try: return f(path) - except: + except Exception: pass diff --git a/pattern/web/cache/__init__.py b/pattern/web/cache/__init__.py index 30daabc9..9695b29b 100644 --- a/pattern/web/cache/__init__.py +++ b/pattern/web/cache/__init__.py @@ -16,7 +16,7 @@ try: import hashlib md5 = hashlib.md5 -except: +except Exception: import md5 md5 = md5.new @@ -40,7 +40,7 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" TMP = os.path.join(tempfile.gettempdir(), "pattern_web") diff --git a/pattern/web/imap/__init__.py b/pattern/web/imap/__init__.py index 0a20fe8e..60e5b835 100644 --- a/pattern/web/imap/__init__.py +++ b/pattern/web/imap/__init__.py @@ -22,22 +22,22 @@ try: MODULE = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: MODULE = "" # Import the Cache class from pattern.web so e-mails can be cached locally (faster): try: from ..cache import cache -except: +except Exception: try: import os import sys sys.path.append(os.path.join(MODULE, "..")) from cache import cache - except: + except Exception: try: from pattern.web.cache import cache - except: + except Exception: cache = {} from pattern.helpers import encode_string, decode_string @@ -123,7 +123,7 @@ def login(self, username, password, **kwargs): self._imap4 = (self._secure and IMAP4_SSL or IMAP4)(self._host, self._port) try: status, response = self._imap4.login(username, password) - except: + except Exception: raise MailLoginError if status != "OK": raise MailLoginError(response) @@ -170,7 +170,7 @@ def _decode(s, message): try: # Decode MIME header (e.g., "=?utf-8?q?"). s = email.Header.decode_header(s)[0][0] - except: + except Exception: pass try: # Decode message Content-Type charset to Unicode. @@ -178,13 +178,13 @@ def _decode(s, message): e = message.get("Content-Type") e = e.split("charset=")[-1].split(";")[0].strip("\"'").lower() s = s.decode(e) - except: + except Exception: try: s = s.decode("utf-8") - except: + except Exception: try: s = s.decode("latin-1") - except: + except Exception: pass return s diff --git a/pattern/web/oauth/__init__.py b/pattern/web/oauth/__init__.py index 458406a5..8e09968b 100755 --- a/pattern/web/oauth/__init__.py +++ b/pattern/web/oauth/__init__.py @@ -31,7 +31,7 @@ try: from hashlib import sha1 from hashlib import md5 -except: +except Exception: import sha as sha1 import md5 md5 = md5.new diff --git a/test/test_de.py b/test/test_de.py index 298db59a..26561d71 100644 --- a/test/test_de.py +++ b/test/test_de.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_en.py b/test/test_en.py index 5a1d5076..727900cd 100644 --- a/test/test_en.py +++ b/test/test_en.py @@ -22,7 +22,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_es.py b/test/test_es.py index a85571c1..bcda8374 100644 --- a/test/test_es.py +++ b/test/test_es.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_fr.py b/test/test_fr.py index 11eebd6c..50e22567 100644 --- a/test/test_fr.py +++ b/test/test_fr.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_it.py b/test/test_it.py index acf3c0e6..cd838832 100644 --- a/test/test_it.py +++ b/test/test_it.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_metrics.py b/test/test_metrics.py index e896c4c6..80013d76 100644 --- a/test/test_metrics.py +++ b/test/test_metrics.py @@ -19,7 +19,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_nl.py b/test/test_nl.py index 7976750d..5067fa7f 100644 --- a/test/test_nl.py +++ b/test/test_nl.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_ru.py b/test/test_ru.py index 08c0f124..fa895632 100644 --- a/test/test_ru.py +++ b/test/test_ru.py @@ -22,7 +22,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #--------------------------------------------------------------------------------------------------- diff --git a/test/test_vector.py b/test/test_vector.py index 79c29e6c..a74f0c9b 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -27,7 +27,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" diff --git a/test/test_web.py b/test/test_web.py index 12587341..15b637d7 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -20,7 +20,7 @@ try: PATH = os.path.dirname(os.path.realpath(__file__)) -except: +except Exception: PATH = "" #---------------------------------------------------------------------------------------------------