当前位置: 首页>>代码示例>>Python>>正文


Python util.int2byte函数代码示例

本文整理汇总了Python中util.int2byte函数的典型用法代码示例。如果您正苦于以下问题:Python int2byte函数的具体用法?Python int2byte怎么用?Python int2byte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了int2byte函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _execute_command

    def _execute_command(self, command, sql):
        # if not self.socket:
        #     raise 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, text_type):
            sql = sql.encode(self.encoding)

        chunk_size = min(MAX_PACKET_LEN, len(sql) + 1)  # +1 is for command

        prelude = struct.pack("<i", chunk_size) + int2byte(command)
        yield self.stream.write(prelude + sql[: chunk_size - 1])
        if DEBUG:
            dump_packet(prelude + sql)

        if chunk_size < MAX_PACKET_LEN:
            raise Return()

        seq_id = 1
        sql = sql[chunk_size - 1 :]
        while True:
            chunk_size = min(MAX_PACKET_LEN, len(sql))
            prelude = struct.pack("<i", chunk_size)[:3]
            data = prelude + int2byte(seq_id % 256) + sql[:chunk_size]
            yield self.stream.write(data)
            if DEBUG:
                dump_packet(data)
            sql = sql[chunk_size:]
            if not sql and chunk_size < MAX_PACKET_LEN:
                break
            seq_id += 1
开发者ID:roson9527,项目名称:AsyncTorndb,代码行数:35,代码来源:connections.py

示例2: _get_server_information

    def _get_server_information(self):
        i = 0
        packet = MysqlPacket(self)
        data = packet.get_all_data()

        if DEBUG: dump_packet(data)
        #packet_len = byte2int(data[i:i+1])
        #i += 4
        self.protocol_version = byte2int(data[i:i+1])

        i += 1
        server_end = data.find(int2byte(0), i)
        # TODO: is this the correct charset? should it be default_charset?
        self.server_version = data[i:server_end].decode(self.charset)

        i = server_end + 1
        self.server_thread_id = struct.unpack('<h', data[i:i+2])

        i += 4
        self.salt = data[i:i+8]

        i += 9
        if len(data) >= i + 1:
            i += 1

        self.server_capabilities = struct.unpack('<h', data[i:i+2])[0]

        i += 1
        self.server_language = byte2int(data[i:i+1])
        self.server_charset = charset_by_id(self.server_language).name

        i += 16
        if len(data) >= i+12-1:
            rest_salt = data[i:i+12]
            self.salt += rest_salt
开发者ID:Webs961,项目名称:PyMySQL,代码行数:35,代码来源:connections.py

示例3: _scramble_323

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()
开发者ID:roson9527,项目名称:AsyncTorndb,代码行数:16,代码来源:connections.py

示例4: close

 def close(self):
     ''' Send the quit message and close the socket '''
     send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
     #self.socket.send(send_data)        # JAWBONE - OLD - PREFER SENDALL
     self.socket.sendall(send_data)      # JAWBONE - NEW - PREFER SENDALL
     self.socket.close()
     self.socket = None
开发者ID:flymio,项目名称:hammer,代码行数:7,代码来源:connections.py

示例5: __recv_packet

  def __recv_packet(self, socket):
    """Parse the packet header and read entire packet payload into buffer."""
    packet_header = socket.recv(4)
    while len(packet_header) < 4:
        d = socket.recv(4 - len(packet_header))
        if len(d) == 0:
            raise OperationalError(2013, "Lost connection to MySQL server during query")
        packet_header += d

    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]

    payload_buff = []  # this is faster than cStringIO
    while bytes_to_read > 0:
      recv_data = socket.recv(bytes_to_read)
      if len(recv_data) == 0:
            raise OperationalError(2013, "Lost connection to MySQL server during query")
      if DEBUG: dump_packet(recv_data)
      payload_buff.append(recv_data)
      bytes_to_read -= len(recv_data)
    self.__data = join_bytes(payload_buff)
开发者ID:flymio,项目名称:hammer,代码行数:26,代码来源:connections.py

示例6: close

 def close(self):
     ''' Send the quit message and close the socket '''
     send_data = struct.pack('<i',1) + int2byte(COM_QUIT)
     self.wfile.write(send_data)
     self.rfile.close()
     self.wfile.close()
     self.socket.close()
     self.socket = None
     self.rfile = None
     self.wfile = None
开发者ID:Alwnikrotikz,项目名称:pymysql,代码行数:10,代码来源:connections.py

示例7: _send_command

    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 isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        buf = int2byte(command) + sql
        pckt_no = 0
        while len(buf) >= MAX_PACKET_LENGTH:
            header = struct.pack('<i', MAX_PACKET_LENGTH)[:-1]+int2byte(pckt_no)
            send_data = header + buf[:MAX_PACKET_LENGTH]
            self.socket.send(send_data)
            if DEBUG: dump_packet(send_data)
            buf = buf[MAX_PACKET_LENGTH:]
            pckt_no += 1
        header = struct.pack('<i', len(buf))[:-1]+int2byte(pckt_no)
        self.socket.send(header+buf)
开发者ID:AftabiPhone,项目名称:Inventariofmo,代码行数:20,代码来源:connections.py

示例8: _scramble

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)
开发者ID:Webs961,项目名称:PyMySQL,代码行数:11,代码来源:connections.py

示例9: close

 def close(self):
     """ Send the quit message and close the socket """
     if self.stream.closed():
         raise Error("Already closed")
     send_data = struct.pack("<i", 1) + int2byte(COM_QUIT)
     try:
         yield self.stream.write(send_data)
     except Exception:
         pass
     finally:
         self.stream.close()
         self.stream = None
开发者ID:roson9527,项目名称:AsyncTorndb,代码行数:12,代码来源:connections.py

示例10: close

 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
开发者ID:Webs961,项目名称:PyMySQL,代码行数:12,代码来源:connections.py

示例11: _send_command

    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 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)
开发者ID:BillTheBest,项目名称:CloudStack,代码行数:13,代码来源:connections.py

示例12: _get_server_information

    def _get_server_information(self):
        i = 0
        packet = MysqlPacket(self)
        yield packet.recv_packet()
        packet.check_error()
        data = packet.get_all_data()

        if DEBUG:
            dump_packet(data)
        self.protocol_version = byte2int(data[i : i + 1])
        i += 1

        server_end = data.find(int2byte(0), i)
        self.server_version = data[i:server_end].decode("latin1")
        i = server_end + 1

        self.server_thread_id = struct.unpack("<I", data[i : i + 4])
        i += 4

        self.salt = data[i : i + 8]
        i += 9  # 8 + 1(filler)

        self.server_capabilities = struct.unpack("<H", data[i : i + 2])[0]
        i += 2

        if len(data) >= i + 6:
            lang, stat, cap_h, salt_len = struct.unpack("<BHHB", data[i : i + 6])
            i += 6
            self.server_language = lang
            self.server_charset = charset_by_id(lang).name

            self.server_status = stat
            if DEBUG:
                print("server_status: %x" % stat)

            self.server_capabilities |= cap_h << 16
            if DEBUG:
                print("salt_len:", salt_len)
            salt_len = max(12, salt_len - 9)

        # reserved
        i += 10

        if len(data) >= i + salt_len:
            self.salt += data[i : i + salt_len]  # salt_len includes auth_plugin_data_part_1 and filler
开发者ID:roson9527,项目名称:AsyncTorndb,代码行数:45,代码来源:connections.py

示例13: _send_command

    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)
开发者ID:Webs961,项目名称:PyMySQL,代码行数:18,代码来源:connections.py

示例14: __recv_packet

  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
开发者ID:Webs961,项目名称:PyMySQL,代码行数:18,代码来源:connections.py

示例15: _send_command

    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 isinstance(sql, unicode):
            sql = sql.encode(self.charset)

        prelude = struct.pack('<i', len(sql)+1) + int2byte(command)
        if len(sql) <= (MAX_PACKET_LENGTH-5):
            #self.socket.send(prelude + sql)        # JAWBONE - OLD - PREFER SENDALL
            self.socket.sendall(prelude + sql)      # JAWBONE - NEW - PREFER SENDALL
            if DEBUG: dump_packet(prelude + sql)
        else:
            #self.socket.send(prelude)              # JAWBONE - OLD - PREFER SENDALL
            self.socket.sendall(prelude)            # JAWBONE - OLD - PREFER SENDALL
            if DEBUG: dump_packet(send_data)
            while len(sql) > MAX_PACKET_LENGTH:
                self.socket.sendall(sql[:MAX_PACKET_LENGTH])
                if DEBUG: dump_packet(sql[:MAX_PACKET_LENGTH])
                sql = sql[MAX_PACKET_LENGTH:]
            if len(sql) > 0:
                self.socket.sendall(sql)
开发者ID:flymio,项目名称:hammer,代码行数:24,代码来源:connections.py


注:本文中的util.int2byte函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。