mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
Patch 1/4: Minor exception handling improvements (don't swallow program exits)
https://sourceforge.net/p/mysql-python/patches/77/
This commit is contained in:
@ -174,6 +174,8 @@ class BaseCursor(object):
|
|||||||
else:
|
else:
|
||||||
self.messages.append((TypeError, m))
|
self.messages.append((TypeError, m))
|
||||||
self.errorhandler(self, TypeError, m)
|
self.errorhandler(self, TypeError, m)
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
raise
|
||||||
except:
|
except:
|
||||||
exc, value, tb = sys.exc_info()
|
exc, value, tb = sys.exc_info()
|
||||||
del tb
|
del tb
|
||||||
@ -223,6 +225,8 @@ class BaseCursor(object):
|
|||||||
self.errorhandler(self, ProgrammingError, msg.args[0])
|
self.errorhandler(self, ProgrammingError, msg.args[0])
|
||||||
else:
|
else:
|
||||||
self.errorhandler(self, TypeError, msg)
|
self.errorhandler(self, TypeError, msg)
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
raise
|
||||||
except:
|
except:
|
||||||
exc, value, tb = sys.exc_info()
|
exc, value, tb = sys.exc_info()
|
||||||
del tb
|
del tb
|
||||||
|
@ -52,6 +52,8 @@ def DateTime_or_None(s):
|
|||||||
try:
|
try:
|
||||||
d, t = s.split(sep, 1)
|
d, t = s.split(sep, 1)
|
||||||
return datetime(*[ int(x) for x in d.split('-')+t.split(':') ])
|
return datetime(*[ int(x) for x in d.split('-')+t.split(':') ])
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
raise
|
||||||
except:
|
except:
|
||||||
return Date_or_None(s)
|
return Date_or_None(s)
|
||||||
|
|
||||||
@ -79,8 +81,12 @@ def Time_or_None(s):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def Date_or_None(s):
|
def Date_or_None(s):
|
||||||
try: return date(*[ int(x) for x in s.split('-',2)])
|
try:
|
||||||
except: return None
|
return date(*[ int(x) for x in s.split('-',2)])
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
raise
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def DateTime2literal(d, c):
|
def DateTime2literal(d, c):
|
||||||
"""Format a DateTime object as an ISO timestamp."""
|
"""Format a DateTime object as an ISO timestamp."""
|
||||||
@ -97,5 +103,9 @@ def mysql_timestamp_converter(s):
|
|||||||
s = s + "0"*(14-len(s)) # padding
|
s = s + "0"*(14-len(s)) # padding
|
||||||
parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],
|
parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],
|
||||||
s[8:10],s[10:12],s[12:14])))
|
s[8:10],s[10:12],s[12:14])))
|
||||||
try: return Timestamp(*parts)
|
try:
|
||||||
except: return None
|
return Timestamp(*parts)
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
raise
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
Reference in New Issue
Block a user