MCPcopy
hub / github.com/PyMySQL/PyMySQL / send_data

Method send_data

pymysql/connections.py:1453–1477  ·  view source on GitHub ↗

Send data packets from the local file to the server

(self)

Source from the content-addressed store, hash-verified

1451 self.connection = connection
1452
1453 def send_data(self):
1454 """Send data packets from the local file to the server"""
1455 if not self.connection._sock:
1456 raise err.InterfaceError(0, "")
1457 conn: Connection = self.connection
1458
1459 try:
1460 with open(self.filename, "rb") as open_file:
1461 packet_size = min(
1462 conn.max_allowed_packet, 16 * 1024
1463 ) # 16KB is efficient enough
1464 while True:
1465 chunk = open_file.read(packet_size)
1466 if not chunk:
1467 break
1468 conn.write_packet(chunk)
1469 except OSError:
1470 raise err.OperationalError(
1471 ER.FILE_NOT_FOUND,
1472 f"Can't find file '{self.filename}'",
1473 )
1474 finally:
1475 if not conn._closed:
1476 # send the empty packet to signify we are done sending data
1477 conn.write_packet(b"")

Callers 1

Calls 2

write_packetMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected