@@ -322,9 +322,6 @@ def is_resultset_packet(self):
322
322
field_count = ord (self ._data [0 :1 ])
323
323
return 1 <= field_count <= 250
324
324
325
- def is_load_local_packet (self ):
326
- return self ._data [0 :1 ] == b'\xfb '
327
-
328
325
def is_error_packet (self ):
329
326
return self ._data [0 :1 ] == b'\xff '
330
327
@@ -437,26 +434,6 @@ def __getattr__(self, key):
437
434
return getattr (self .packet , key )
438
435
439
436
440
- class LoadLocalPacketWrapper (object ):
441
- """
442
- Load Local Packet Wrapper. It uses an existing packet object, and wraps
443
- around it, exposing useful variables while still providing access
444
- to the original packet objects variables and methods.
445
- """
446
-
447
- def __init__ (self , from_packet ):
448
- if not from_packet .is_load_local_packet ():
449
- raise ValueError (
450
- "Cannot create '{0}' object from invalid packet type" .format (
451
- self .__class__ ))
452
-
453
- self .packet = from_packet
454
- self .filename = self .packet .get_all_data ()[1 :]
455
- if DEBUG : print ("filename=" , self .filename )
456
-
457
- def __getattr__ (self , key ):
458
- return getattr (self .packet , key )
459
-
460
437
461
438
class Connection (object ):
462
439
"""
@@ -476,8 +453,7 @@ def __init__(self, host="localhost", user=None, password="",
476
453
client_flag = 0 , cursorclass = Cursor , init_command = None ,
477
454
connect_timeout = None , ssl = None , read_default_group = None ,
478
455
compress = None , named_pipe = None , no_delay = False ,
479
- autocommit = False , db = None , passwd = None , local_infile = False ,
480
- io_loop = None ):
456
+ autocommit = False , db = None , passwd = None , io_loop = None ):
481
457
"""
482
458
Establish a connection to the MySQL database. Accepts several
483
459
arguments:
@@ -511,7 +487,6 @@ def __init__(self, host="localhost", user=None, password="",
511
487
no_delay: Disable Nagle's algorithm on the socket
512
488
autocommit: Autocommit mode. None means use server default. (default: False)
513
489
io_loop: Tornado IOLoop
514
- local_infile: Boolean to enable the use of LOAD DATA LOCAL command. (default: False)
515
490
516
491
db: Alias for database. (for compatibility to MySQLdb)
517
492
passwd: Alias for password. (for compatibility to MySQLdb)
@@ -529,9 +504,6 @@ def __init__(self, host="localhost", user=None, password="",
529
504
if compress or named_pipe :
530
505
raise NotImplementedError ("compress and named_pipe arguments are not supported" )
531
506
532
- if local_infile :
533
- client_flag |= CLIENT .LOCAL_FILES
534
-
535
507
if ssl and ('capath' in ssl or 'cipher' in ssl ):
536
508
raise NotImplementedError ('ssl options capath and cipher are not supported' )
537
509
@@ -624,6 +596,9 @@ def close(self):
624
596
@gen .coroutine
625
597
def close_async (self ):
626
598
"""Send the quit message and close the socket"""
599
+ if self ._stream is None or self ._stream .closed ():
600
+ self ._stream = None
601
+ return
627
602
send_data = struct .pack ('<i' , 1 ) + int2byte (COMMAND .COM_QUIT )
628
603
yield self ._stream .write (send_data )
629
604
self .close ()
@@ -1060,8 +1035,6 @@ def read(self):
1060
1035
1061
1036
if first_packet .is_ok_packet ():
1062
1037
self ._read_ok_packet (first_packet )
1063
- elif first_packet .is_load_local_packet ():
1064
- self ._read_load_local_packet (first_packet )
1065
1038
else :
1066
1039
yield self ._read_result_packet (first_packet )
1067
1040
finally :
@@ -1094,16 +1067,6 @@ def _read_ok_packet(self, first_packet):
1094
1067
self .message = ok_packet .message
1095
1068
self .has_next = ok_packet .has_next
1096
1069
1097
- def _read_load_local_packet (self , first_packet ):
1098
- load_packet = LoadLocalPacketWrapper (first_packet )
1099
- sender = LoadLocalFile (load_packet .filename , self .connection )
1100
- sender .send_data ()
1101
-
1102
- ok_packet = self .connection ._read_packet ()
1103
- if not ok_packet .is_ok_packet ():
1104
- raise OperationalError (2014 , "Commands Out of Sync" )
1105
- self ._read_ok_packet (ok_packet )
1106
-
1107
1070
def _check_packet_is_eof (self , packet ):
1108
1071
if packet .is_eof_packet ():
1109
1072
eof_packet = EOFPacketWrapper (packet )
@@ -1209,39 +1172,4 @@ def _get_descriptions(self):
1209
1172
self .description = tuple (description )
1210
1173
1211
1174
1212
- class LoadLocalFile (object ):
1213
- def __init__ (self , filename , connection ):
1214
- self .filename = filename
1215
- self .connection = connection
1216
-
1217
- def send_data (self ):
1218
- """Send data packets from the local file to the server"""
1219
- if not self .connection .socket :
1220
- raise InterfaceError ("(0, '')" )
1221
-
1222
- # sequence id is 2 as we already sent a query packet
1223
- seq_id = 2
1224
- try :
1225
- with open (self .filename , 'rb' ) as open_file :
1226
- chunk_size = MAX_PACKET_LEN
1227
- prelude = b""
1228
- packet = b""
1229
- packet_size = 0
1230
-
1231
- while True :
1232
- chunk = open_file .read (chunk_size )
1233
- if not chunk :
1234
- break
1235
- packet = struct .pack ('<i' , len (chunk ))[:3 ] + int2byte (seq_id )
1236
- format_str = '!{0}s' .format (len (chunk ))
1237
- packet += struct .pack (format_str , chunk )
1238
- self .connection ._write_bytes (packet )
1239
- seq_id += 1
1240
- except IOError :
1241
- raise OperationalError (1017 , "Can't find file '{0}'" .format (self .filename ))
1242
- finally :
1243
- # send the empty packet to signify we are done sending data
1244
- packet = struct .pack ('<i' , 0 )[:3 ] + int2byte (seq_id )
1245
- self .connection ._write_bytes (packet )
1246
-
1247
1175
# g:khuno_ignore='E226,E301,E701'
0 commit comments