Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[lint]
ignore = [
"BLE001",
"DTZ001",
"EXE001",
"FLY002",
"N999",
"RUF012",
"S102",
"SIM115",
"TRY002",
"UP031",
]
29 changes: 14 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import os
import subprocess
import sys

import setuptools
from configparser import ConfigParser

import setuptools

release_info = {}
with open("src/MySQLdb/release.py", encoding="utf-8") as f:
Expand Down Expand Up @@ -70,11 +69,11 @@ def get_config_posix(options=None):
("__version__", release_info["__version__"]),
]

ext_options = dict(
extra_compile_args=cflags,
extra_link_args=ldflags,
define_macros=define_macros,
)
ext_options = {
"extra_compile_args": cflags,
"extra_link_args": ldflags,
"define_macros": define_macros,
}
# newer versions of gcc require libstdc++ if doing a static build
if static:
ext_options["language"] = "c++"
Expand Down Expand Up @@ -120,14 +119,14 @@ def get_config_win32(options):
("__version__", release_info["__version__"]),
]

ext_options = dict(
library_dirs=library_dirs,
libraries=libraries,
extra_link_args=extra_link_args,
include_dirs=include_dirs,
extra_objects=extra_objects,
define_macros=define_macros,
)
ext_options = {
"library_dirs": library_dirs,
"libraries": libraries,
"extra_link_args": extra_link_args,
"include_dirs": include_dirs,
"extra_objects": extra_objects,
"define_macros": define_macros,
}
return ext_options


Expand Down
69 changes: 35 additions & 34 deletions src/MySQLdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
MySQLdb.converters module.
"""

from .release import version_info
from . import _mysql
from .release import version_info

if version_info != _mysql.version_info:
raise ImportError(
Expand All @@ -24,32 +24,33 @@
)


from ._mysql import (
NotSupportedError,
OperationalError,
get_client_info,
ProgrammingError,
Error,
InterfaceError,
debug,
IntegrityError,
string_literal,
MySQLError,
DataError,
DatabaseError,
InternalError,
Warning,
)
from MySQLdb.constants import FIELD_TYPE
from MySQLdb.times import (
Date,
Time,
Timestamp,
DateFromTicks,
Time,
TimeFromTicks,
Timestamp,
TimestampFromTicks,
)

from ._mysql import (
DatabaseError,
DataError,
Error,
IntegrityError,
InterfaceError,
InternalError,
MySQLError,
NotSupportedError,
OperationalError,
ProgrammingError,
Warning,
debug,
get_client_info,
string_literal,
)

threadsafety = 1
apilevel = "2.0"
paramstyle = "format"
Expand Down Expand Up @@ -95,7 +96,7 @@ def __eq__(self, other):


def test_DBAPISet_set_equality():
assert STRING == STRING
assert STRING == STRING # noqa


def test_DBAPISet_set_inequality():
Expand Down Expand Up @@ -125,33 +126,33 @@ def Connect(*args, **kwargs):

__all__ = [
"BINARY",
"DATE",
"FIELD_TYPE",
"NUMBER",
"ROWID",
"STRING",
"TIME",
"TIMESTAMP",
"Binary",
"Connect",
"Connection",
"DATE",
"Date",
"Time",
"Timestamp",
"DateFromTicks",
"TimeFromTicks",
"TimestampFromTicks",
"DBAPISet",
"DataError",
"DatabaseError",
"Date",
"DateFromTicks",
"Error",
"FIELD_TYPE",
"IntegrityError",
"InterfaceError",
"InternalError",
"MySQLError",
"NUMBER",
"NotSupportedError",
"DBAPISet",
"OperationalError",
"ProgrammingError",
"ROWID",
"STRING",
"TIME",
"TIMESTAMP",
"Time",
"TimeFromTicks",
"Timestamp",
"TimestampFromTicks",
"Warning",
"apilevel",
"connect",
Expand Down
35 changes: 12 additions & 23 deletions src/MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import re

from . import cursors, _mysql
from . import _mysql, cursors
from ._exceptions import (
Warning,
Error,
InterfaceError,
DataError,
DatabaseError,
OperationalError,
DataError,
Error,
IntegrityError,
InterfaceError,
InternalError,
NotSupportedError,
OperationalError,
ProgrammingError,
Warning,
)

# Mapping from MySQL charset name to Python codec name
Expand Down Expand Up @@ -164,7 +164,7 @@ class object, used to create cursors (keyword only)
documentation for the MySQL C API for some hints on what they do.
"""
from MySQLdb.constants import CLIENT, FIELD_TYPE
from MySQLdb.converters import conversions, _bytes_or_str
from MySQLdb.converters import _bytes_or_str, conversions

kwargs2 = kwargs.copy()

Expand All @@ -173,11 +173,7 @@ class object, used to create cursors (keyword only)
if "passwd" in kwargs2:
kwargs2["password"] = kwargs2.pop("passwd")

if "conv" in kwargs:
conv = kwargs["conv"]
else:
conv = conversions

conv = kwargs.get("conv", conversions)
conv2 = {}
for k, v in conv.items():
if isinstance(k, int) and isinstance(v, list):
Expand Down Expand Up @@ -207,11 +203,7 @@ class object, used to create cursors (keyword only)
super().__init__(*args, **kwargs2)

self.cursorclass = cursorclass
self.encoders = {
k: v
for k, v in conv.items()
if type(k) is not int # noqa: E721
}
self.encoders = {k: v for k, v in conv.items() if type(k) is not int}
self._server_version = tuple(
[numeric_part(n) for n in self.get_server_info().split(".")[:2]]
)
Expand Down Expand Up @@ -240,9 +232,8 @@ class object, used to create cursors (keyword only)
self.converter[FIELD_TYPE.JSON] = str

self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
if self._transactional:
if autocommit is not None:
self.autocommit(autocommit)
if self._transactional and autocommit is not None:
self.autocommit(autocommit)
self.messages = []

def _set_attributes(
Expand Down Expand Up @@ -314,9 +305,7 @@ def literal(self, o):
"""
if isinstance(o, str):
s = self.string_literal(o.encode(self.encoding))
elif isinstance(o, bytearray):
s = self._bytes_literal(o)
elif isinstance(o, bytes):
elif isinstance(o, (bytes, bytearray)):
s = self._bytes_literal(o)
elif isinstance(o, (tuple, list)):
s = self._tuple_literal(o)
Expand Down
3 changes: 1 addition & 2 deletions src/MySQLdb/constants/ER.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
m = re.match(r"^\s*#define\s+((ER|WARN)_[A-Z0-9_]+)\s+(\d+)\s*", line)
if m:
name = m.group(1)
if name.startswith("ER_"):
name = name[3:]
name = name.removeprefix("ER_")
value = int(m.group(3))
if name == "ERROR_LAST":
if error_last is None or error_last < value:
Expand Down
2 changes: 1 addition & 1 deletion src/MySQLdb/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ["CR", "FIELD_TYPE", "CLIENT", "ER", "FLAG"]
__all__ = ["CLIENT", "CR", "ER", "FIELD_TYPE", "FLAG"]
13 changes: 6 additions & 7 deletions src/MySQLdb/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
MySQL.connect().
"""

import array
from decimal import Decimal

from MySQLdb._exceptions import ProgrammingError
from MySQLdb._mysql import string_literal
from MySQLdb.constants import FIELD_TYPE, FLAG
from MySQLdb.times import (
Date,
DateTimeType,
Date_or_None,
DateTime2literal,
DateTimeDeltaType,
DateTimeDelta2literal,
DateTime_or_None,
DateTimeDelta2literal,
DateTimeDeltaType,
DateTimeType,
TimeDelta_or_None,
Date_or_None,
)
from MySQLdb._exceptions import ProgrammingError

import array

NoneType = type(None)

Expand Down
1 change: 1 addition & 0 deletions src/MySQLdb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def __getattr__(self, name):
# DB-API 2.0 optional extension says these errors can be accessed
# via Connection object. But MySQLdb had defined them on Cursor object.
import warnings

from . import _exceptions as err

if name in (
Expand Down
3 changes: 2 additions & 1 deletion src/MySQLdb/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
Use Python datetime module to handle date and time columns.
"""

from time import localtime
from datetime import date, datetime, time, timedelta
from time import localtime

from MySQLdb._mysql import string_literal

Date = date
Expand Down
11 changes: 6 additions & 5 deletions tests/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

"""

from time import time
import unittest
from time import time

from configdb import connection_factory


class DatabaseTest(unittest.TestCase):
db_module = None
connect_args = ()
connect_kwargs = dict()
connect_kwargs = {}
create_table_extra = ""
rows = 10
debug = False
Expand Down Expand Up @@ -162,7 +163,7 @@ def generator(row, col):
pass
else:
self.fail(
"Over-long column did not generate warnings/exception with single insert" # noqa: E501
"Over-long column did not generate warnings/exception with single insert"
)

self.connection.rollback()
Expand All @@ -177,7 +178,7 @@ def generator(row, col):
pass
else:
self.fail(
"Over-long columns did not generate warnings/exception with execute()" # noqa: E501
"Over-long columns did not generate warnings/exception with execute()"
)

self.connection.rollback()
Expand All @@ -192,7 +193,7 @@ def generator(row, col):
pass
else:
self.fail(
"Over-long columns did not generate warnings/exception with executemany()" # noqa: E501
"Over-long columns did not generate warnings/exception with executemany()"
)

self.connection.rollback()
Expand Down
8 changes: 4 additions & 4 deletions tests/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
tests_path = path.dirname(__file__)
conf_file = environ.get("TESTDB", "default.cnf")
conf_path = path.join(tests_path, conf_file)
connect_kwargs = dict(
read_default_file=conf_path,
read_default_group="MySQLdb-tests",
)
connect_kwargs = {
"read_default_file": conf_path,
"read_default_group": "MySQLdb-tests",
}


def connection_kwargs(kwargs):
Expand Down
Loading
Loading