diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 908706a3..13e55c4a 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 348a586a..b45ddaf9 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -188,7 +188,7 @@ def execute(self, query, args=None): 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 @@ def executemany(self, query, args): 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_common.py b/setup_common.py index 03c39bb7..4f72cda3 100644 --- a/setup_common.py +++ b/setup_common.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + try: # Python 2.x from ConfigParser import SafeConfigParser diff --git a/setup_posix.py b/setup_posix.py index cfcf33ca..9f3d9e64 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -1,5 +1,8 @@ -import os, sys -from ConfigParser import SafeConfigParser +# -*- coding: utf-8 -*- + +import os +import sys +from setup_common import 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 ead69822..c45353fd 100644 --- a/tests/test_MySQLdb_capabilities.py +++ b/tests/test_MySQLdb_capabilities.py @@ -76,8 +76,8 @@ def test_bug_2671682(self): from MySQLdb.constants import ER try: self.cursor.execute("describe some_non_existent_table"); - except self.connection.ProgrammingError, msg: - self.assertEquals(msg[0], ER.NO_SUCH_TABLE) + except self.connection.ProgrammingError as msg: + self.assertTrue(str(ER.NO_SUCH_TABLE) in str(msg)) def test_bug_3514287(self): c = self.cursor