2323from concurrent .futures import Executor , ThreadPoolExecutor , TimeoutError
2424from inspect import signature
2525
26+ from aws_advanced_python_wrapper .driver_dialect import DriverDialect
27+ from aws_advanced_python_wrapper .driver_dialect_codes import DriverDialectCodes
28+ from aws_advanced_python_wrapper .errors import UnsupportedOperationError
29+ from aws_advanced_python_wrapper .utils .decorators import timeout
30+ from aws_advanced_python_wrapper .utils .messages import Messages
31+ from aws_advanced_python_wrapper .utils .properties import (Properties ,
32+ PropertiesUtils ,
33+ WrapperProperties )
34+
2635CMYSQL_ENABLED = False
2736
28- from mysql .connector import MySQLConnection
29- from mysql .connector .cursor import MySQLCursor
37+ from mysql .connector import MySQLConnection # noqa: E402
38+ from mysql .connector .cursor import MySQLCursor # noqa: E402
3039
3140try :
32- from mysql .connector import CMySQLConnection
33- from mysql .connector .cursor_cext import CMySQLCursor
41+ from mysql .connector import CMySQLConnection # noqa: E402
42+ from mysql .connector .cursor_cext import CMySQLCursor # noqa: E402
3443
3544 CMYSQL_ENABLED = True
3645
3746except ImportError :
3847 # Do nothing
3948 pass
4049
41- from aws_advanced_python_wrapper .driver_dialect import DriverDialect
42- from aws_advanced_python_wrapper .driver_dialect_codes import DriverDialectCodes
43- from aws_advanced_python_wrapper .errors import UnsupportedOperationError
44- from aws_advanced_python_wrapper .utils .decorators import timeout
45- from aws_advanced_python_wrapper .utils .messages import Messages
46- from aws_advanced_python_wrapper .utils .properties import (Properties ,
47- PropertiesUtils ,
48- WrapperProperties )
49-
5050
5151class MySQLDriverDialect (DriverDialect ):
5252 _driver_name = "MySQL Connector Python"
@@ -94,7 +94,7 @@ def is_closed(self, conn: Connection) -> bool:
9494 if self .can_execute_query (conn ):
9595 socket_timeout = WrapperProperties .SOCKET_TIMEOUT_SEC .get_float (self ._props )
9696 timeout_sec = socket_timeout if socket_timeout > 0 else MySQLDriverDialect .IS_CLOSED_TIMEOUT_SEC
97- is_connected_with_timeout = timeout (MySQLDriverDialect ._executor , timeout_sec )(conn .is_connected ) # type: ignore
97+ is_connected_with_timeout = timeout (MySQLDriverDialect ._executor , timeout_sec )(conn .is_connected ) # type: ignore
9898
9999 try :
100100 return not is_connected_with_timeout ()
@@ -106,14 +106,14 @@ def is_closed(self, conn: Connection) -> bool:
106106
107107 def get_autocommit (self , conn : Connection ) -> bool :
108108 if MySQLDriverDialect ._is_mysql_connection (conn ):
109- return conn .autocommit # type: ignore
109+ return conn .autocommit # type: ignore
110110
111111 raise UnsupportedOperationError (
112112 Messages .get_formatted ("DriverDialect.UnsupportedOperationError" , self ._driver_name , "autocommit" ))
113113
114114 def set_autocommit (self , conn : Connection , autocommit : bool ):
115115 if MySQLDriverDialect ._is_mysql_connection (conn ):
116- conn .autocommit = autocommit # type: ignore
116+ conn .autocommit = autocommit # type: ignore
117117 return
118118
119119 raise UnsupportedOperationError (
@@ -132,13 +132,13 @@ def abort_connection(self, conn: Connection):
132132
133133 def can_execute_query (self , conn : Connection ) -> bool :
134134 if MySQLDriverDialect ._is_mysql_connection (conn ):
135- if conn .unread_result : # type: ignore
136- return conn .can_consume_results # type: ignore
135+ if conn .unread_result : # type: ignore
136+ return conn .can_consume_results # type: ignore
137137 return True
138138
139139 def is_in_transaction (self , conn : Connection ) -> bool :
140140 if MySQLDriverDialect ._is_mysql_connection (conn ):
141- return bool (conn .in_transaction ) # type: ignore
141+ return bool (conn .in_transaction ) # type: ignore
142142
143143 raise UnsupportedOperationError (
144144 Messages .get_formatted ("DriverDialect.UnsupportedOperationError" , self ._driver_name ,
@@ -176,7 +176,7 @@ def get_connection_from_obj(self, obj: object) -> Any:
176176
177177 def transfer_session_state (self , from_conn : Connection , to_conn : Connection ):
178178 if MySQLDriverDialect ._is_mysql_connection (from_conn ) and MySQLDriverDialect ._is_mysql_connection (to_conn ):
179- to_conn .autocommit = from_conn .autocommit # type: ignore
179+ to_conn .autocommit = from_conn .autocommit # type: ignore
180180
181181 def ping (self , conn : Connection ) -> bool :
182182 return not self .is_closed (conn )
0 commit comments