From 5d8964a4754cde8371c1836765cd546e7befa905 Mon Sep 17 00:00:00 2001 From: Giuseppe Sucameli Date: Mon, 27 May 2013 01:29:53 +0200 Subject: [PATCH] DBManager: replace the deprecated Exception.message attribute --- python/plugins/db_manager/db_plugins/plugin.py | 11 ++++++++--- python/plugins/db_manager/dlg_db_error.py | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/python/plugins/db_manager/db_plugins/plugin.py b/python/plugins/db_manager/db_plugins/plugin.py index 7987db241b77..7812c6258cc0 100644 --- a/python/plugins/db_manager/db_plugins/plugin.py +++ b/python/plugins/db_manager/db_plugins/plugin.py @@ -29,16 +29,21 @@ class BaseError(Exception): """Base class for exceptions in the plugin.""" def __init__(self, e): - msg = e if isinstance(e, (str,unicode,QString)) else e.message + if isinstance(e, Exception): + msg = e.args[0] if len(e.args) > 0 else '' + else: + msg = e try: msg = unicode( msg ) except UnicodeDecodeError: msg = unicode( msg, 'utf-8' ) + + self.msg = msg Exception.__init__(self, msg) def __unicode__(self): - return self.message + return self.msg def __str__(self): return unicode(self).encode('utf-8') @@ -55,7 +60,7 @@ def __init__(self, e, query=None): self.query = unicode( query ) if query != None else None def __unicode__(self): - if self.query == None: + if self.query is None: return BaseError.__unicode__(self) msg = u"Error:\n%s" % BaseError.__unicode__(self) diff --git a/python/plugins/db_manager/dlg_db_error.py b/python/plugins/db_manager/dlg_db_error.py index 408d472934e5..80416ec86ed1 100644 --- a/python/plugins/db_manager/dlg_db_error.py +++ b/python/plugins/db_manager/dlg_db_error.py @@ -36,10 +36,10 @@ def __init__(self, e, parent=None): def sanitize(txt): return "" if txt == None else "
" + txt.replace('<','<') + "
" - if isinstance(e, DbError) and hasattr(e, 'query'): - self.setQueryMessage( sanitize(e.message), sanitize(e.query) ) + if isinstance(e, DbError): + self.setQueryMessage( sanitize(e.msg), sanitize(e.query) ) else: - self.setMessage( sanitize(e.message) ) + self.setMessage( sanitize(e.msg) ) def setMessage(self, msg): self.txtErrorMsg.setHtml(msg)