Python util 模块,int2byte() 实例源码

我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用util.int2byte()

项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
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 = StringIO.StringIO()
    for _ in xrange(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 = StringIO.StringIO()
    for c in out:
        outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
    return outbuf.getvalue()
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def __recv_packet(self):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = self.connection.rfile.read(4)
    if len(packet_header) < 4:
        raise OperationalError(2013, "Lost connection to MySQL server during query")

    if DEBUG: dump_packet(packet_header)
    packet_length_bin = packet_header[:3]
    self.__packet_number = byte2int(packet_header[3])
    # TODO: check packet_num is correct (+1 from last packet)

    bin_length = packet_length_bin + int2byte(0)  # pad little-endian number
    bytes_to_read = struct.unpack('<I', bin_length)[0]
    recv_data = self.connection.rfile.read(bytes_to_read)
    if len(recv_data) < bytes_to_read:
        raise OperationalError(2013, "Lost connection to MySQL server during query")
    if DEBUG: dump_packet(recv_data)
    self.__data = recv_data
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def _send_command(self, command, sql):
        #send_data = struct.pack('<i', len(sql) + 1) + command + sql
        # could probably be more efficient, at least it's correct
        if not self.socket:
            self.errorhandler(None, InterfaceError, "(0, '')")

        # If the last query was unbuffered, make sure it finishes before
        # sending new commands
        if self._result is not None and self._result.unbuffered_active:
            self._result._finish_unbuffered_query()

        if isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        self.wfile.write(prelude + sql)
        self.wfile.flush()
        if DEBUG: dump_packet(prelude + sql)
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
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 = StringIO.StringIO()
    for _ in xrange(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 = StringIO.StringIO()
    for c in out:
        outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
    return outbuf.getvalue()
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def __recv_packet(self):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = self.connection.rfile.read(4)
    if len(packet_header) < 4:
        raise OperationalError(2013, "Lost connection to MySQL server during query")

    if DEBUG: dump_packet(packet_header)
    packet_length_bin = packet_header[:3]
    self.__packet_number = byte2int(packet_header[3])
    # TODO: check packet_num is correct (+1 from last packet)

    bin_length = packet_length_bin + int2byte(0)  # pad little-endian number
    bytes_to_read = struct.unpack('<I', bin_length)[0]
    recv_data = self.connection.rfile.read(bytes_to_read)
    if len(recv_data) < bytes_to_read:
        raise OperationalError(2013, "Lost connection to MySQL server during query")
    if DEBUG: dump_packet(recv_data)
    self.__data = recv_data
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def _send_command(self, command, sql):
        #send_data = struct.pack('<i', len(sql) + 1) + command + sql
        # could probably be more efficient, at least it's correct
        if not self.socket:
            self.errorhandler(None, InterfaceError, "(0, '')")

        # If the last query was unbuffered, make sure it finishes before
        # sending new commands
        if self._result is not None and self._result.unbuffered_active:
            self._result._finish_unbuffered_query()

        if isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        self.wfile.write(prelude + sql)
        self.wfile.flush()
        if DEBUG: dump_packet(prelude + sql)
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
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 = StringIO.StringIO()
    for _ in xrange(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 = StringIO.StringIO()
    for c in out:
        outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
    return outbuf.getvalue()
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def __recv_packet(self):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = self.connection.rfile.read(4)
    if len(packet_header) < 4:
        raise OperationalError(2013, "Lost connection to MySQL server during query")

    if DEBUG: dump_packet(packet_header)
    packet_length_bin = packet_header[:3]
    self.__packet_number = byte2int(packet_header[3])
    # TODO: check packet_num is correct (+1 from last packet)

    bin_length = packet_length_bin + int2byte(0)  # pad little-endian number
    bytes_to_read = struct.unpack('<I', bin_length)[0]
    recv_data = self.connection.rfile.read(bytes_to_read)
    if len(recv_data) < bytes_to_read:
        raise OperationalError(2013, "Lost connection to MySQL server during query")
    if DEBUG: dump_packet(recv_data)
    self.__data = recv_data
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def _send_command(self, command, sql):
        #send_data = struct.pack('<i', len(sql) + 1) + command + sql
        # could probably be more efficient, at least it's correct
        if not self.socket:
            self.errorhandler(None, InterfaceError, "(0, '')")

        # If the last query was unbuffered, make sure it finishes before
        # sending new commands
        if self._result is not None and self._result.unbuffered_active:
            self._result._finish_unbuffered_query()

        if isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        self.wfile.write(prelude + sql)
        self.wfile.flush()
        if DEBUG: dump_packet(prelude + sql)
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
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 = StringIO.StringIO()
    for _ in xrange(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 = StringIO.StringIO()
    for c in out:
        outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
    return outbuf.getvalue()
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def __recv_packet(self):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = self.connection.rfile.read(4)
    if len(packet_header) < 4:
        raise OperationalError(2013, "Lost connection to MySQL server during query")

    if DEBUG: dump_packet(packet_header)
    packet_length_bin = packet_header[:3]
    self.__packet_number = byte2int(packet_header[3])
    # TODO: check packet_num is correct (+1 from last packet)

    bin_length = packet_length_bin + int2byte(0)  # pad little-endian number
    bytes_to_read = struct.unpack('<I', bin_length)[0]
    recv_data = self.connection.rfile.read(bytes_to_read)
    if len(recv_data) < bytes_to_read:
        raise OperationalError(2013, "Lost connection to MySQL server during query")
    if DEBUG: dump_packet(recv_data)
    self.__data = recv_data
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def _send_command(self, command, sql):
        #send_data = struct.pack('<i', len(sql) + 1) + command + sql
        # could probably be more efficient, at least it's correct
        if not self.socket:
            self.errorhandler(None, InterfaceError, "(0, '')")

        # If the last query was unbuffered, make sure it finishes before
        # sending new commands
        if self._result is not None and self._result.unbuffered_active:
            self._result._finish_unbuffered_query()

        if isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        self.wfile.write(prelude + sql)
        self.wfile.flush()
        if DEBUG: dump_packet(prelude + sql)
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
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 = StringIO.StringIO()
    for _ in xrange(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 = StringIO.StringIO()
    for c in out:
        outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
    return outbuf.getvalue()
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def __recv_packet(self):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = self.connection.rfile.read(4)
    if len(packet_header) < 4:
        raise OperationalError(2013, "Lost connection to MySQL server during query")

    if DEBUG: dump_packet(packet_header)
    packet_length_bin = packet_header[:3]
    self.__packet_number = byte2int(packet_header[3])
    # TODO: check packet_num is correct (+1 from last packet)

    bin_length = packet_length_bin + int2byte(0)  # pad little-endian number
    bytes_to_read = struct.unpack('<I', bin_length)[0]
    recv_data = self.connection.rfile.read(bytes_to_read)
    if len(recv_data) < bytes_to_read:
        raise OperationalError(2013, "Lost connection to MySQL server during query")
    if DEBUG: dump_packet(recv_data)
    self.__data = recv_data
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def _send_command(self, command, sql):
        #send_data = struct.pack('<i', len(sql) + 1) + command + sql
        # could probably be more efficient, at least it's correct
        if not self.socket:
            self.errorhandler(None, InterfaceError, "(0, '')")

        # If the last query was unbuffered, make sure it finishes before
        # sending new commands
        if self._result is not None and self._result.unbuffered_active:
            self._result._finish_unbuffered_query()

        if isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        self.wfile.write(prelude + sql)
        self.wfile.flush()
        if DEBUG: dump_packet(prelude + sql)
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def _scramble(password, message):
    if password == None or len(password) == 0:
        return int2byte(0)
    if DEBUG: print 'password=' + password
    stage1 = sha_new(password).digest()
    stage2 = sha_new(stage1).digest()
    s = sha_new()
    s.update(message)
    s.update(stage2)
    result = s.digest()
    return _my_crypt(result, stage1)
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def close(self):
        ''' Send the quit message and close the socket '''
        if self.socket is None:
            raise Error("Already closed")
        send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
        self.wfile.write(send_data)
        self.wfile.close()
        self.rfile.close()
        self.socket.close()
        self.socket = None
        self.rfile = None
        self.wfile = None
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def _scramble(password, message):
    if password == None or len(password) == 0:
        return int2byte(0)
    if DEBUG: print 'password=' + password
    stage1 = sha_new(password).digest()
    stage2 = sha_new(stage1).digest()
    s = sha_new()
    s.update(message)
    s.update(stage2)
    result = s.digest()
    return _my_crypt(result, stage1)
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def close(self):
        ''' Send the quit message and close the socket '''
        if self.socket is None:
            raise Error("Already closed")
        send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
        self.wfile.write(send_data)
        self.wfile.close()
        self.rfile.close()
        self.socket.close()
        self.socket = None
        self.rfile = None
        self.wfile = None
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def _scramble(password, message):
    if password == None or len(password) == 0:
        return int2byte(0)
    if DEBUG: print 'password=' + password
    stage1 = sha_new(password).digest()
    stage2 = sha_new(stage1).digest()
    s = sha_new()
    s.update(message)
    s.update(stage2)
    result = s.digest()
    return _my_crypt(result, stage1)
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def close(self):
        ''' Send the quit message and close the socket '''
        if self.socket is None:
            raise Error("Already closed")
        send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
        self.wfile.write(send_data)
        self.wfile.close()
        self.rfile.close()
        self.socket.close()
        self.socket = None
        self.rfile = None
        self.wfile = None
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def _scramble(password, message):
    if password == None or len(password) == 0:
        return int2byte(0)
    if DEBUG: print 'password=' + password
    stage1 = sha_new(password).digest()
    stage2 = sha_new(stage1).digest()
    s = sha_new()
    s.update(message)
    s.update(stage2)
    result = s.digest()
    return _my_crypt(result, stage1)
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def close(self):
        ''' Send the quit message and close the socket '''
        if self.socket is None:
            raise Error("Already closed")
        send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
        self.wfile.write(send_data)
        self.wfile.close()
        self.rfile.close()
        self.socket.close()
        self.socket = None
        self.rfile = None
        self.wfile = None
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def _scramble(password, message):
    if password == None or len(password) == 0:
        return int2byte(0)
    if DEBUG: print 'password=' + password
    stage1 = sha_new(password).digest()
    stage2 = sha_new(stage1).digest()
    s = sha_new()
    s.update(message)
    s.update(stage2)
    result = s.digest()
    return _my_crypt(result, stage1)
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def close(self):
        ''' Send the quit message and close the socket '''
        if self.socket is None:
            raise Error("Already closed")
        send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
        self.wfile.write(send_data)
        self.wfile.close()
        self.rfile.close()
        self.socket.close()
        self.socket = None
        self.rfile = None
        self.wfile = None