def test_read_lc_int(self):
        """Read a length encoded integer from a buffer."""
        buf = '\xfb'

        exp = 2**(8-1)
        lcs = utils.intstore(exp)
        self.assertEqual(exp,utils.read_lc_int(lcs)[1],
            "Failed getting length coded int(250)")

        exp = 2**(8-1)
        lcs = utils.intstore(251) + utils.intstore(exp)
        self.assertEqual(None,utils.read_lc_int(lcs)[1],
            "Failed getting length coded int(250)")

        exp = 2**(16-1)
        lcs = utils.intstore(252) + utils.intstore(exp)
        self.assertEqual(exp,utils.read_lc_int(lcs)[1],
            "Failed getting length coded int(2^16-1)")

        exp = 2**(24-1)
        lcs = utils.intstore(253) + utils.intstore(exp)
        self.assertEqual(exp,utils.read_lc_int(lcs)[1],
            "Failed getting length coded int(2^24-1)")

        exp = 12321848580485677055
        lcs = '\xfe\xff\xff\xff\xff\xff\xff\xff\xaa\xdd\xdd'
        exprest = '\xdd\xdd'
        self.assertEqual((exprest,exp),utils.read_lc_int(lcs),
            "Failed getting length coded long long")
示例#2
0
    def test_read_lc_int(self):
        """Read a length encoded integer from a buffer."""
        buf = b'\xfb'

        exp = 2**(8 - 1)
        lcs = utils.intstore(exp)
        self.assertEqual(exp,
                         utils.read_lc_int(lcs)[1],
                         "Failed getting length coded int(250)")

        exp = 2**(8 - 1)
        lcs = utils.intstore(251) + utils.intstore(exp)
        self.assertEqual(None,
                         utils.read_lc_int(lcs)[1],
                         "Failed getting length coded int(250)")

        exp = 2**(16 - 1)
        lcs = utils.intstore(252) + utils.intstore(exp)
        self.assertEqual(exp,
                         utils.read_lc_int(lcs)[1],
                         "Failed getting length coded int(2^16-1)")

        exp = 2**(24 - 1)
        lcs = utils.intstore(253) + utils.intstore(exp)
        self.assertEqual(exp,
                         utils.read_lc_int(lcs)[1],
                         "Failed getting length coded int(2^24-1)")

        exp = 12321848580485677055
        lcs = b'\xfe\xff\xff\xff\xff\xff\xff\xff\xaa\xdd\xdd'
        exprest = b'\xdd\xdd'
        self.assertEqual((exprest, exp), utils.read_lc_int(lcs),
                         "Failed getting length coded long long")
示例#3
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok = {}
        try:
            (packet, ok['field_count']) = utils.read_int(packet[4:], 1)
            (packet, ok['affected_rows']) = utils.read_lc_int(packet)
            (packet, ok['insert_id']) = utils.read_lc_int(packet)
            (packet, ok['server_status']) = utils.read_int(packet, 2)
            (packet, ok['warning_count']) = utils.read_int(packet, 2)
            if packet:
                (packet, ok['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok
示例#4
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok = {}
        try:
            (packet, ok['field_count']) = utils.read_int(packet[4:], 1)
            (packet, ok['affected_rows']) = utils.read_lc_int(packet)
            (packet, ok['insert_id']) = utils.read_lc_int(packet)
            (packet, ok['server_status']) = utils.read_int(packet, 2)
            (packet, ok['warning_count']) = utils.read_int(packet, 2)
            if packet:
                (packet, ok['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok
示例#5
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok_packet = {}
        try:
            ok_packet['field_count'] = struct.unpack('<xxxxB', packet[0:5])[0]
            (packet, ok_packet['affected_rows']) = utils.read_lc_int(packet[5:])
            (packet, ok_packet['insert_id']) = utils.read_lc_int(packet)
            (ok_packet['server_status'],
                ok_packet['warning_count']) = struct.unpack('<HH', packet[0:4])
            packet = packet[4:]
            if packet:
                (packet, ok_packet['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok_packet
示例#6
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok_packet = {}
        try:
            ok_packet['field_count'] = struct.unpack('<xxxxB', packet[0:5])[0]
            (packet, ok_packet['affected_rows']) = utils.read_lc_int(packet[5:])
            (packet, ok_packet['insert_id']) = utils.read_lc_int(packet)
            (ok_packet['server_status'],
             ok_packet['warning_count']) = struct.unpack('<HH', packet[0:4])
            packet = packet[4:]
            if packet:
                (packet, ok_packet['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok_packet
示例#7
0
    def _handle_resultset(self, pkt):
        """Processes a resultset getting fields information.
        
        The argument pkt must be a protocol.Packet with length 1, a byte
        which contains the number of fields.
        """
        if not isinstance(pkt, protocol.PacketIn):
            raise ValueError("%s is not a protocol.PacketIn" % pkt)
        
        if len(pkt) == 1:
            (buf,nrflds) = utils.read_lc_int(pkt.data)
            
            # Get the fields
#            fields = self._handle_fields(nrflds)
            fields = yield self._handle_fields(nrflds)

            buf = (yield self.conn.recv())[0]
            eof = protocol.EOFPacket(buf)

#            return (nrflds, fields, eof)
            yield (nrflds, fields, eof)
        else:
            raise errors.InterfaceError('Something wrong reading result after query.')
示例#8
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     try:
         return utils.read_lc_int(packet[4:])[1]
     except (struct.error, ValueError):
         raise errors.InterfaceError("Failed parsing column count")
示例#9
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     try:
         return utils.read_lc_int(packet[4:])[1]
     except (struct.error, ValueError):
         raise errors.InterfaceError("Failed parsing column count")
示例#10
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     return utils.read_lc_int(packet[4:])[1]
示例#11
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     return utils.read_lc_int(packet[4:])[1]
示例#12
-1
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == 0:
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok_packet = {}
        try:
            ok_packet["field_count"] = struct.unpack("<xxxxB", packet[0:5])[0]
            (packet, ok_packet["affected_rows"]) = utils.read_lc_int(packet[5:])
            (packet, ok_packet["insert_id"]) = utils.read_lc_int(packet)
            (ok_packet["server_status"], ok_packet["warning_count"]) = struct.unpack("<HH", packet[0:4])
            packet = packet[4:]
            if packet:
                (packet, ok_packet["info_msg"]) = utils.read_lc_string(packet)
                ok_packet["info_msg"] = ok_packet["info_msg"].decode("utf-8")
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok_packet