diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 908706a..13e55c4 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -33,7 +33,11 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue): connection.messages.append(error) del cursor del connection - raise errorclass, errorvalue + if errorclass is not None: + raise errorclass(errorvalue) + else: + raise Exception(errorvalue) + re_numeric_part = re.compile(r"^(\d+)") diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 348a586..b45ddaf 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -188,7 +188,7 @@ class BaseCursor(object): try: r = None r = self._query(query) - except TypeError, m: + except TypeError as m: if m.args[0] in ("not enough arguments for format string", "not all arguments converted"): self.messages.append((ProgrammingError, m.args[0])) @@ -247,7 +247,7 @@ class BaseCursor(object): for key, item in a.iteritems())) else: q.append(qv % tuple([db.literal(item) for item in a])) - except TypeError, msg: + except TypeError as msg: if msg.args[0] in ("not enough arguments for format string", "not all arguments converted"): self.errorhandler(self, ProgrammingError, msg.args[0]) diff --git a/setup_posix.py b/setup_posix.py index cfcf33c..dc9b90b 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -1,5 +1,9 @@ import os, sys -from ConfigParser import SafeConfigParser +try: + from ConfigParser import SafeConfigParser +except ImportError: + # Probably running Python 3.x + from configparser import ConfigParser as SafeConfigParser # This dequote() business is required for some older versions # of mysql_config diff --git a/tests/test_MySQLdb_capabilities.py b/tests/test_MySQLdb_capabilities.py index ead6982..31e5f6f 100644 --- a/tests/test_MySQLdb_capabilities.py +++ b/tests/test_MySQLdb_capabilities.py @@ -76,7 +76,7 @@ class test_MySQLdb(capabilities.DatabaseTest): from MySQLdb.constants import ER try: self.cursor.execute("describe some_non_existent_table"); - except self.connection.ProgrammingError, msg: + except self.connection.ProgrammingError as msg: self.assertEquals(msg[0], ER.NO_SUCH_TABLE) def test_bug_3514287(self):