diff --git a/MySQLdb/__init__.py b/MySQLdb/__init__.py index a4a9da94..ad2057bc 100644 --- a/MySQLdb/__init__.py +++ b/MySQLdb/__init__.py @@ -15,7 +15,7 @@ from MySQLdb.release import __version__, version_info, __author__ -import _mysql +from . import _mysql if version_info != _mysql.version_info: raise ImportError("this is MySQLdb version %s, but _mysql is version %r" % @@ -25,7 +25,7 @@ apilevel = "2.0" paramstyle = "format" -from _mysql import * +from ._mysql import * from MySQLdb.compat import PY2 from MySQLdb.constants import FIELD_TYPE from MySQLdb.times import Date, Time, Timestamp, \ diff --git a/_mysql.c b/MySQLdb/_mysql.c similarity index 99% rename from _mysql.c rename to MySQLdb/_mysql.c index 537e61bc..04eadb7c 100644 --- a/_mysql.c +++ b/MySQLdb/_mysql.c @@ -2746,7 +2746,7 @@ init_mysql(void) (PyObject *)&_mysql_ResultObject_Type)) goto error; Py_INCREF(&_mysql_ResultObject_Type); - if (!(emod = PyImport_ImportModule("_mysql_exceptions"))) { + if (!(emod = PyImport_ImportModule("MySQLdb._mysql_exceptions"))) { PyErr_Print(); goto error; } diff --git a/_mysql_exceptions.py b/MySQLdb/_mysql_exceptions.py similarity index 100% rename from _mysql_exceptions.py rename to MySQLdb/_mysql_exceptions.py diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 10a0bf77..98c1ebff 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -7,14 +7,13 @@ import re import sys -from MySQLdb import cursors +from MySQLdb import cursors, _mysql from MySQLdb.compat import unicode, PY2 -from _mysql_exceptions import ( +from MySQLdb._mysql_exceptions import ( Warning, Error, InterfaceError, DataError, DatabaseError, OperationalError, IntegrityError, InternalError, NotSupportedError, ProgrammingError, ) -import _mysql if not PY2: diff --git a/MySQLdb/converters.py b/MySQLdb/converters.py index 5e28005d..c13e4265 100644 --- a/MySQLdb/converters.py +++ b/MySQLdb/converters.py @@ -31,7 +31,7 @@ MySQL.connect(). """ -from _mysql import string_literal, escape, NULL +from MySQLdb._mysql import string_literal, escape, NULL from MySQLdb.constants import FIELD_TYPE, FLAG from MySQLdb.times import * from MySQLdb.compat import PY2, long diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 98b3c738..60044830 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -8,8 +8,8 @@ import re import sys -from MySQLdb.compat import unicode -from _mysql_exceptions import ( +from .compat import unicode +from ._mysql_exceptions import ( Warning, Error, InterfaceError, DataError, DatabaseError, OperationalError, IntegrityError, InternalError, NotSupportedError, ProgrammingError) @@ -55,9 +55,11 @@ class BaseCursor(object): #: Default value of max_allowed_packet is 1048576. max_stmt_length = 64*1024 - from _mysql_exceptions import MySQLError, Warning, Error, InterfaceError, \ - DatabaseError, DataError, OperationalError, IntegrityError, \ - InternalError, ProgrammingError, NotSupportedError + from ._mysql_exceptions import ( + MySQLError, Warning, Error, InterfaceError, + DatabaseError, DataError, OperationalError, IntegrityError, + InternalError, ProgrammingError, NotSupportedError, + ) _defer_warnings = False connection = None diff --git a/MySQLdb/times.py b/MySQLdb/times.py index e26f8868..510d1c7c 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -6,7 +6,7 @@ """ from time import localtime from datetime import date, datetime, time, timedelta -from _mysql import string_literal +from MySQLdb._mysql import string_literal Date = date Time = time diff --git a/doc/user_guide.rst b/doc/user_guide.rst index d686b786..55c2c83f 100644 --- a/doc/user_guide.rst +++ b/doc/user_guide.rst @@ -17,11 +17,11 @@ Installation The ``README`` file has complete installation instructions. -_mysql ------- +MySQLdb._mysql +-------------- If you want to write applications which are portable across databases, -use MySQLdb_, and avoid using this module directly. ``_mysql`` +use MySQLdb_, and avoid using this module directly. ``MySQLdb._mysql`` provides an interface which mostly implements the MySQL C API. For more information, see the `MySQL documentation`_. The documentation for this module is intentionally weak because you probably should use diff --git a/metadata.cfg b/metadata.cfg index 6e05d35d..93b329b6 100644 --- a/metadata.cfg +++ b/metadata.cfg @@ -31,7 +31,7 @@ classifiers: Topic :: Database Topic :: Database :: Database Engines/Servers py_modules: - _mysql_exceptions + MySQLdb._mysql_exceptions MySQLdb.compat MySQLdb.connections MySQLdb.converters diff --git a/setup.py b/setup.py index ca4b362e..d1029962 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,9 @@ readme = f.read() metadata, options = get_config() -metadata['ext_modules'] = [setuptools.Extension(sources=['_mysql.c'], **options)] +metadata['ext_modules'] = [ + setuptools.Extension("MySQLdb._mysql", sources=['MySQLdb/_mysql.c'], **options) +] metadata['long_description'] = readme metadata['long_description_content_type'] = "text/markdown" setuptools.setup(**metadata) diff --git a/setup_posix.py b/setup_posix.py index 7b86ec73..9289bb50 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -94,7 +94,6 @@ def get_config(): create_release_file(metadata) del metadata['version_info'] ext_options = dict( - name = "_mysql", library_dirs = library_dirs, libraries = libraries, extra_compile_args = extra_compile_args, @@ -102,7 +101,7 @@ def get_config(): include_dirs = include_dirs, extra_objects = extra_objects, define_macros = define_macros, - ) + ) # newer versions of gcc require libstdc++ if doing a static build if static: diff --git a/setup_windows.py b/setup_windows.py index 74279077..0811e127 100644 --- a/setup_windows.py +++ b/setup_windows.py @@ -35,7 +35,6 @@ def get_config(): create_release_file(metadata) del metadata['version_info'] ext_options = dict( - name = "_mysql", library_dirs = library_dirs, libraries = libraries, extra_compile_args = extra_compile_args, @@ -43,7 +42,7 @@ def get_config(): include_dirs = include_dirs, extra_objects = extra_objects, define_macros = define_macros, - ) + ) return metadata, ext_options if __name__ == "__main__": diff --git a/tests/test_MySQLdb_nonstandard.py b/tests/test_MySQLdb_nonstandard.py index 52f6a4fb..a06d5edf 100644 --- a/tests/test_MySQLdb_nonstandard.py +++ b/tests/test_MySQLdb_nonstandard.py @@ -1,6 +1,6 @@ import unittest -import _mysql +from MySQLdb import _mysql import MySQLdb from MySQLdb.constants import FIELD_TYPE from configdb import connection_factory diff --git a/tests/test__mysql.py b/tests/test__mysql.py index e2cb6088..dd024b72 100644 --- a/tests/test__mysql.py +++ b/tests/test__mysql.py @@ -1,5 +1,5 @@ import pytest -import _mysql +from MySQLdb import _mysql def test_result_type():