• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python six.indexbytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: decrypt

    def decrypt(self, ctxt, ttl=None, associated_data=''):
        if not isinstance(ctxt, bytes):
            raise TypeError("ctxt must be bytes.")

        try:
            data = base64.urlsafe_b64decode(ctxt)
        except (TypeError, binascii.Error):
            raise InvalidToken
        
        if not data:
            raise InvalidToken

        # return: version || iv || ctx || tag
        if six.indexbytes(data, 0) == 0x80:
            # This is a Fernet1 (old version) ctx, handle accordingly
            try:
                msg = self._fernet1.decrypt(ctxt, ttl=ttl)
            except Exception:
                raise InvalidToken
            return msg
        elif six.indexbytes(data, 0) != 0x81:
            raise InvalidToken
        assert not debug or not ttl, "You are calling new fernet with ttl values."

        # First, verify the tag
        basic_parts = (
            b"\x81" + bytes(associated_data) + data[1:-32]
        )

        try:
            self.SHA256hmac(self._signing_key, basic_parts, sig=data[-32:])
        except InvalidSignature:
            raise InvalidToken

        # Now decrypt the text
        # version (1-byte) || iv (16-byte) || ctx || tag (32-byte)
        iv = data[1:17]
        ciphertext = data[17:-32]
        decryptor = Cipher(
            algorithms.AES(self._encryption_key), modes.CBC(iv), self._backend
        ).decryptor()
        plaintext_padded = decryptor.update(ciphertext)
        try:
            plaintext_padded += decryptor.finalize()
        except ValueError:
            raise InvalidToken
        unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()

        unpadded = unpadder.update(plaintext_padded)
        try:
            unpadded += unpadder.finalize()
        except ValueError:
            raise InvalidToken
        return unpadded
开发者ID:NCEghtebas,项目名称:cryptohw5,代码行数:54,代码来源:fernet2.py


示例17: unpad

def unpad(data):
    # At the moment, this is only used for unpadding private keys on disk. This
    # really ought to be made constant time (possibly by upstreaming this logic
    # into pyca/cryptography).
    padding_length = six.indexbytes(data, -1)
    if padding_length > 16:
        raise SSHException("Invalid key")
    for i in range(1, padding_length + 1):
        if six.indexbytes(data, -i) != (padding_length - i + 1):
            raise SSHException("Invalid key")
    return data[:-padding_length]
开发者ID:DanLipsitt,项目名称:paramiko,代码行数:11,代码来源:ed25519key.py


示例18: decode_bigint

 def decode_bigint(self, n, buf, offset):
     sign = six.indexbytes(buf, offset)
     offset += 1
     b = 1
     val = 0
     for i in range(n):
         val += six.indexbytes(buf, offset) * b
         b <<= 8
         offset += 1
     if sign != 0:
         val = -val
     return val, offset
开发者ID:ichernetsky,项目名称:python-erlastic,代码行数:12,代码来源:codec.py


示例19: HNxorg

def HNxorg( hash_class, N, g ):
    bN = ctypes.create_string_buffer( BN_num_bytes(N) )
    bg = ctypes.create_string_buffer( BN_num_bytes(g) )

    BN_bn2bin(N, bN)
    BN_bn2bin(g, bg)

    padding = len(bN) - len(bg) if _rfc5054_compat else 0

    hN = hash_class( bN.raw ).digest()
    hg = hash_class( b''.join([ b'\0'*padding, bg.raw ]) ).digest()

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


示例20: decode

    def decode(cls, data, connection=None, payload_auto_decode=True):
        if len(data) < 4:
            raise NotEnoughData("Not enough data to decode header")

        if six.indexbytes(data, 3) == 0x00 and six.indexbytes(data, 4) == 0x02:
            obj = SSLv2Record(
                connection=connection
            )
        elif six.indexbytes(data, 1) == 0x03:
            obj = SSLv3Record(
                connection=connection
            )

        data = obj.dissect(data)
        return (obj, data)
开发者ID:DinoTools,项目名称:python-flextls,代码行数:15,代码来源:record.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python six.int2byte函数代码示例发布时间:2022-05-27
下一篇:
Python six.get_unbound_function函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap