Catch only Exception according to PEP 352

This commit is contained in:
Cédric Krier
2010-07-08 19:52:57 +02:00
parent 9c0a1116f0
commit df7f9b9597
35 changed files with 96 additions and 96 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ try:
'..', '..', 'tryton')))
if os.path.isdir(DIR):
sys.path.insert(0, os.path.dirname(DIR))
except:
except Exception:
pass
# True only if running as a py2exe app
+1 -1
View File
@@ -58,7 +58,7 @@ class TrytonClient(object):
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(
os.path.join(PIXMAPS_DIR, fname))
except:
except Exception:
continue
icon_set = gtk.IconSet(pixbuf)
factory.add(name, icon_set)
+1 -1
View File
@@ -32,7 +32,7 @@ class CellRendererFloat(CellRendererInteger):
or len(new_decimal) > self.digits[1]:
entry.stop_emission('insert-text')
except:
except Exception:
entry.stop_emission('insert-text')
gobject.type_register(CellRendererFloat)
+1 -1
View File
@@ -24,7 +24,7 @@ class CellRendererInteger(CellRendererText):
if new_value == '-':
return
locale.atoi(new_value)
except:
except Exception:
entry.stop_emission('insert-text')
gobject.type_register(CellRendererInteger)
+11 -11
View File
@@ -243,7 +243,7 @@ def file_selection(title, filename='', parent=None,
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, 128, 128)
img.set_from_pixbuf(pixbuf)
have_preview = True
except:
except Exception:
have_preview = False
win.set_preview_widget_active(have_preview)
return
@@ -266,7 +266,7 @@ def file_selection(title, filename='', parent=None,
CONFIG['client.default_path'] = \
os.path.dirname(filepath)
CONFIG.save()
except:
except Exception:
pass
parent.present()
win.destroy()
@@ -278,7 +278,7 @@ def file_selection(title, filename='', parent=None,
try:
CONFIG['client.default_path'] = \
os.path.dirname(filenames[0])
except:
except Exception:
pass
parent.present()
win.destroy()
@@ -291,11 +291,11 @@ def file_open(filename, type, parent, print_p=False):
operation = 'print'
try:
os.startfile(os.path.normpath(filename), operation)
except:
except Exception:
# Try without operation, it is not supported on version < 2.5
try:
os.startfile(os.path.normpath(filename))
except:
except Exception:
save_name = file_selection(_('Save As...'), parent=parent,
action=gtk.FILE_CHOOSER_ACTION_SAVE)
if save_name:
@@ -313,7 +313,7 @@ def file_open(filename, type, parent, print_p=False):
if not pid:
try:
os.execv('/usr/bin/open', ['/usr/bin/open', filename])
except:
except Exception:
sys.exit(0)
time.sleep(0.1)
sys.exit(0)
@@ -353,7 +353,7 @@ def file_open(filename, type, parent, print_p=False):
if not pid:
try:
os.execv(prog, args)
except:
except Exception:
sys.exit(0)
time.sleep(0.1)
sys.exit(0)
@@ -380,7 +380,7 @@ def mailto(to=None, cc=None, subject=None, body=None, attachment=None):
if not pid:
try:
os.execv(prog, args)
except:
except Exception:
sys.exit(0)
time.sleep(0.1)
sys.exit(0)
@@ -1078,7 +1078,7 @@ def text_to_float_time(text, conv=None):
try:
try:
return locale.atof(text)
except:
except Exception:
pass
if conv:
tmp_conv = FLOAT_TIME_CONV.copy()
@@ -1104,7 +1104,7 @@ def text_to_float_time(text, conv=None):
try:
value += abs(locale.atof(buf))
continue
except:
except Exception:
pass
for sep in conv.keys():
if buf.endswith(sep):
@@ -1113,7 +1113,7 @@ def text_to_float_time(text, conv=None):
if text.startswith('-'):
value *= -1
return value
except:
except Exception:
return 0.0
def float_time_to_text(val, conv=None):
+3 -3
View File
@@ -185,7 +185,7 @@ class DateEntry(gtk.Entry):
try:
time.strptime(self.compute_date(text, default=default, year='2000'),
self.format)
except:
except Exception:
return False
return True
@@ -194,7 +194,7 @@ class DateEntry(gtk.Entry):
date = self.compute_date(self.get_text())
try:
res = datetime.datetime(*time.strptime(date, self.format)[:6])
except:
except Exception:
return None
self.set_text(date)
return res
@@ -327,7 +327,7 @@ def compute_date(cmd, dt, format):
dt = datetime.datetime.now()
try:
return f(dt, groups)
except:
except Exception:
continue
if __name__ == '__main__':
+1 -1
View File
@@ -137,7 +137,7 @@ class ConfigManager(object):
configparser.add_section(section)
configparser.set(section, name, self.config[entry])
configparser.write(open(self.rcfile, 'wb'))
except:
except Exception:
logging.getLogger('common.options').warn(
_('Unable to write config file %s!') % \
(self.rcfile,))
+4 -4
View File
@@ -34,7 +34,7 @@ except ImportError:
igemacintegration = None
try:
import gtkspell
except:
except Exception:
gtkspell = None
_ = gettext.gettext
@@ -936,7 +936,7 @@ class Main(object):
try:
shortcuts = rpc.execute('model', 'ir.ui.view_sc', 'get_sc',
user, 'ir.ui.menu', rpc.CONTEXT)
except:
except Exception:
shortcuts = []
menu = gtk.Menu()
for shortcut in shortcuts:
@@ -1096,7 +1096,7 @@ class Main(object):
len(ids2))
self.sb_requests.set_text(message)
return (ids, ids2)
except:
except Exception:
if exception:
raise
return ([], [])
@@ -1123,7 +1123,7 @@ class Main(object):
try:
prefs = rpc.execute('model', 'res.user', 'get_preferences',
False, rpc.CONTEXT)
except:
except Exception:
prefs = None
if prefs and 'language_direction' in prefs:
translate.set_language_direction(prefs['language_direction'])
+2 -2
View File
@@ -67,7 +67,7 @@ class DBCreate(object):
if self.combo_language and host and port:
common.refresh_langlist(self.combo_language, host, port)
self.server_connection_state(True)
except:
except Exception:
self.server_connection_state(False)
return False
CONFIG['login.server'] = host
@@ -317,7 +317,7 @@ class DBCreate(object):
self.combo_language.set_model(liststore)
try:
common.refresh_langlist(self.combo_language, host, port)
except:
except Exception:
self.button_create.set_sensitive(False)
while True:
+2 -2
View File
@@ -184,7 +184,7 @@ class Form(SignalEvent):
new_value = value[:position] + new_text + value[position:]
try:
locale.atoi(new_value)
except:
except Exception:
widget.stop_emission('insert-text')
entry.connect('insert_text', sig_insert_text)
table.attach(entry, 1, 2, 1, 2)
@@ -275,7 +275,7 @@ class Form(SignalEvent):
sdt = szone.localize(datetime, is_dst=True)
ldt = sdt.astimezone(lzone)
date = ldt
except:
except Exception:
pass
value = common.datetime_strftime(date, display_format)
message_str += val + ' ' + value +'\n'
+1 -1
View File
@@ -92,7 +92,7 @@ You can save any graphs in PNG file with right-click on it.
try:
self.number = int(CONFIG['tip.position'])
except:
except Exception:
self.number = 0
self.tip_set()
+1 -1
View File
@@ -197,7 +197,7 @@ class Tree(SignalEvent):
try:
icon.set_from_stock(res[icon_name],
gtk.ICON_SIZE_BUTTON)
except:
except Exception:
pass
hbox = gtk.HBox(spacing=6)
+7 -7
View File
@@ -88,7 +88,7 @@ class CharField(object):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
return
@@ -191,7 +191,7 @@ class FloatField(CharField):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
record.signal('record-changed')
@@ -213,7 +213,7 @@ class NumericField(CharField):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
return
@@ -240,7 +240,7 @@ class BooleanField(CharField):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
return
@@ -313,7 +313,7 @@ class M2OField(CharField):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
return
@@ -321,7 +321,7 @@ class M2OField(CharField):
elif force_change:
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
return
record.signal('record-changed')
@@ -603,7 +603,7 @@ class ReferenceField(CharField):
record.modified_fields.setdefault(self.name)
try:
self.sig_changed(record)
except:
except Exception:
record.value[self.name] = internal
record.modified = prev_modified
return
+2 -2
View File
@@ -28,7 +28,7 @@ class EvalEnvironment(dict):
def get(self, item, default=None):
try:
return self.__getattr__(item)
except:
except Exception:
pass
return super(EvalEnvironment, self).get(item, default)
@@ -462,6 +462,6 @@ class Record(SignalEvent):
])
try:
self.attachment_count = rpc.execute(*args)
except:
except Exception:
return 0
return self.attachment_count
+4 -4
View File
@@ -88,7 +88,7 @@ class Screen(SignalEvent):
self.fields_view_tree = rpc.execute('model',
self.model_name, 'fields_view_get', False,
'tree', ctx)
except:
except Exception:
return
self.filter_widget = Form(self.fields_view_tree['arch'],
self.fields_view_tree['fields'], self.model_name,
@@ -143,7 +143,7 @@ class Screen(SignalEvent):
self.model_name, 'search_count', values, ctx)
else:
self.search_count = len(ids)
except:
except Exception:
ids = []
if only_ids:
return ids
@@ -201,11 +201,11 @@ class Screen(SignalEvent):
self.__current_record = record
try:
offset = int(self.filter_widget.get_offset())
except:
except Exception:
offset = 0
try:
pos = self.group.index(record)
except:
except Exception:
pos = -1
self.signal('record-message', (pos + offset, len(self.group) + offset,
self.search_count, record and record.id))
@@ -73,7 +73,7 @@ class Calendar(WidgetInterface):
return False
try:
date = datetime.date(*time.strptime(value, self.format)[:3])
except:
except Exception:
return False
return datetime_strftime(date, DT_FORMAT)
@@ -209,7 +209,7 @@ class DateTime(WidgetInterface):
return False
try:
date = datetime.datetime(*time.strptime(value, self.format)[:6])
except:
except Exception:
return False
if 'timezone' in rpc.CONTEXT and timezone:
try:
@@ -219,7 +219,7 @@ class DateTime(WidgetInterface):
ldt = lzone.localize(date, is_dst=True)
sdt = ldt.astimezone(szone)
date = sdt
except:
except Exception:
pass
return datetime_strftime(date, DHM_FORMAT)
@@ -246,7 +246,7 @@ class DateTime(WidgetInterface):
sdt = szone.localize(date, is_dst=True)
ldt = sdt.astimezone(lzone)
date = ldt
except:
except Exception:
pass
format = self.format
if date.year < 10:
@@ -15,7 +15,7 @@ class Float(Integer):
def set_value(self, record, field):
try:
value = locale.atof(self.entry.get_text())
except:
except Exception:
value = 0.0
return field.set_client(record, value)
@@ -58,5 +58,5 @@ class Float(Integer):
or len(new_decimal) > digits[1]:
entry.stop_emission('insert-text')
except:
except Exception:
entry.stop_emission('insert-text')
@@ -158,7 +158,7 @@ class Image(WidgetInterface):
try:
loader = gtk.gdk.PixbufLoader(ftype)
loader.write(data, len(data))
except:
except Exception:
continue
pixbuf = loader.get_pixbuf()
if pixbuf:
@@ -17,7 +17,7 @@ class Integer(Char):
def set_value(self, record, field):
try:
value = locale.atoi(self.entry.get_text())
except:
except Exception:
value = 0
return field.set_client(record, value)
@@ -41,5 +41,5 @@ class Integer(Char):
if new_value == '-':
return
locale.atoi(new_value)
except:
except Exception:
entry.stop_emission('insert-text')
@@ -165,7 +165,7 @@ class Many2Many(WidgetInterface):
try:
result = rpc.execute('model', self.attrs['relation'], 'read',
ids, ['rec_name'], rpc.CONTEXT)
except:
except Exception:
return str(ids)
return ', '.join(x['rec_name'] for x in result)
@@ -104,7 +104,7 @@ class Button(object):
icon = gtk.Image()
icon.set_from_stock(stock, gtk.ICON_SIZE_SMALL_TOOLBAR)
self.widget.set_image(icon)
except:
except Exception:
log = logging.getLogger('common')
log.warning(_('Wrong icon for the button!'))
else:
@@ -7,7 +7,7 @@ from tryton.config import CONFIG
try:
import gtkspell
except:
except Exception:
gtkspell = None
@@ -51,7 +51,7 @@ class TextBox(WidgetInterface):
spell = None
try:
spell = gtkspell.get_from_text_view(self.textview)
except:
except Exception:
pass
if not value and self.attrs.get('spell') \
@@ -64,11 +64,11 @@ class TextBox(WidgetInterface):
if self.lang != language:
try:
spell.set_language(language)
except:
except Exception:
spell.detach()
del spell
self.lang = language
except:
except Exception:
pass
elif spell:
spell.detach()
@@ -98,7 +98,7 @@ class TextBox(WidgetInterface):
spell = None
try:
spell = gtkspell.get_from_text_view(self.textview)
except:
except Exception:
pass
if self.attrs.get('spell') and CONFIG['client.spellcheck'] \
@@ -110,11 +110,11 @@ class TextBox(WidgetInterface):
if self.lang != language:
try:
spell.set_language(language)
except:
except Exception:
spell.detach()
del spell
self.lang = language
except:
except Exception:
pass
elif spell:
spell.detach()
@@ -79,7 +79,7 @@ def save(widget, graph, window):
CONFIG['client.default_path'] = \
os.path.dirname(filepath)
CONFIG.save()
except:
except Exception:
pass
if response == gtk.RESPONSE_OK:
if width and height and filename:
+2 -2
View File
@@ -70,7 +70,7 @@ class AdaptModelGroup(gtk.GenericTreeModel):
if old_pos != pos:
new_order[old_pos] = pos
pos += 1
except:
except Exception:
continue
self.group.sort(lambda x, y: \
cmp(new_order[ids2pos[x.id]], new_order[ids2pos[y.id]]))
@@ -512,7 +512,7 @@ class ViewList(ParserView):
try:
rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
self.screen.model_name, fields, rpc.CONTEXT)
except:
except Exception:
pass
self.widget_tree.destroy()
del self.screen
@@ -372,7 +372,7 @@ class Date(Char):
return False
try:
date = datetime.date(*time.strptime(text, self.display_format)[:3])
except:
except Exception:
return False
return common.datetime_strftime(date, self.server_format)
@@ -399,7 +399,7 @@ class Datetime(Date):
sdt = szone.localize(date, is_dst=True)
ldt = sdt.astimezone(lzone)
date = ldt
except:
except Exception:
pass
return common.datetime_strftime(date, self.display_format)
@@ -409,7 +409,7 @@ class Datetime(Date):
try:
date = datetime.datetime(*time.strptime(text,
self.display_format)[:6])
except:
except Exception:
return False
if 'timezone' in rpc.CONTEXT:
try:
@@ -419,7 +419,7 @@ class Datetime(Date):
ldt = lzone.localize(date, is_dst=True)
sdt = ldt.astimezone(szone)
date = sdt
except:
except Exception:
pass
return common.datetime_strftime(date, self.server_format)
@@ -453,7 +453,7 @@ class Float(Char):
def value_from_text(self, record, text):
try:
return locale.atof(text)
except:
except Exception:
return 0.0
@@ -99,7 +99,7 @@ class Calendar(Interface):
def _date_get(self, value):
try:
date = datetime.date(*time.strptime(value, self.format)[:3])
except:
except Exception:
return False
if self.attrs.get('type', 'date') == 'datetime':
return datetime_strftime(datetime.datetime.combine(date,
@@ -139,7 +139,7 @@ class Calendar(Interface):
return ''
try:
return datetime_strftime(value, self.format)
except:
except Exception:
return ''
i = self.liststore.get_iter_root()
@@ -19,11 +19,11 @@ class Float(Integer):
def _value_get(self):
try:
value1 = locale.atof(self.entry1.get_text())
except:
except Exception:
value1 = False
try:
value2 = locale.atof(self.entry2.get_text())
except:
except Exception:
value2 = False
return self._get_clause(value1, value2)
@@ -62,5 +62,5 @@ class Float(Integer):
return
if len(str(int(locale.atof(new_value)))) > self.digits[0]:
widget.stop_emission('insert-text')
except:
except Exception:
widget.stop_emission('insert-text')
@@ -63,11 +63,11 @@ class Integer(Interface):
def _value_get(self):
try:
value1 = locale.atoi(self.entry1.get_text())
except:
except Exception:
value1 = False
try:
value2 = locale.atoi(self.entry2.get_text())
except:
except Exception:
value2 = False
return self._get_clause(value1, value2)
@@ -132,5 +132,5 @@ class Integer(Interface):
if new_value == '-':
return
locale.atoi(new_value)
except:
except Exception:
widget.stop_emission('insert-text')
+4 -4
View File
@@ -86,7 +86,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
sdt = szone.localize(obj[field], is_dst=True)
ldt = sdt.astimezone(lzone)
obj[field] = ldt
except:
except Exception:
pass
obj[field] = common.datetime_strftime(obj[field],
display_format)
@@ -105,7 +105,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
0, None, None,
rpc.CONTEXT, ['rec_name'])
selection = [(x['id'], x['rec_name']) for x in result]
except:
except Exception:
selection = []
else:
if not isinstance(self.fields_type[field]['selection'],
@@ -115,7 +115,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
self.view['model'],
self.fields_type[field]['selection'],
rpc.CONTEXT)
except:
except Exception:
selection = []
self.fields_type[field]['selection'] = selection
elif field_type in ('float', 'numeric'):
@@ -320,7 +320,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
return None
tree = node[2]
return (tuple(path), node)
except:
except Exception:
return None
class ViewTree(object):
+1 -1
View File
@@ -256,7 +256,7 @@ class WinImport(object):
try:
data = csv.reader(open(fname, 'rb'), quotechar=csvdel,
delimiter=csvsep)
except:
except Exception:
common.warning(_('Error opening CSV file'), self.dialog,
_('Error'))
return True
+1 -1
View File
@@ -129,7 +129,7 @@ class Wizard(SignalEvent):
rpc.execute('wizard', self.action, 'delete', self.wiz_id)
#XXX to remove when company displayed in status bar
rpc.context_reload()
except:
except Exception:
pass
Main.get_main()._win_del(self.widget)
+5 -5
View File
@@ -68,7 +68,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)
@@ -83,7 +83,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)
@@ -95,7 +95,7 @@ class PySocket:
elif hasattr(socket, 'ssl'):
ssl_sock = socket.ssl(sock)
self.ssl = True
except:
except Exception:
pass
self.sock.settimeout(TIMEOUT)
if self.ssl:
@@ -143,10 +143,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
+6 -6
View File
@@ -48,7 +48,7 @@ def db_list(host, port):
_SEMAPHORE.release()
logging.getLogger('rpc.result').debug(repr(res))
return res
except:
except Exception:
logging.getLogger('rpc.result').debug(repr(None))
return None
@@ -80,7 +80,7 @@ def db_exec(host, port, method, *args):
_SEMAPHORE.release()
logging.getLogger('rpc.result').debug(repr(res))
return res
except:
except Exception:
raise
def server_version(host, port):
@@ -111,7 +111,7 @@ def server_version(host, port):
_SEMAPHORE.release()
logging.getLogger('rpc.result').debug(repr(res))
return res
except:
except Exception:
logging.getLogger('rpc.result').debug(repr(None))
return None
@@ -170,7 +170,7 @@ def logout():
logging.getLogger('rpc.result').debug(repr(res))
finally:
_SEMAPHORE.release()
except:
except Exception:
pass
_SOCK.disconnect()
_SOCK = None
@@ -185,7 +185,7 @@ def context_reload():
global CONTEXT, TIMEZONE
try:
context = execute('model', 'res.user', 'get_preferences', True, {})
except:
except Exception:
return
CONTEXT = {}
for i in context:
@@ -194,7 +194,7 @@ def context_reload():
if i == 'timezone':
try:
TIMEZONE = execute('common', None, 'timezone_get')
except:
except Exception:
pass
def _execute(blocking, *args):
+1 -1
View File
@@ -177,7 +177,7 @@ def setlang(lang=None, locale_dict=None):
os.environ['LC_MESSAGES'] = lang2 + '.' + encoding
os.environ['LANG'] = lang + '.' + encoding
locale.setlocale(locale.LC_ALL, str(lang2 + '.' + encoding))
except:
except Exception:
logging.getLogger('translate').info(
_('Unable to set locale %s') % lang2 + '.' + encoding)
+2 -2
View File
@@ -131,7 +131,7 @@ class Dialog(object):
rpc.execute('model', 'ir.action.wizard_size', 'set_size',
self.action, self.screen.name, width, height,
rpc.CONTEXT)
except:
except Exception:
pass
if res < len(self.states) and res >= 0:
@@ -249,5 +249,5 @@ class Wizard(object):
rpc.execute('wizard', action, 'delete', wiz_id)
#XXX to remove when company displayed in status bar
rpc.context_reload()
except:
except Exception:
pass