Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8ad1525

Browse filesBrowse files
authored
Raise ProgrammingError for nan and inf (PyMySQL#314)
* Raise ProgrammingError when inf or nan is passed Fixes PyMySQL#246 * Rename _mysql_exceptions -> _exceptions
1 parent 911bef9 commit 8ad1525
Copy full SHA for 8ad1525

File tree

Expand file treeCollapse file tree

10 files changed

+20
-19
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+20
-19
lines changed

‎MySQLdb/_mysql_exceptions.py renamed to ‎MySQLdb/_exceptions.py

Copy file name to clipboardExpand all lines: MySQLdb/_exceptions.py
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
"""_mysql_exceptions: Exception classes for _mysql and MySQLdb.
1+
"""Exception classes for _mysql and MySQLdb.
22
33
These classes are dictated by the DB API v2.0:
44
55
https://www.python.org/dev/peps/pep-0249/
66
"""
7-
8-
try:
9-
from exceptions import Exception, StandardError, Warning
10-
except ImportError:
11-
# Python 3
12-
StandardError = Exception
7+
from .compat import StandardError
138

149

1510
class MySQLError(StandardError):
@@ -20,6 +15,7 @@ class Warning(Warning, MySQLError):
2015
"""Exception raised for important warnings like data truncations
2116
while inserting, etc."""
2217

18+
2319
class Error(MySQLError):
2420
"""Exception that is the base class of all other error exceptions
2521
(not Warning)."""

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,7 @@ init_mysql(void)
26692669
(PyObject *)&_mysql_ResultObject_Type))
26702670
goto error;
26712671
Py_INCREF(&_mysql_ResultObject_Type);
2672-
if (!(emod = PyImport_ImportModule("MySQLdb._mysql_exceptions"))) {
2672+
if (!(emod = PyImport_ImportModule("MySQLdb._exceptions"))) {
26732673
PyErr_Print();
26742674
goto error;
26752675
}

‎MySQLdb/compat.py

Copy file name to clipboardExpand all lines: MySQLdb/compat.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
unicode = unicode
66
unichr = unichr
77
long = long
8+
StandardError = StandardError
89
else:
910
PY2 = False
1011
unicode = str
1112
unichr = chr
1213
long = int
14+
StandardError = Exception

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from MySQLdb import cursors, _mysql
1111
from MySQLdb.compat import unicode, PY2
12-
from MySQLdb._mysql_exceptions import (
12+
from MySQLdb._exceptions import (
1313
Warning, Error, InterfaceError, DataError,
1414
DatabaseError, OperationalError, IntegrityError, InternalError,
1515
NotSupportedError, ProgrammingError,

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from MySQLdb.constants import FIELD_TYPE, FLAG
3737
from MySQLdb.times import *
3838
from MySQLdb.compat import PY2, long, unicode
39+
from MySQLdb._exceptions import ProgrammingError
3940

4041
NoneType = type(None)
4142

@@ -66,6 +67,8 @@ def Unicode2Str(s, d):
6667

6768
def Float2Str(o, d):
6869
s = repr(o)
70+
if s in ('inf', 'nan'):
71+
raise ProgrammingError("%s can not be used with MySQL" % s)
6972
if 'e' not in s:
7073
s += 'e0'
7174
return s

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sys
1010

1111
from .compat import unicode
12-
from ._mysql_exceptions import (
12+
from ._exceptions import (
1313
Warning, Error, InterfaceError, DataError,
1414
DatabaseError, OperationalError, IntegrityError, InternalError,
1515
NotSupportedError, ProgrammingError)
@@ -48,7 +48,7 @@ class BaseCursor(object):
4848
#: Default value of max_allowed_packet is 1048576.
4949
max_stmt_length = 64*1024
5050

51-
from ._mysql_exceptions import (
51+
from ._exceptions import (
5252
MySQLError, Warning, Error, InterfaceError,
5353
DatabaseError, DataError, OperationalError, IntegrityError,
5454
InternalError, ProgrammingError, NotSupportedError,
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
_mysql_exceptions Module
1+
_exceptions Module
22
========================
33

4-
.. automodule:: _mysql_exceptions
4+
.. automodule:: MySQLdb._exceptions
55
:members:
66
:undoc-members:
77
:show-inheritance:

‎doc/_mysql.rst

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
_mysql Module
22
=============
33

4-
.. automodule:: _mysql
4+
.. automodule:: MySQLdb._mysql
55
:members:
66
:undoc-members:
77
:show-inheritance:

‎doc/user_guide.rst

Copy file name to clipboardExpand all lines: doc/user_guide.rst
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Okay, so you want to use ``_mysql`` anyway. Here are some examples.
106106

107107
The simplest possible database connection is::
108108

109-
import _mysql
109+
from MySQLdb import _mysql
110110
db=_mysql.connect()
111111

112112
This creates a connection to the MySQL server running on the local
@@ -162,8 +162,8 @@ substitution, so you have to pass a complete query string to
162162
WHERE price < 5""")
163163

164164
There's no return value from this, but exceptions can be raised. The
165-
exceptions are defined in a separate module, ``_mysql_exceptions``,
166-
but ``_mysql`` exports them. Read DB API specification PEP-249_ to
165+
exceptions are defined in a separate module, ``MySQLdb._exceptions``,
166+
but ``MySQLdb._mysql`` exports them. Read DB API specification PEP-249_ to
167167
find out what they are, or you can use the catch-all ``MySQLError``.
168168

169169
.. _PEP-249: https://www.python.org/dev/peps/pep-0249/
@@ -213,7 +213,7 @@ implicitly asked for one row, since we didn't specify ``maxrows``.
213213
The other oddity is: Assuming these are numeric columns, why are they
214214
returned as strings? Because MySQL returns all data as strings and
215215
expects you to convert it yourself. This would be a real pain in the
216-
ass, but in fact, ``_mysql`` can do this for you. (And ``MySQLdb``
216+
ass, but in fact, ``MySQLdb._mysql`` can do this for you. (And ``MySQLdb``
217217
does do this for you.) To have automatic type conversion done, you
218218
need to create a type converter dictionary, and pass this to
219219
``connect()`` as the ``conv`` keyword parameter.

‎metadata.cfg

Copy file name to clipboardExpand all lines: metadata.cfg
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers:
2828
Topic :: Database
2929
Topic :: Database :: Database Engines/Servers
3030
py_modules:
31-
MySQLdb._mysql_exceptions
31+
MySQLdb._exceptions
3232
MySQLdb.compat
3333
MySQLdb.connections
3434
MySQLdb.converters

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.