(self)
| 1182 | return self.protocol_version |
| 1183 | |
| 1184 | def _get_server_information(self): |
| 1185 | i = 0 |
| 1186 | packet = self._read_packet() |
| 1187 | data = packet.get_all_data() |
| 1188 | |
| 1189 | self.protocol_version = data[i] |
| 1190 | i += 1 |
| 1191 | |
| 1192 | server_end = data.find(b"\0", i) |
| 1193 | self.server_version = data[i:server_end].decode("latin1") |
| 1194 | i = server_end + 1 |
| 1195 | |
| 1196 | self.server_thread_id = struct.unpack("<I", data[i : i + 4]) |
| 1197 | i += 4 |
| 1198 | |
| 1199 | self.salt = data[i : i + 8] |
| 1200 | i += 9 # 8 + 1(filler) |
| 1201 | |
| 1202 | self.server_capabilities = struct.unpack("<H", data[i : i + 2])[0] |
| 1203 | i += 2 |
| 1204 | |
| 1205 | if len(data) >= i + 6: |
| 1206 | lang, stat, cap_h, salt_len = struct.unpack("<BHHB", data[i : i + 6]) |
| 1207 | i += 6 |
| 1208 | # TODO: deprecate server_language and server_charset. |
| 1209 | # mysqlclient-python doesn't provide it. |
| 1210 | self.server_language = lang |
| 1211 | try: |
| 1212 | self.server_charset = charset_by_id(lang).name |
| 1213 | except KeyError: |
| 1214 | # unknown collation |
| 1215 | self.server_charset = None |
| 1216 | |
| 1217 | self.server_status = stat |
| 1218 | if DEBUG: |
| 1219 | print("server_status: %x" % stat) |
| 1220 | |
| 1221 | self.server_capabilities |= cap_h << 16 |
| 1222 | if DEBUG: |
| 1223 | print("salt_len:", salt_len) |
| 1224 | salt_len = max(12, salt_len - 9) |
| 1225 | |
| 1226 | # reserved |
| 1227 | i += 10 |
| 1228 | |
| 1229 | if len(data) >= i + salt_len: |
| 1230 | # salt_len includes auth_plugin_data_part_1 and filler |
| 1231 | self.salt += data[i : i + salt_len] |
| 1232 | i += salt_len |
| 1233 | |
| 1234 | i += 1 |
| 1235 | # AUTH PLUGIN NAME may appear here. |
| 1236 | if self.server_capabilities & CLIENT.PLUGIN_AUTH and len(data) >= i: |
| 1237 | # Due to Bug#59453 the auth-plugin-name is missing the terminating |
| 1238 | # NUL-char in versions prior to 5.5.10 and 5.6.2. |
| 1239 | # ref: https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake |
| 1240 | # didn't use version checks as mariadb is corrected and reports |
| 1241 | # earlier than those two. |
no test coverage detected