コード例 #1
0
    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
ファイル: protocol.py プロジェクト: bopopescu/mythbox
    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
ファイル: protocol.py プロジェクト: khankuan/IvleHangout
    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
ファイル: protocol.py プロジェクト: christopherfan/urlShorty
    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
ファイル: protocol.py プロジェクト: bopopescu/HawkProxy
    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
ファイル: protocol.py プロジェクト: pombredanne/litchiweb
    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
ファイル: protocol.py プロジェクト: richfab/LOG210-server
 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
ファイル: protocol.py プロジェクト: bopopescu/HawkProxy
 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
ファイル: protocol.py プロジェクト: bopopescu/mythbox
 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