@@ -322,9 +322,6 @@ def is_resultset_packet(self):
322322 field_count = ord (self ._data [0 :1 ])
323323 return 1 <= field_count <= 250
324324
325- def is_load_local_packet (self ):
326- return self ._data [0 :1 ] == b'\xfb '
327-
328325 def is_error_packet (self ):
329326 return self ._data [0 :1 ] == b'\xff '
330327
@@ -437,26 +434,6 @@ def __getattr__(self, key):
437434 return getattr (self .packet , key )
438435
439436
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-
460437
461438class Connection (object ):
462439 """
@@ -476,8 +453,7 @@ def __init__(self, host="localhost", user=None, password="",
476453 client_flag = 0 , cursorclass = Cursor , init_command = None ,
477454 connect_timeout = None , ssl = None , read_default_group = None ,
478455 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 ):
481457 """
482458 Establish a connection to the MySQL database. Accepts several
483459 arguments:
@@ -511,7 +487,6 @@ def __init__(self, host="localhost", user=None, password="",
511487 no_delay: Disable Nagle's algorithm on the socket
512488 autocommit: Autocommit mode. None means use server default. (default: False)
513489 io_loop: Tornado IOLoop
514- local_infile: Boolean to enable the use of LOAD DATA LOCAL command. (default: False)
515490
516491 db: Alias for database. (for compatibility to MySQLdb)
517492 passwd: Alias for password. (for compatibility to MySQLdb)
@@ -529,9 +504,6 @@ def __init__(self, host="localhost", user=None, password="",
529504 if compress or named_pipe :
530505 raise NotImplementedError ("compress and named_pipe arguments are not supported" )
531506
532- if local_infile :
533- client_flag |= CLIENT .LOCAL_FILES
534-
535507 if ssl and ('capath' in ssl or 'cipher' in ssl ):
536508 raise NotImplementedError ('ssl options capath and cipher are not supported' )
537509
@@ -624,6 +596,9 @@ def close(self):
624596 @gen .coroutine
625597 def close_async (self ):
626598 """Send the quit message and close the socket"""
599+ if self ._stream is None or self ._stream .closed ():
600+ self ._stream = None
601+ return
627602 send_data = struct .pack ('<i' , 1 ) + int2byte (COMMAND .COM_QUIT )
628603 yield self ._stream .write (send_data )
629604 self .close ()
@@ -1060,8 +1035,6 @@ def read(self):
10601035
10611036 if first_packet .is_ok_packet ():
10621037 self ._read_ok_packet (first_packet )
1063- elif first_packet .is_load_local_packet ():
1064- self ._read_load_local_packet (first_packet )
10651038 else :
10661039 yield self ._read_result_packet (first_packet )
10671040 finally :
@@ -1094,16 +1067,6 @@ def _read_ok_packet(self, first_packet):
10941067 self .message = ok_packet .message
10951068 self .has_next = ok_packet .has_next
10961069
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-
11071070 def _check_packet_is_eof (self , packet ):
11081071 if packet .is_eof_packet ():
11091072 eof_packet = EOFPacketWrapper (packet )
@@ -1209,39 +1172,4 @@ def _get_descriptions(self):
12091172 self .description = tuple (description )
12101173
12111174
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-
12471175# g:khuno_ignore='E226,E301,E701'
0 commit comments