'Read an entire "mysql packet" in its entirety from the network
and return a MysqlPacket type that represents the results.'

def _read_packet(self, packet_type=MysqlPacket):

    buff = ''
    while True:
        packet_header = self._read_bytes(4)
        if DEBUG:
            dump_packet(packet_header)
        (btrl, btrh, packet_number) = struct.unpack('<HBB', packet_header)
        bytes_to_read = (btrl + (btrh << 16))
        if (packet_number != self._next_seq_id):
            self._force_close()
            if (packet_number == 0):
                raise err.OperationalError(CR.CR_SERVER_LOST, 'Lost    connection    to    MySQL    server    during    query')
            raise err.InternalError(('Packet    sequence    number    wrong    -    got    %d    expected    %d' % (packet_number, self._next_seq_id)))
        self._next_seq_id = ((self._next_seq_id + 1) % 256)
        recv_data = self._read_bytes(bytes_to_read)
        if DEBUG:
            dump_packet(recv_data)
        buff += recv_data
        if (bytes_to_read == 16777215):
            continue
        if (bytes_to_read < MAX_PACKET_LEN):
            break
    packet = packet_type(buff, self.encoding)
    packet.check_error()
    return packet
