def dump_packet(data): def is_ascii(data): if 65 <= byte2int(data) <= 122: #data.isalnum(): if isinstance(data, int): return chr(data) return data return '.' try: print("packet length:", len(data)) print("method call[1]:", sys._getframe(1).f_code.co_name) print("method call[2]:", sys._getframe(2).f_code.co_name) print("method call[3]:", sys._getframe(3).f_code.co_name) print("method call[4]:", sys._getframe(4).f_code.co_name) print("method call[5]:", sys._getframe(5).f_code.co_name) print("-" * 88) except ValueError: pass dump_data = [ data[i:i + 16] for i in range_type(0, min(len(data), 256), 16) ] for d in dump_data: print(' '.join(map(lambda x: "{:02X}".format(byte2int(x)), d)) + ' ' * (16 - len(d)) + ' ' * 2 + ' '.join(map(lambda x: "{}".format(is_ascii(x)), d))) print("-" * 88) print()
def _my_crypt(message1, message2): length = len(message1) result = struct.pack("B", length) for i in range_type(length): x = struct.unpack("B", message1[i : i + 1])[0] ^ struct.unpack("B", message2[i : i + 1])[0] result += struct.pack("B", x) return result
def dump_packet(data): def is_ascii(data): if 65 <= byte2int(data) <= 122: # data.isalnum(): if isinstance(data, int): return chr(data) return data return "." try: print("packet length:", len(data)) print("method call[1]:", sys._getframe(1).f_code.co_name) print("method call[2]:", sys._getframe(2).f_code.co_name) print("method call[3]:", sys._getframe(3).f_code.co_name) print("method call[4]:", sys._getframe(4).f_code.co_name) print("method call[5]:", sys._getframe(5).f_code.co_name) print("-" * 88) except ValueError: pass dump_data = [data[i : i + 16] for i in range_type(0, min(len(data), 256), 16)] for d in dump_data: print( " ".join(map(lambda x: "{:02X}".format(byte2int(x)), d)) + " " * (16 - len(d)) + " " * 2 + " ".join(map(lambda x: "{}".format(is_ascii(x)), d)) ) print("-" * 88) print()
def _my_crypt(message1, message2): length = len(message1) result = struct.pack('B', length) for i in range_type(length): x = (struct.unpack('B', message1[i:i + 1])[0] ^ struct.unpack('B', message2[i:i + 1])[0]) result += struct.pack('B', x) return result
def _get_descriptions(self): """Read a column descriptor packet for each column in the result.""" self.fields = [] description = [] for i in range_type(self.field_count): field = self.connection._read_packet(FieldDescriptorPacket) self.fields.append(field) description.append(field.description()) eof_packet = self.connection._read_packet() assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF' self.description = tuple(description)
def _get_descriptions(self): """Read a column descriptor packet for each column in the result.""" self.fields = [] description = [] for i in range_type(self.field_count): field = yield self.connection._read_packet(FieldDescriptorPacket) self.fields.append(field) description.append(field.description()) eof_packet = yield self.connection._read_packet() assert eof_packet.is_eof_packet(), "Protocol error, expecting EOF" self.description = tuple(description)
def scroll(self, value, mode='relative'): self._check_executed() if mode == 'relative': if value < 0: raise NotSupportedError( "Backwards scrolling not supported by this cursor") for _ in range_type(value): self.read_next() self.rownumber += value elif mode == 'absolute': if value < self.rownumber: raise NotSupportedError( "Backwards scrolling not supported by this cursor") end = value - self.rownumber for _ in range_type(end): self.read_next() self.rownumber = value else: raise ProgrammingError("unknown scroll mode %s" % mode)
def fetchmany(self, size=None): """ Fetch many """ self._check_executed() if size is None: size = self.arraysize rows = [] for i in range_type(size): row = self.read_next() if row is None: break rows.append(row) self.rownumber += 1 return rows
def _scramble_323(password, message): hash_pass = _hash_password_323(password) hash_message = _hash_password_323(message[:SCRAMBLE_LENGTH_323]) hash_pass_n = struct.unpack(">LL", hash_pass) hash_message_n = struct.unpack(">LL", hash_message) rand_st = RandStruct_323(hash_pass_n[0] ^ hash_message_n[0], hash_pass_n[1] ^ hash_message_n[1]) outbuf = io.BytesIO() for _ in range_type(min(SCRAMBLE_LENGTH_323, len(message))): outbuf.write(int2byte(int(rand_st.my_rnd() * 31) + 64)) extra = int2byte(int(rand_st.my_rnd() * 31)) out = outbuf.getvalue() outbuf = io.BytesIO() for c in out: outbuf.write(int2byte(byte2int(c) ^ byte2int(extra))) return outbuf.getvalue()
def callproc(self, procname, args=()): """Execute stored procedure procname with args procname -- string, name of procedure to execute on server args -- Sequence of parameters to use with procedure Returns the original args. Compatibility warning: PEP-249 specifies that any modified parameters must be returned. This is currently impossible as they are only available by storing them in a server variable and then retrieved by a query. Since stored procedures return zero or more result sets, there is no reliable way to get at OUT or INOUT parameters via callproc. The server variables are named @_procname_n, where procname is the parameter above and n is the position of the parameter (from zero). Once all result sets generated by the procedure have been fetched, you can issue a SELECT @_procname_0, ... query using .execute() to get any OUT or INOUT values. Compatibility warning: The act of calling a stored procedure itself creates an empty result set. This appears after any result sets generated by the procedure. This is non-standard behavior with respect to the DB-API. Be sure to use nextset() to advance through all result sets; otherwise you may get disconnected. """ conn = self._get_db() for index, arg in enumerate(args): q = "SET @_%s_%d=%s" % (procname, index, conn.escape(arg)) self._query(q) self.nextset() q = "CALL %s(%s)" % (procname, ','.join(['@_%s_%d' % (procname, i) for i in range_type(len(args))])) self._query(q) self._executed = q return args