From a7f55a5d6a89cc2f3b750a2b3f06c69cf6e02a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Malo?= Date: Wed, 3 Oct 2012 13:10:25 -0400 Subject: Patch 1/4: Minor exception handling improvements (don't swallow program exits) https://sourceforge.net/p/mysql-python/patches/77/ --- MySQLdb/MySQLdb/cursors.py | 4 ++++ MySQLdb/MySQLdb/times.py | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'MySQLdb') diff --git a/MySQLdb/MySQLdb/cursors.py b/MySQLdb/MySQLdb/cursors.py index 50614f9..ffe60c0 100644 --- a/MySQLdb/MySQLdb/cursors.py +++ b/MySQLdb/MySQLdb/cursors.py @@ -174,6 +174,8 @@ class BaseCursor(object): else: self.messages.append((TypeError, m)) self.errorhandler(self, TypeError, m) + except (SystemExit, KeyboardInterrupt): + raise except: exc, value, tb = sys.exc_info() del tb @@ -223,6 +225,8 @@ class BaseCursor(object): self.errorhandler(self, ProgrammingError, msg.args[0]) else: self.errorhandler(self, TypeError, msg) + except (SystemExit, KeyboardInterrupt): + raise except: exc, value, tb = sys.exc_info() del tb diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py index 35adc7b..bc92eb4 100644 --- a/MySQLdb/MySQLdb/times.py +++ b/MySQLdb/MySQLdb/times.py @@ -52,6 +52,8 @@ def DateTime_or_None(s): try: d, t = s.split(sep, 1) return datetime(*[ int(x) for x in d.split('-')+t.split(':') ]) + except (SystemExit, KeyboardInterrupt): + raise except: return Date_or_None(s) @@ -79,8 +81,12 @@ def Time_or_None(s): return None def Date_or_None(s): - try: return date(*[ int(x) for x in s.split('-',2)]) - except: return None + try: + return date(*[ int(x) for x in s.split('-',2)]) + except (SystemExit, KeyboardInterrupt): + raise + except: + return None def DateTime2literal(d, c): """Format a DateTime object as an ISO timestamp.""" @@ -97,5 +103,9 @@ def mysql_timestamp_converter(s): s = s + "0"*(14-len(s)) # padding parts = map(int, filter(None, (s[:4],s[4:6],s[6:8], s[8:10],s[10:12],s[12:14]))) - try: return Timestamp(*parts) - except: return None + try: + return Timestamp(*parts) + except (SystemExit, KeyboardInterrupt): + raise + except: + return None -- cgit v1.2.1