@@ -39,14 +39,14 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
39
39
40
40
def numeric_part (s ):
41
41
"""Returns the leading numeric part of a string.
42
-
42
+
43
43
>>> numeric_part("20-alpha")
44
44
20
45
45
>>> numeric_part("foo")
46
46
>>> numeric_part("16b")
47
47
16
48
48
"""
49
-
49
+
50
50
m = re_numeric_part .match (s )
51
51
if m :
52
52
return int (m .group (1 ))
@@ -58,7 +58,7 @@ class Connection(_mysql.connection):
58
58
"""MySQL Database Connection Object"""
59
59
60
60
default_cursor = cursors .Cursor
61
-
61
+
62
62
def __init__ (self , * args , ** kwargs ):
63
63
"""
64
64
@@ -68,7 +68,7 @@ def __init__(self, *args, **kwargs):
68
68
69
69
host
70
70
string, host to connect
71
-
71
+
72
72
user
73
73
string, user to connect as
74
74
@@ -125,7 +125,7 @@ class object, used to create cursors (keyword only)
125
125
If supplied, the session SQL mode will be changed to this
126
126
setting (MySQL-4.1 and newer). For more details and legal
127
127
values, see the MySQL documentation.
128
-
128
+
129
129
client_flag
130
130
integer, flags to use or 0
131
131
(see MySQL docs or constants/CLIENTS.py)
@@ -138,19 +138,17 @@ class object, used to create cursors (keyword only)
138
138
139
139
local_infile
140
140
integer, non-zero enables LOAD LOCAL INFILE; zero disables
141
-
141
+
142
142
There are a number of undocumented, non-standard methods. See the
143
143
documentation for the MySQL C API for some hints on what they do.
144
144
145
145
"""
146
146
from MySQLdb .constants import CLIENT , FIELD_TYPE
147
147
from MySQLdb .converters import conversions
148
- from weakref import proxy , WeakValueDictionary
149
-
150
- import types
148
+ from weakref import proxy
151
149
152
150
kwargs2 = kwargs .copy ()
153
-
151
+
154
152
if 'conv' in kwargs :
155
153
conv = kwargs ['conv' ]
156
154
else :
@@ -171,7 +169,7 @@ class object, used to create cursors (keyword only)
171
169
use_unicode = True
172
170
else :
173
171
use_unicode = False
174
-
172
+
175
173
use_unicode = kwargs2 .pop ('use_unicode' , use_unicode )
176
174
sql_mode = kwargs2 .pop ('sql_mode' , '' )
177
175
@@ -181,14 +179,14 @@ class object, used to create cursors (keyword only)
181
179
client_flag |= CLIENT .MULTI_STATEMENTS
182
180
if client_version >= (5 , 0 ):
183
181
client_flag |= CLIENT .MULTI_RESULTS
184
-
182
+
185
183
kwargs2 ['client_flag' ] = client_flag
186
184
187
185
super (Connection , self ).__init__ (* args , ** kwargs2 )
188
186
self .cursorclass = cursorclass
189
187
self .encoders = dict ([ (k , v ) for k , v in conv .items ()
190
188
if type (k ) is not int ])
191
-
189
+
192
190
self ._server_version = tuple ([ numeric_part (n ) for n in self .get_server_info ().split ('.' )[:2 ] ])
193
191
194
192
db = proxy (self )
@@ -206,7 +204,7 @@ def _get_string_decoder():
206
204
def string_decoder (s ):
207
205
return s .decode (string_decoder .charset )
208
206
return string_decoder
209
-
207
+
210
208
string_literal = _get_string_literal ()
211
209
self .unicode_literal = unicode_literal = _get_unicode_literal ()
212
210
self .string_decoder = string_decoder = _get_string_decoder ()
@@ -230,7 +228,7 @@ def string_decoder(s):
230
228
# PEP-249 requires autocommit to be initially off
231
229
self .autocommit (False )
232
230
self .messages = []
233
-
231
+
234
232
def cursor (self , cursorclass = None ):
235
233
"""
236
234
@@ -242,14 +240,15 @@ def cursor(self, cursorclass=None):
242
240
"""
243
241
return (cursorclass or self .cursorclass )(self )
244
242
245
- def __enter__ (self ): return self .cursor ()
246
-
243
+ def __enter__ (self ):
244
+ return self .cursor ()
245
+
247
246
def __exit__ (self , exc , value , tb ):
248
247
if exc :
249
248
self .rollback ()
250
249
else :
251
250
self .commit ()
252
-
251
+
253
252
def literal (self , o ):
254
253
"""
255
254
@@ -271,7 +270,7 @@ def begin(self):
271
270
warn ("begin() is non-standard and will be removed in 1.3" ,
272
271
DeprecationWarning , 2 )
273
272
self .query ("BEGIN" )
274
-
273
+
275
274
if not hasattr (_mysql .connection , 'warning_count' ):
276
275
277
276
def warning_count (self ):
@@ -311,7 +310,7 @@ def set_sql_mode(self, sql_mode):
311
310
raise NotSupportedError ("server is too old to set sql_mode" )
312
311
self .query ("SET SESSION sql_mode='%s'" % sql_mode )
313
312
self .store_result ()
314
-
313
+
315
314
def show_warnings (self ):
316
315
"""Return detailed information about warnings as a
317
316
sequence of tuples of (Level, Code, Message). This
@@ -322,7 +321,7 @@ def show_warnings(self):
322
321
r = self .store_result ()
323
322
warnings = r .fetch_row (0 )
324
323
return warnings
325
-
324
+
326
325
Warning = Warning
327
326
Error = Error
328
327
InterfaceError = InterfaceError
0 commit comments