From 483afed26a002cc3ec03ff54379ba2c2c65a7d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 8 Jul 2010 19:53:39 +0200 Subject: [PATCH] Catch only Exception according to PEP 352 --- trytond/backend/mysql/database.py | 2 +- trytond/backend/mysql/table.py | 6 +++--- trytond/backend/postgresql/database.py | 4 ++-- trytond/backend/postgresql/table.py | 6 +++--- trytond/backend/sqlite/database.py | 10 +++++----- trytond/ir/action.py | 24 ++++++++++++------------ trytond/ir/cron.py | 8 ++++---- trytond/ir/lang.py | 4 ++-- trytond/ir/model.py | 6 +++--- trytond/ir/module/module.py | 2 +- trytond/ir/sequence.py | 2 +- trytond/ir/translation.py | 2 +- trytond/ir/ui/view.py | 14 +++++++------- trytond/model/browse.py | 2 +- trytond/model/fields/reference.py | 4 ++-- trytond/model/modelsql.py | 2 +- trytond/model/modelstorage.py | 8 ++++---- trytond/model/modelview.py | 2 +- trytond/modules/__init__.py | 4 ++-- trytond/monitor.py | 2 +- trytond/pool.py | 2 +- trytond/protocols/dispatcher.py | 10 +++++----- trytond/protocols/jsonrpc.py | 8 ++++---- trytond/protocols/netrpc.py | 18 +++++++++--------- trytond/protocols/webdav.py | 6 +++--- trytond/protocols/xmlrpc.py | 10 +++++----- trytond/pysocket.py | 10 +++++----- trytond/res/user.py | 2 +- trytond/server.py | 2 +- trytond/tools/convert.py | 8 ++++---- trytond/tools/misc.py | 2 +- trytond/webdav/webdav.py | 14 +++++++------- 32 files changed, 103 insertions(+), 103 deletions(-) diff --git a/trytond/backend/mysql/database.py b/trytond/backend/mysql/database.py index 60ad2bdc17..2697c2540e 100644 --- a/trytond/backend/mysql/database.py +++ b/trytond/backend/mysql/database.py @@ -146,7 +146,7 @@ class Database(DatabaseInterface): for db_name, in cursor.fetchall(): try: database = Database(db_name).connect() - except: + except Exception: continue cursor2 = database.cursor() if cursor2.test(): diff --git a/trytond/backend/mysql/table.py b/trytond/backend/mysql/table.py index b708c98682..daedbf108b 100644 --- a/trytond/backend/mysql/table.py +++ b/trytond/backend/mysql/table.py @@ -327,7 +327,7 @@ class TableHandler(TableHandlerInterface): self.cursor.execute('ALTER TABLE `%s` ' \ 'ADD CONSTRAINT `%s` %s' % \ (self.table_name, ident, constraint,)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( @@ -347,7 +347,7 @@ class TableHandler(TableHandlerInterface): self.cursor.execute('ALTER TABLE `%s` ' \ 'DROP CONSTRAINT `%s`' % \ (self.table_name, ident)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( @@ -363,7 +363,7 @@ class TableHandler(TableHandlerInterface): 'ALTER TABLE `%s` DROP COLUMN `%s`' % (self.table_name, column_name)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index c231270671..2d4e504db0 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -191,7 +191,7 @@ class Database(DatabaseInterface): db_name = db_name.encode('utf-8') try: database = Database(db_name).connect() - except: + except Exception: continue cursor2 = database.cursor() if cursor2.test(): @@ -290,7 +290,7 @@ class Cursor(CursorInterface): res = self.cursor.execute(sql, params) else: res = self.cursor.execute(sql) - except: + except Exception: logger = logging.getLogger('sql') logger.error('Wrong SQL: ' + (self.cursor.query or '')) raise diff --git a/trytond/backend/postgresql/table.py b/trytond/backend/postgresql/table.py index f435e79ee1..90335d6a2e 100644 --- a/trytond/backend/postgresql/table.py +++ b/trytond/backend/postgresql/table.py @@ -380,7 +380,7 @@ class TableHandler(TableHandlerInterface): self.cursor.execute('ALTER TABLE "%s" ' \ 'ADD CONSTRAINT "%s" %s' % \ (self.table_name, ident, constraint,)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( @@ -400,7 +400,7 @@ class TableHandler(TableHandlerInterface): self.cursor.execute('ALTER TABLE "%s" ' \ 'DROP CONSTRAINT "%s"' % \ (self.table_name, ident)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( @@ -416,7 +416,7 @@ class TableHandler(TableHandlerInterface): 'ALTER TABLE "%s" DROP COLUMN "%s"' % (self.table_name, column_name)) - except: + except Exception: if exception: raise logging.getLogger('init').warning( diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index 6f4bb89637..cd5b4e292c 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -36,7 +36,7 @@ def extract(lookup_type, date): microseconds = int(timepart_full[1]) date = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds) - except: + except Exception: return None if lookup_type.lower() == 'century': return date.year / 100 + (date.year % 100 and 1 or 0) @@ -65,7 +65,7 @@ def date_trunc(_type, date): return date try: tm_tuple = time.strptime(date, '%Y-%m-%d %H:%M:%S') - except: + except Exception: return None if _type == 'year': return "%i-01-01 00:00:00" % tm_tuple.tm_year @@ -197,7 +197,7 @@ class Database(DatabaseInterface): db_name = db_file[:-7] try: database = Database(db_name) - except: + except Exception: continue cursor2 = database.cursor() if cursor2.test(): @@ -292,7 +292,7 @@ class Cursor(CursorInterface): unicode(x, 'utf-8') or x for x in params]) else: res = self.cursor.execute(sql) - except: + except Exception: raise return res @@ -330,7 +330,7 @@ class Cursor(CursorInterface): "'ir_translation, '" "'ir_lang'" ")") - except: + except Exception: return False return len(self.cursor.fetchall()) != 0 diff --git a/trytond/ir/action.py b/trytond/ir/action.py index 9afb2f86be..62a9fb1b80 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -128,7 +128,7 @@ class ActionKeyword(ModelSQL, ModelView): try: self.pool.get(keyword.model.split(',')[0])\ .fields_view_get(cursor.dbname) - except: + except Exception: pass return super(ActionKeyword, self).delete(cursor, user, ids, context=context) @@ -140,7 +140,7 @@ class ActionKeyword(ModelSQL, ModelView): try: self.pool.get(vals['model'].split(',')[0])\ .fields_view_get(cursor.dbname) - except: + except Exception: pass return super(ActionKeyword, self).create(cursor, user, vals, context=context) @@ -154,7 +154,7 @@ class ActionKeyword(ModelSQL, ModelView): try: self.pool.get(keyword.model.split(',')[0])\ .fields_view_get(cursor.dbname) - except: + except Exception: pass res = super(ActionKeyword, self).write(cursor, user, ids, vals, context=context) @@ -163,7 +163,7 @@ class ActionKeyword(ModelSQL, ModelView): try: self.pool.get(keyword.model.split(',')[0])\ .fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -186,7 +186,7 @@ class ActionKeyword(ModelSQL, ModelView): context=context): try: action_obj = self.pool.get(action_keyword.action.type) - except: + except Exception: continue action_id = action_obj.search(cursor, user, [ ('action', '=', action_keyword.action.id), @@ -289,7 +289,7 @@ class ActionReport(ModelSQL, ModelView): data = base64.encodestring(file_open( report[name[:-8]].replace('/', os.sep), mode='rb').read()) - except: + except Exception: data = False res[report.id] = data return res @@ -306,7 +306,7 @@ class ActionReport(ModelSQL, ModelView): data = base64.encodestring(file_open( report.style.replace('/', os.sep), mode='rb').read()) - except: + except Exception: data = False res[report.id] = data return res @@ -453,7 +453,7 @@ class ActionActWindow(ModelSQL, ModelView): if action.domain: try: value = safe_eval(action.domain, CONTEXT) - except: + except Exception: return False if isinstance(value, PYSON): if not value.types() == set([list]): @@ -463,7 +463,7 @@ class ActionActWindow(ModelSQL, ModelView): else: try: fields.domain_validate(value) - except: + except Exception: return False return True @@ -473,7 +473,7 @@ class ActionActWindow(ModelSQL, ModelView): if action.context: try: value = safe_eval(action.context, CONTEXT) - except: + except Exception: return False if isinstance(value, PYSON): if not value.types() == set([dict]): @@ -483,7 +483,7 @@ class ActionActWindow(ModelSQL, ModelView): else: try: fields.context_validate(value) - except: + except Exception: return False return True @@ -493,7 +493,7 @@ class ActionActWindow(ModelSQL, ModelView): if action.search_value: try: value = safe_eval(action.search_value, CONTEXT) - except: + except Exception: return False if isinstance(value, PYSON): if not value.types() == set([dict]): diff --git a/trytond/ir/cron.py b/trytond/ir/cron.py index 06def37545..d5fdd6ddf4 100644 --- a/trytond/ir/cron.py +++ b/trytond/ir/cron.py @@ -112,12 +112,12 @@ class Cron(ModelSQL, ModelView): for line in traceback.format_exception(*sys.exc_info()): try: line = line.encode('utf-8', 'ignore') - except: + except Exception: continue tb_s += line try: tb_s += error.message.decode('utf-8', 'ignore') - except: + except Exception: pass request_obj = self.pool.get('res.request') @@ -143,7 +143,7 @@ class Cron(ModelSQL, ModelView): 'trigger_date': datetime.datetime.now(), }) cursor.commit() - except: + except Exception: cursor.rollback() def pool_jobs(self, db_name): @@ -151,7 +151,7 @@ class Cron(ModelSQL, ModelView): try: database = Database(db_name).connect() cursor = database.cursor() - except: + except Exception: return try: try: diff --git a/trytond/ir/lang.py b/trytond/ir/lang.py index f6d7cfee45..65b61b8251 100644 --- a/trytond/ir/lang.py +++ b/trytond/ir/lang.py @@ -114,7 +114,7 @@ class Lang(ModelSQL, ModelView, Cacheable): for i in grouping: if not isinstance(i, int): return False - except: + except Exception: return False return True @@ -126,7 +126,7 @@ class Lang(ModelSQL, ModelView, Cacheable): try: datetime_strftime(datetime.datetime.now(), lang.date.encode('utf-8')) - except: + except Exception: return False if '%Y' not in lang.date: return False diff --git a/trytond/ir/model.py b/trytond/ir/model.py index 1e4d4fdb71..5ab058315b 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -263,7 +263,7 @@ class ModelAccess(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -275,7 +275,7 @@ class ModelAccess(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -287,7 +287,7 @@ class ModelAccess(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index dd9aabd849..225d07cf09 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -68,7 +68,7 @@ class Module(ModelSQL, ModelView): data = file_p.read() info = tools.safe_eval(data) file_p.close() - except: + except Exception: return {} return info diff --git a/trytond/ir/sequence.py b/trytond/ir/sequence.py index 368d28daae..6cff9e080a 100644 --- a/trytond/ir/sequence.py +++ b/trytond/ir/sequence.py @@ -75,7 +75,7 @@ class Sequence(ModelSQL, ModelView): try: self._process(cursor, user, sequence.prefix) self._process(cursor, user, sequence.suffix) - except: + except Exception: return False return True diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 65e0e3904f..747d80a787 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -645,7 +645,7 @@ class ReportTranslationSet(Wizard): style_content = None try: style_content = base64.decodestring(report.style_content) - except: + except Exception: pass if style_content: diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 508f1c9c65..7652fe453e 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -182,7 +182,7 @@ class View(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -192,7 +192,7 @@ class View(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -202,7 +202,7 @@ class View(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -275,7 +275,7 @@ class ViewTreeWidth(ModelSQL, ModelView): # Restart the cache try: self.pool.get(view.model).fields_view_get(cursor.dbname) - except: + except Exception: pass res = super(ViewTreeWidth, self).delete(cursor, user, ids, context=context) return res @@ -287,7 +287,7 @@ class ViewTreeWidth(ModelSQL, ModelView): # Restart the cache try: self.pool.get(model).fields_view_get(cursor.dbname) - except: + except Exception: pass return res @@ -299,7 +299,7 @@ class ViewTreeWidth(ModelSQL, ModelView): # Restart the cache try: self.pool.get(view.model).fields_view_get(cursor.dbname) - except: + except Exception: pass res = super(ViewTreeWidth, self).write(cursor, user, ids, vals, context=context) views = self.browse(cursor, user, ids) @@ -307,7 +307,7 @@ class ViewTreeWidth(ModelSQL, ModelView): # Restart the cache try: self.pool.get(view.model).fields_view_get(cursor.dbname) - except: + except Exception: pass return res diff --git a/trytond/model/browse.py b/trytond/model/browse.py index 4880d602e3..5b8058f2ec 100644 --- a/trytond/model/browse.py +++ b/trytond/model/browse.py @@ -271,7 +271,7 @@ class EvalEnvironment(dict): def get(self, item, default=None): try: return self.__getitem__(item) - except: + except Exception: pass return super(EvalEnvironment, self).get(item, default) diff --git a/trytond/model/fields/reference.py b/trytond/model/fields/reference.py index 5514af1648..ef36d088d3 100644 --- a/trytond/model/fields/reference.py +++ b/trytond/model/fields/reference.py @@ -66,11 +66,11 @@ class Reference(Field): ref_id_found.setdefault(ref_model, set()) try: ref_id = safe_eval(ref_id) - except: + except Exception: pass try: ref_id = int(ref_id) - except: + except Exception: continue ctx = context.copy() ctx['active_test'] = False diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index ef6555f038..bcc6e65401 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -102,7 +102,7 @@ class ModelSQL(ModelStorage): try: # XXX ugly hack: some default fct try # to access the non-existing table result = fun(*a) - except: + except Exception: return None clean_results = self._clean_defaults( {field_name: result}) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 262bf8b253..73439efd5b 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -322,7 +322,7 @@ class ModelStorage(Model): try: data[field_name] = data[field_name] and \ data[field_name][0] - except: + except Exception: pass elif ftype in ('one2many',): if data[field_name]: @@ -728,7 +728,7 @@ class ModelStorage(Model): return False try: relation, value = value.split(',', 1) - except: + except Exception: warn('reference_syntax_error', value, '/'.join(field)) return False relation_obj = self.pool.get(relation) @@ -756,7 +756,7 @@ class ModelStorage(Model): elif ftype == 'reference': try: relation, value = value.split(',', 1) - except: + except Exception: warn('reference_syntax_error', value, '/'.join(field)) return False value = [value] @@ -766,7 +766,7 @@ class ModelStorage(Model): for word in value: try: module, xml_id = word.rsplit('.', 1) - except: + except Exception: warn('xml_id_syntax_error', word, '/'.join(field)) continue db_id = ir_model_data_obj.get_id(cursor, user, diff --git a/trytond/model/modelview.py b/trytond/model/modelview.py index 4f9f0e6919..fe27ea3e77 100644 --- a/trytond/model/modelview.py +++ b/trytond/model/modelview.py @@ -330,7 +330,7 @@ class ModelView(Model): relation = field.model_name else: relation = field.get_target(self.pool)._name - except: + except Exception: relation = False if relation and element.tag == 'field': childs = False diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index 80627eace5..c3210abcb2 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -153,7 +153,7 @@ def create_graph(module_list, force=None): try: info = tools.safe_eval(tools.file_open(tryton_file, subdir='').read()) - except: + except Exception: logger.error('%s:eval file %s' % (module, tryton_file)) raise packages.append((module, info.get('depends', []), info)) @@ -434,7 +434,7 @@ def load_modules(database_name, pool, update=False, lang=None): try: load_module_graph(cursor, graph, pool, lang) - except: + except Exception: cursor.rollback() raise diff --git a/trytond/monitor.py b/trytond/monitor.py index e1adb67bf8..670420143d 100644 --- a/trytond/monitor.py +++ b/trytond/monitor.py @@ -24,7 +24,7 @@ def _modified(path): if mtime != _TIMES[path]: _TIMES[path] = mtime return True - except: + except Exception: return True finally: _LOCK.release() diff --git a/trytond/pool.py b/trytond/pool.py index eb54917529..867b03858f 100644 --- a/trytond/pool.py +++ b/trytond/pool.py @@ -73,7 +73,7 @@ class Pool(object): Pool.classes[type] = {} try: register_classes(reload_p=reload_p) - except: + except Exception: if not reload_p: raise for type in prev_classes: diff --git a/trytond/protocols/dispatcher.py b/trytond/protocols/dispatcher.py index 0bc64ecb3d..45d6cb3091 100644 --- a/trytond/protocols/dispatcher.py +++ b/trytond/protocols/dispatcher.py @@ -63,7 +63,7 @@ def dispatch(host, port, protocol, database_name, user, session, object_type, cursor = database.cursor() cursor.close(close=True) return True - except: + except Exception: return False elif method == 'list': database = Database().connect() @@ -71,7 +71,7 @@ def dispatch(host, port, protocol, database_name, user, session, object_type, cursor = database.cursor() res = database.list(cursor) cursor.close(close=True) - except: + except Exception: res = [] return res elif method == 'create': @@ -206,7 +206,7 @@ def create(database_name, password, lang, admin_password): module_obj.update_list(cursor, 0) cursor.commit() res = True - except: + except Exception: logger.error('CREATE DB: %s failed' % (database_name,)) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) @@ -232,7 +232,7 @@ def drop(database_name, password): try: database.drop(cursor, database_name) cursor.commit() - except: + except Exception: logger.error('DROP DB: %s failed' % (database_name,)) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(*sys.exc_info())) @@ -264,7 +264,7 @@ def restore(database_name, password, data, update=False): cursor = database.cursor() cursor.close(close=True) raise Exception("Database already exists!") - except: + except Exception: pass data = base64.decodestring(data) Database.restore(database_name, data) diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index 5cbb74fca9..b9acdd7eb2 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -92,12 +92,12 @@ class SimpleJSONRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher): response['result'] = dispatch_method(method, params) else: response['result'] = self._dispatch(method, params) - except: + except Exception: tb_s = '' for line in traceback.format_exception(*sys.exc_info()): try: line = line.encode('utf-8', 'ignore') - except: + except Exception: continue tb_s += line for path in sys.path: @@ -175,7 +175,7 @@ class SimpleJSONRPCRequestHandler(GenericJSONRPCRequestHandler, response = self.server._marshaled_dispatch( data, getattr(self, '_dispatch', None) ) - except: # This should only happen if the module is buggy + except Exception: # This should only happen if the module is buggy # internal error, report as HTTP server error self.send_response(500) self.end_headers() @@ -314,7 +314,7 @@ class JSONRPCDaemon(threading.Thread): try: socket.getaddrinfo(interface or None, port, socket.AF_INET6) ipv6 = True - except: + except Exception: pass if secure: handler_class = SecureJSONRPCRequestHandler diff --git a/trytond/protocols/netrpc.py b/trytond/protocols/netrpc.py index 06d5b810a9..95906fe4ef 100644 --- a/trytond/protocols/netrpc.py +++ b/trytond/protocols/netrpc.py @@ -23,7 +23,7 @@ class NetRPCClientThread(threading.Thread): self.running = True try: pysocket = PySocket(self.sock) - except: + except Exception: self.sock.close() self.threads.remove(self) return False @@ -38,7 +38,7 @@ class NetRPCClientThread(threading.Thread): timeout = 0 try: msg = pysocket.receive() - except: + except Exception: pysocket.disconnect() self.threads.remove(self) return False @@ -51,7 +51,7 @@ class NetRPCClientThread(threading.Thread): for line in traceback.format_exception(*sys.exc_info()): try: line = line.encode('utf-8', 'ignore') - except: + except Exception: continue tb_s += line for path in sys.path: @@ -63,7 +63,7 @@ class NetRPCClientThread(threading.Thread): try: pysocket.send(exception.args, exception=True, traceback=tb_s) - except: + except Exception: pysocket.disconnect() self.threads.remove(self) return False @@ -83,7 +83,7 @@ class NetRPCServerThread(threading.Thread): try: socket.getaddrinfo(interface or None, port, socket.AF_INET6) self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) - except: + except Exception: pass if self.socket is None: self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -107,10 +107,10 @@ class NetRPCServerThread(threading.Thread): self.secure) self.threads.append(c_thread) c_thread.start() - except: + except Exception: try: self.socket.close() - except: + except Exception: pass return False @@ -121,7 +121,7 @@ class NetRPCServerThread(threading.Thread): thread = self.threads[0] thread.stop() thread.join() - except: + except Exception: pass try: if hasattr(socket, 'SHUT_RDWR'): @@ -129,5 +129,5 @@ class NetRPCServerThread(threading.Thread): else: self.socket.shutdown(2) self.socket.close() - except: + except Exception: return False diff --git a/trytond/protocols/webdav.py b/trytond/protocols/webdav.py index 9ec70932b4..05d8873fe9 100644 --- a/trytond/protocols/webdav.py +++ b/trytond/protocols/webdav.py @@ -65,7 +65,7 @@ if not hasattr(WebDAVServer.DAVRequestHandler, '_config'): def get(self, name, default=None): try: return self[name] - except: + except Exception: return default @@ -107,7 +107,7 @@ class WebDAVServerThread(threading.Thread): try: socket.getaddrinfo(interface or None, port, socket.AF_INET6) ipv6 = True - except: + except Exception: pass if secure: handler_class = SecureWebDAVAuthRequestHandler @@ -193,7 +193,7 @@ class TrytonDAVInterface(iface.dav_interface): try: cursor = database.cursor() lists = database.list(cursor) - except: + except Exception: lists = [] finally: cursor.close() diff --git a/trytond/protocols/xmlrpc.py b/trytond/protocols/xmlrpc.py index 1e370f7c15..59a987dca9 100644 --- a/trytond/protocols/xmlrpc.py +++ b/trytond/protocols/xmlrpc.py @@ -63,12 +63,12 @@ class GenericXMLRPCRequestHandler: } return dispatch(host, port, 'XML-RPC', database_name, user, session, object_type, object_name, method, *params) - except: + except Exception: tb_s = '' for line in traceback.format_exception(*sys.exc_info()): try: line = line.encode('utf-8', 'ignore') - except: + except Exception: continue tb_s += line for path in sys.path: @@ -101,7 +101,7 @@ class SimpleXMLRPCRequestHandler(GenericXMLRPCRequestHandler, password) self.tryton = {'user': user_id, 'session': session} return res - except: + except Exception: pass self.send_error(401, 'Unauthorized') self.send_header("WWW-Authenticate", 'Basic realm="Tryton"') @@ -142,7 +142,7 @@ class SimpleXMLRPCRequestHandler(GenericXMLRPCRequestHandler, response = self.server._marshaled_dispatch( data, getattr(self, '_dispatch', None) ) - except: # This should only happen if the module is buggy + except Exception: # This should only happen if the module is buggy # internal error, report as HTTP server error self.send_response(500) self.end_headers() @@ -219,7 +219,7 @@ class XMLRPCDaemon(threading.Thread): try: socket.getaddrinfo(interface or None, port, socket.AF_INET6) ipv6 = True - except: + except Exception: pass if secure: handler_class = SecureXMLRPCRequestHandler diff --git a/trytond/pysocket.py b/trytond/pysocket.py index b824c6d96d..ffbb07dd01 100644 --- a/trytond/pysocket.py +++ b/trytond/pysocket.py @@ -57,7 +57,7 @@ class PySocket: socket.SOCK_STREAM) self.sock.settimeout(CONNECT_TIMEOUT) self.sock.connect((host, int(port))) - except: + except Exception: self.sock = None if self.sock is None: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -72,7 +72,7 @@ class PySocket: sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) sock.settimeout(CONNECT_TIMEOUT) sock.connect((host, int(port))) - except: + except Exception: sock = None if sock is None: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -84,7 +84,7 @@ class PySocket: elif hasattr(socket, 'ssl'): socket.ssl(sock) self.ssl = True - except: + except Exception: pass self.sock.settimeout(TIMEOUT) if self.ssl: @@ -111,10 +111,10 @@ class PySocket: sock.sock_shutdown(shutdown_value) else: sock.shutdown(shutdown_value) - except: + except Exception: pass sock.close() - except: + except Exception: pass self.sock = None self.ssl = False diff --git a/trytond/res/user.py b/trytond/res/user.py index b100cecd41..535b31f26c 100644 --- a/trytond/res/user.py +++ b/trytond/res/user.py @@ -183,7 +183,7 @@ class User(ModelSQL, ModelView): for _, model in self.pool.iterobject(): try: model.fields_view_get(cursor.dbname) - except: + except Exception: pass return res diff --git a/trytond/server.py b/trytond/server.py index ec5c1cbee8..7bfc652e73 100644 --- a/trytond/server.py +++ b/trytond/server.py @@ -232,7 +232,7 @@ class TrytonServer(object): if CONFIG['auto_reload'] and monitor(): try: Pool.start() - except: + except Exception: pass for dbname in Pool.database_list(): pool = Pool(dbname) diff --git a/trytond/tools/convert.py b/trytond/tools/convert.py index 61fddb9618..13cd4a366e 100644 --- a/trytond/tools/convert.py +++ b/trytond/tools/convert.py @@ -433,7 +433,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler): try: self.sax_parser.parse(source) - except: + except Exception: logging.getLogger("convert").error( "Error while parsing xml file:\n" +\ self.current_state() @@ -524,7 +524,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler): ref_mode, ref_id = browse_record[key].split(',', 1) try: ref_id = safe_eval(ref_id) - except: + except Exception: pass if isinstance(ref_id, (list, tuple)): ref_id = ref_id[0] @@ -1001,7 +1001,7 @@ def post_import(cursor, pool, module, to_delete): model_obj.delete(cursor, user, db_id) mdata_delete.append(mdata_id) cursor.commit() - except: + except Exception: cursor.rollback() tb_s = reduce(lambda x, y: x + y, traceback.format_exception(*sys.exc_info())) @@ -1022,7 +1022,7 @@ def post_import(cursor, pool, module, to_delete): transition_obj.delete(cursor, user, db_id) mdata_delete.append(mdata_id) cursor.commit() - except: + except Exception: cursor.rollback() logging.getLogger("convert").error( 'Could not delete id: %d of model workflow.transition' % diff --git a/trytond/tools/misc.py b/trytond/tools/misc.py index 8967189453..3d85ab1ea3 100644 --- a/trytond/tools/misc.py +++ b/trytond/tools/misc.py @@ -133,7 +133,7 @@ def file_open(name, mode="r", subdir='modules'): return StringIO.StringIO(zfile.read(os.path.join( os.path.basename(head), zipname).replace( os.sep, '/'))) - except: + except Exception: name2 = os.path.normpath(os.path.join(head + '.zip', zipname)) for i in (name2, name, name3): if i and os.path.isfile(i): diff --git a/trytond/webdav/webdav.py b/trytond/webdav/webdav.py index 24c3350904..dc4de1fc23 100644 --- a/trytond/webdav/webdav.py +++ b/trytond/webdav/webdav.py @@ -359,7 +359,7 @@ class Collection(ModelSQL, ModelView): try: if attachment.datas_size: size = str(attachment.datas_size) - except: + except Exception: pass if attachment.id == object_id: res = size @@ -480,7 +480,7 @@ class Collection(ModelSQL, ModelView): try: if attachment.datas is not False: data = base64.decodestring(attachment.datas) - except: + except Exception: pass if attachment.id == object_id: res = data @@ -527,14 +527,14 @@ class Collection(ModelSQL, ModelView): 'name': name, 'resource': '%s,%s' % (object_name, object_id), }, context=context) - except: + except Exception: raise DAV_Forbidden else: try: attachment_obj.write(cursor, user, object_id2, { 'datas': base64.encodestring(data or ''), }, context=context) - except: + except Exception: raise DAV_Forbidden return @@ -553,7 +553,7 @@ class Collection(ModelSQL, ModelView): 'name': name, 'parent': object_id, }, context=context) - except: + except Exception: raise DAV_Forbidden return 201 @@ -566,7 +566,7 @@ class Collection(ModelSQL, ModelView): raise DAV_Forbidden try: self.delete(cursor, user, object_id, context=context) - except: + except Exception: raise DAV_Forbidden return 200 @@ -582,7 +582,7 @@ class Collection(ModelSQL, ModelView): model_obj = self.pool.get(object_name) try: model_obj.delete(cursor, user, object_id, context=context) - except: + except Exception: raise DAV_Forbidden return 200