77
88import re
99
10- from . import cursors , _mysql
10+ from . import _mysql , cursors
1111from ._exceptions import (
12- Warning ,
13- Error ,
14- InterfaceError ,
15- DataError ,
1612 DatabaseError ,
17- OperationalError ,
13+ DataError ,
14+ Error ,
1815 IntegrityError ,
16+ InterfaceError ,
1917 InternalError ,
2018 NotSupportedError ,
19+ OperationalError ,
2120 ProgrammingError ,
21+ Warning ,
2222)
2323
2424# Mapping from MySQL charset name to Python codec name
@@ -164,7 +164,7 @@ class object, used to create cursors (keyword only)
164164 documentation for the MySQL C API for some hints on what they do.
165165 """
166166 from MySQLdb .constants import CLIENT , FIELD_TYPE
167- from MySQLdb .converters import conversions , _bytes_or_str
167+ from MySQLdb .converters import _bytes_or_str , conversions
168168
169169 kwargs2 = kwargs .copy ()
170170
@@ -173,11 +173,7 @@ class object, used to create cursors (keyword only)
173173 if "passwd" in kwargs2 :
174174 kwargs2 ["password" ] = kwargs2 .pop ("passwd" )
175175
176- if "conv" in kwargs :
177- conv = kwargs ["conv" ]
178- else :
179- conv = conversions
180-
176+ conv = kwargs .get ("conv" , conversions )
181177 conv2 = {}
182178 for k , v in conv .items ():
183179 if isinstance (k , int ) and isinstance (v , list ):
@@ -207,11 +203,7 @@ class object, used to create cursors (keyword only)
207203 super ().__init__ (* args , ** kwargs2 )
208204
209205 self .cursorclass = cursorclass
210- self .encoders = {
211- k : v
212- for k , v in conv .items ()
213- if type (k ) is not int # noqa: E721
214- }
206+ self .encoders = {k : v for k , v in conv .items () if type (k ) is not int }
215207 self ._server_version = tuple (
216208 [numeric_part (n ) for n in self .get_server_info ().split ("." )[:2 ]]
217209 )
@@ -240,9 +232,8 @@ class object, used to create cursors (keyword only)
240232 self .converter [FIELD_TYPE .JSON ] = str
241233
242234 self ._transactional = self .server_capabilities & CLIENT .TRANSACTIONS
243- if self ._transactional :
244- if autocommit is not None :
245- self .autocommit (autocommit )
235+ if self ._transactional and autocommit is not None :
236+ self .autocommit (autocommit )
246237 self .messages = []
247238
248239 def _set_attributes (
@@ -314,9 +305,7 @@ def literal(self, o):
314305 """
315306 if isinstance (o , str ):
316307 s = self .string_literal (o .encode (self .encoding ))
317- elif isinstance (o , bytearray ):
318- s = self ._bytes_literal (o )
319- elif isinstance (o , bytes ):
308+ elif isinstance (o , (bytes , bytearray )):
320309 s = self ._bytes_literal (o )
321310 elif isinstance (o , (tuple , list )):
322311 s = self ._tuple_literal (o )
0 commit comments