main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -1,9 +1,11 @@
# dialects/mysql/pymysql.py
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# mysql/pymysql.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
# mypy: ignore-errors
r"""
@@ -39,6 +41,7 @@ necessary to indicate ``ssl_check_hostname=false`` in PyMySQL::
"&ssl_check_hostname=false"
)
MySQL-Python Compatibility
--------------------------
@@ -47,26 +50,9 @@ and targets 100% compatibility. Most behavioral notes for MySQL-python apply
to the pymysql driver as well.
""" # noqa
from __future__ import annotations
from typing import Any
from typing import Dict
from typing import Optional
from typing import TYPE_CHECKING
from typing import Union
from .mysqldb import MySQLDialect_mysqldb
from ...util import langhelpers
from ...util.typing import Literal
if TYPE_CHECKING:
from ...engine.interfaces import ConnectArgsType
from ...engine.interfaces import DBAPIConnection
from ...engine.interfaces import DBAPICursor
from ...engine.interfaces import DBAPIModule
from ...engine.interfaces import PoolProxiedConnection
from ...engine.url import URL
class MySQLDialect_pymysql(MySQLDialect_mysqldb):
@@ -76,7 +62,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
description_encoding = None
@langhelpers.memoized_property
def supports_server_side_cursors(self) -> bool:
def supports_server_side_cursors(self):
try:
cursors = __import__("pymysql.cursors").cursors
self._sscursor = cursors.SSCursor
@@ -85,11 +71,11 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
return False
@classmethod
def import_dbapi(cls) -> DBAPIModule:
def import_dbapi(cls):
return __import__("pymysql")
@langhelpers.memoized_property
def _send_false_to_ping(self) -> bool:
def _send_false_to_ping(self):
"""determine if pymysql has deprecated, changed the default of,
or removed the 'reconnect' argument of connection.ping().
@@ -100,9 +86,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
""" # noqa: E501
try:
Connection = __import__(
"pymysql.connections"
).connections.Connection
Connection = __import__("pymysql.connections").Connection
except (ImportError, AttributeError):
return True
else:
@@ -116,7 +100,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
not insp.defaults or insp.defaults[0] is not False
)
def do_ping(self, dbapi_connection: DBAPIConnection) -> Literal[True]:
def do_ping(self, dbapi_connection):
if self._send_false_to_ping:
dbapi_connection.ping(False)
else:
@@ -124,24 +108,17 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
return True
def create_connect_args(
self, url: URL, _translate_args: Optional[Dict[str, Any]] = None
) -> ConnectArgsType:
def create_connect_args(self, url, _translate_args=None):
if _translate_args is None:
_translate_args = dict(username="user")
return super().create_connect_args(
url, _translate_args=_translate_args
)
def is_disconnect(
self,
e: DBAPIModule.Error,
connection: Optional[Union[PoolProxiedConnection, DBAPIConnection]],
cursor: Optional[DBAPICursor],
) -> bool:
def is_disconnect(self, e, connection, cursor):
if super().is_disconnect(e, connection, cursor):
return True
elif isinstance(e, self.loaded_dbapi.Error):
elif isinstance(e, self.dbapi.Error):
str_e = str(e).lower()
return (
"already closed" in str_e or "connection was killed" in str_e
@@ -149,7 +126,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
else:
return False
def _extract_error_code(self, exception: BaseException) -> Any:
def _extract_error_code(self, exception):
if isinstance(exception.args[0], Exception):
exception = exception.args[0]
return exception.args[0]