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


Python six.indexbytes函数代码示例

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


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

示例1: _multi_char_find

 def _multi_char_find(self, needle, start, stop, mask, skip):
     i = start - 1
     w = (stop - start) - len(needle)
     while i + 1 <= start + w:
         i += 1
         if self._data[i + len(needle) - 1] == six.indexbytes(needle, -1):
             for j in xrange(len(needle) - 1):
                 if self._data[i + j] != six.indexbytes(needle, j):
                     break
             else:
                 return i
             if (
                 i + len(needle) < len(self) and
                 not self._bloom(mask, self._data[i + len(needle)])
             ):
                 i += len(needle)
             else:
                 i += skip
         else:
             if (
                 i + len(needle) < len(self) and
                 not self._bloom(mask, self._data[i + len(needle)])
             ):
                 i += len(needle)
     return -1
开发者ID:adamchainz,项目名称:zero_buffer,代码行数:25,代码来源:zero_buffer.py

示例2: process_IAC

    def process_IAC(self, sock, cmd, option):
        """
            Read in and parse IAC commands as passed by telnetlib.

            SB/SE commands are stored in sbdataq, and passed in w/ a command
            of SE.
        """
        if cmd == DO:
            if option == TM:
                # timing mark - send WILL into outgoing stream
                os.write(self.remote, IAC + WILL + TM)
            else:
                pass
        elif cmd == IP:
            # interrupt process
            os.write(self.local, IPRESP)
        elif cmd == SB:
            pass
        elif cmd == SE:
            option = self.sbdataq[0]
            if option == NAWS[0]:
                # negotiate window size.
                cols = six.indexbytes(self.sbdataq, 1)
                rows = six.indexbytes(self.sbdataq, 2)
                s = struct.pack('HHHH', rows, cols, 0, 0)
                fcntl.ioctl(self.local, termios.TIOCSWINSZ, s)
        elif cmd == DONT:
            pass
        else:
            pass
开发者ID:sassoftware,项目名称:epdb,代码行数:30,代码来源:epdb_server.py

示例3: __new__

    def __new__(cls, *args):
        if len(args) == 1:
            data = args[0]
            if isinstance(data, int):  # Called with tag only, blank value
                tag = data
                value = b''
            else:  # Called with binary TLV data
                tag = six.indexbytes(data, 0)
                ln = six.indexbytes(data, 1)
                offs = 2
                if ln > 0x80:
                    n_bytes = ln - 0x80
                    ln = bytes2int(data[offs:offs + n_bytes])
                    offs = offs + n_bytes
                value = data[offs:offs+ln]
        elif len(args) == 2:  # Called with tag and value.
            (tag, value) = args
        else:
            raise TypeError('{}() takes at most 2 arguments ({} given)'.format(
                cls, len(args)))

        data = bytearray([tag])
        length = len(value)
        if length < 0x80:
            data.append(length)
        elif length < 0xff:
            data.extend([0x81, length])
        else:
            data.extend([0x82, length >> 8, length & 0xff])
        data += value

        return super(Tlv, cls).__new__(cls, bytes(data))
开发者ID:Yubico,项目名称:yubikey-manager,代码行数:32,代码来源:util.py

示例4: calculate

    def calculate(self, cred, timestamp=None):

        # The 4.2.0-4.2.6 firmwares have a known issue with credentials that
        # require touch: If this action is performed within 2 seconds of a
        # command resulting in a long response (over 54 bytes),
        # the command will hang. A workaround is to send an invalid command
        # (resulting in a short reply) prior to the "calculate" command.
        if self._426device and cred.touch:
            self._driver.send_apdu(0, 0, 0, 0, '', check=SW.INVALID_INSTRUCTION)

        if timestamp is None:
            timestamp = int(time.time())
        if cred.oath_type == OATH_TYPE.TOTP:
            valid_from = timestamp - (timestamp % cred.period)
            valid_to = valid_from + cred.period
            challenge = time_challenge(timestamp, period=cred.period)
        else:
            valid_from = timestamp
            valid_to = float('Inf')
            challenge = b''
        data = Tlv(TAG.NAME, cred.key) + Tlv(TAG.CHALLENGE, challenge)
        resp = self.send_apdu(INS.CALCULATE, 0, 0, data)
        resp = parse_tlvs(resp)[0].value
        # Manual dynamic truncation is required
        # for Steam entries, so let's do it for all.
        digits = six.indexbytes(resp, 0)
        resp = resp[1:]
        offset = six.indexbytes(resp, -1) & 0xF
        code_data = resp[offset:offset + 4]
        code_data = parse_truncated(code_data)
        code_value = format_code(code_data, digits, steam=cred.is_steam)
        return Code(code_value, valid_from, valid_to)
开发者ID:Yubico,项目名称:yubikey-manager,代码行数:32,代码来源:oath.py

示例5: _parse_messages

    def _parse_messages(self):
        """ Parses for messages in the buffer *buf*.  It is assumed that
        the buffer contains the start character for a message, but that it
        may contain only part of the rest of the message.

        Returns an array of messages, and the buffer remainder that
        didn't contain any full messages."""
        msgs = []
        end_idx = 0
        buf = self._buf
        while buf:
            frame_type = six.indexbytes(buf, 0)
            if frame_type == 0:
                # Normal message.
                end_idx = buf.find(b"\xFF")
                if end_idx == -1:  # pragma NO COVER
                    break
                msgs.append(buf[1:end_idx].decode('utf-8', 'replace'))
                buf = buf[end_idx + 1:]
            elif frame_type == 255:
                # Closing handshake.
                assert six.indexbytes(buf, 1) == 0, "Unexpected closing handshake: %r" % buf
                self.websocket_closed = True
                break
            else:
                raise ValueError("Don't understand how to parse this type of message: %r" % buf)
        self._buf = buf
        return msgs
开发者ID:2216288075,项目名称:meiduo_project,代码行数:28,代码来源:websocket.py

示例6: rldecode

def rldecode(data):
    """
    RunLength decoder (Adobe version) implementation based on PDF Reference
    version 1.4 section 3.3.4:
        The RunLengthDecode filter decodes data that has been encoded in a
        simple byte-oriented format based on run length. The encoded data
        is a sequence of runs, where each run consists of a length byte
        followed by 1 to 128 bytes of data. If the length byte is in the
        range 0 to 127, the following length + 1 (1 to 128) bytes are
        copied literally during decompression. If length is in the range
        129 to 255, the following single byte is to be copied 257 - length
        (2 to 128) times during decompression. A length value of 128
        denotes EOD.
    """
    decoded = b''
    i = 0
    while i < len(data):
        #print 'data[%d]=:%d:' % (i,ord(data[i]))
        length = six.indexbytes(data,i)
        if length == 128:
            break
        if length >= 0 and length < 128:
            for j in range(i+1,(i+1)+(length+1)):
                decoded+=six.int2byte(six.indexbytes(data,j))
            #print 'length=%d, run=%s' % (length+1,run)
            
            i = (i+1) + (length+1)
        if length > 128:
            run = six.int2byte(six.indexbytes(data,i+1))*(257-length)
            #print 'length=%d, run=%s' % (257-length,run)
            decoded+=run
            i = (i+1) + 1
    return decoded
开发者ID:qstin,项目名称:darkmoney,代码行数:33,代码来源:runlength.py

示例7: _make_rfind_mask

 def _make_rfind_mask(self, needle):
     mask = self._bloom_add(0, six.indexbytes(needle, 0))
     skip = len(needle) - 1
     for i in xrange(len(needle) - 1, 0, -1):
         mask = self._bloom_add(mask, six.indexbytes(needle, i))
         if needle[i] == needle[0]:
             skip = i - 1
     return mask, skip
开发者ID:adamchainz,项目名称:zero_buffer,代码行数:8,代码来源:zero_buffer.py

示例8: _gen_creds

 def _gen_creds():
     resp = self.send_apdu(INS.LIST, 0, 0)
     while resp:
         length = six.indexbytes(resp, 1) - 1
         oath_type = OATH_TYPE(MASK.TYPE & six.indexbytes(resp, 2))
         key = resp[3:3 + length]
         yield Credential(key, oath_type)
         resp = resp[3 + length:]
开发者ID:Yubico,项目名称:yubikey-manager,代码行数:8,代码来源:oath.py

示例9: _set_mode_otp

 def _set_mode_otp(self, mode_data):
     resp = self.select(AID.OTP)
     pgm_seq_old = six.indexbytes(resp, 3)
     resp = self.send_apdu(0, OTP_INS.YK2_REQ, SLOT.DEVICE_CONFIG, 0,
                           mode_data)
     pgm_seq_new = six.indexbytes(resp, 3)
     if not _pgm_seq_ok(pgm_seq_old, pgm_seq_new):
         raise ModeSwitchError()
开发者ID:Yubico,项目名称:yubikey-manager,代码行数:8,代码来源:driver_ccid.py

示例10: truncate

    def truncate(self, digest):
        offset = six.indexbytes(digest, -1) & 0x0f

        binary = (six.indexbytes(digest, (offset + 0)) & 0x7f) << 24
        binary |= (six.indexbytes(digest, (offset + 1)) & 0xff) << 16
        binary |= (six.indexbytes(digest, (offset + 2)) & 0xff) << 8
        binary |= (six.indexbytes(digest, (offset + 3)) & 0xff)

        return binary % (10 ** self.digits)
开发者ID:privacyidea,项目名称:privacyidea,代码行数:9,代码来源:HMAC.py

示例11: _make_find_mask

 def _make_find_mask(self, needle):
     mlast = len(needle) - 1
     mask = 0
     skip = mlast - 1
     for i in xrange(mlast):
         mask = self._bloom_add(mask, six.indexbytes(needle, i))
         if needle[i] == needle[mlast]:
             skip = mlast - i - 1
     mask = self._bloom_add(mask, six.indexbytes(needle, mlast))
     return mask, skip
开发者ID:adamchainz,项目名称:zero_buffer,代码行数:10,代码来源:zero_buffer.py

示例12: bytes_eq

 def bytes_eq(buf1, buf2):
     if buf1 != buf2:
         msg = 'EOF in either data'
         for i in range(0, min(len(buf1), len(buf2))):
             c1 = six.indexbytes(six.binary_type(buf1), i)
             c2 = six.indexbytes(six.binary_type(buf2), i)
             if c1 != c2:
                 msg = 'differs at chr %d, %d != %d' % (i, c1, c2)
                 break
         assert buf1 == buf2, "%r != %r, %s" % (buf1, buf2, msg)
开发者ID:AsmaSwapna,项目名称:ryu,代码行数:10,代码来源:test_parser.py

示例13: HNxorg

def HNxorg( hash_class, N, g ):
    bin_N = long_to_bytes(N)
    bin_g = long_to_bytes(g)

    padding = len(bin_N) - len(bin_g) if _rfc5054_compat else 0

    hN = hash_class( bin_N ).digest()
    hg = hash_class( b''.join( [b'\0'*padding, bin_g] ) ).digest()

    return six.b( ''.join( chr( six.indexbytes(hN, i) ^ six.indexbytes(hg, i) ) for i in range(0,len(hN)) ) )
开发者ID:cocagne,项目名称:pysrp,代码行数:10,代码来源:_pysrp.py

示例14: decode_int

def decode_int(x, f):
    f += 1
    newf = x.find(b'e', f)
    n = int(x[f:newf])
    if six.indexbytes(x, f) == 45:
        if six.indexbytes(x, f+1) == 48:
            raise ValueError
    elif six.indexbytes(x, f) == 48 and newf != f+1:
        raise ValueError
    return (n, newf+1)
开发者ID:Hellowlol,项目名称:autotorrent,代码行数:10,代码来源:bencode.py

示例15: encode

def encode(value):
	"""Encodes bytes to a base65536 string."""
	stream = io.StringIO()
	length = len(value)
	for x in range(0, length, 2):
		b1 = indexbytes(value, x)
		b2 = indexbytes(value, x + 1) if x + 1 < length else -1
		code_point = BLOCK_START[b2] + b1
		stream.write(unichr(code_point))
	return stream.getvalue()
开发者ID:PepperoniAndCheese,项目名称:GCTF-challenges,代码行数:10,代码来源:base65536.py


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