From 308e835058c4127c8a3e8449b60df1a7a9f0d666 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 29 Aug 2016 20:40:45 +0900 Subject: [PATCH] Support DEPRECATE_EOF (#433) --- pymysql/connections.py | 28 ++++++++++++++++------------ pymysql/constants/CLIENT.py | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 65dc8d2..9d13b14 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -363,17 +363,18 @@ class MysqlPacket(object): return result def is_ok_packet(self): - return self._data[0:1] == b'\0' - - def is_auth_switch_request(self): - # http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest - return self._data[0:1] == b'\xfe' + # https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html + return self._data[0:1] == b'\0' and len(self._data) >= 7 def is_eof_packet(self): # http://dev.mysql.com/doc/internals/en/generic-response-packets.html#packet-EOF_Packet # Caution: \xFE may be LengthEncodedInteger. # If \xFE is LengthEncodedInteger header, 8bytes followed. - return len(self._data) < 9 and self._data[0:1] == b'\xfe' + return self._data[0:1] == b'\xfe' and len(self._data) < 9 + + def is_auth_switch_request(self): + # http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest + return self._data[0:1] == b'\xfe' def is_resultset_packet(self): field_count = ord(self._data[0:1]) @@ -1357,11 +1358,14 @@ class MySQLResult(object): def _check_packet_is_eof(self, packet): if packet.is_eof_packet(): - eof_packet = EOFPacketWrapper(packet) - self.warning_count = eof_packet.warning_count - self.has_next = eof_packet.has_next - return True - return False + wp = EOFPacketWrapper(packet) + elif packet.is_ok_packet(): + wp = OKPacketWrapper(packet) + else: + return False + self.warning_count = wp.warning_count + self.has_next = wp.has_next + return True def _read_result_packet(self, first_packet): self.field_count = first_packet.read_length_encoded_integer() @@ -1466,7 +1470,7 @@ class MySQLResult(object): self.converters.append((encoding, converter)) eof_packet = self.connection._read_packet() - assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF' + assert eof_packet.is_eof_packet() or eof_packet.is_ok_packet, 'Protocol error, expecting EOF' self.description = tuple(description) diff --git a/pymysql/constants/CLIENT.py b/pymysql/constants/CLIENT.py index 7f8c590..a983938 100644 --- a/pymysql/constants/CLIENT.py +++ b/pymysql/constants/CLIENT.py @@ -26,4 +26,4 @@ CAPABILITIES = (LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | CONNECT_ATTRS = 1 << 20 HANDLE_EXPIRED_PASSWORDS = 1 << 22 SESSION_TRACK = 1 << 23 -CLIENT_DEPRECATE_EOF = 1 << 24 +DEPRECATE_EOF = 1 << 24