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


Python six.indexbytes方法代码示例

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


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

示例1: _VarintDecoder

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def _VarintDecoder(mask, result_type):
  """Return an encoder for a basic varint value (does not include tag).

  Decoded values will be bitwise-anded with the given mask before being
  returned, e.g. to limit them to 32 bits.  The returned decoder does not
  take the usual "end" parameter -- the caller is expected to do bounds checking
  after the fact (often the caller can defer such checking until later).  The
  decoder returns a (value, new_pos) pair.
  """

  def DecodeVarint(buffer, pos):
    result = 0
    shift = 0
    while 1:
      b = six.indexbytes(buffer, pos)
      result |= ((b & 0x7f) << shift)
      pos += 1
      if not (b & 0x80):
        result &= mask
        result = result_type(result)
        return (result, pos)
      shift += 7
      if shift >= 64:
        raise _DecodeError('Too many bytes when decoding varint.')
  return DecodeVarint 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:decoder.py

示例2: ReadTag

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def ReadTag(buffer, pos):
  """Read a tag from the buffer, and return a (tag_bytes, new_pos) tuple.

  We return the raw bytes of the tag rather than decoding them.  The raw
  bytes can then be used to look up the proper decoder.  This effectively allows
  us to trade some work that would be done in pure-python (decoding a varint)
  for work that is done in C (searching for a byte string in a hash table).
  In a low-level language it would be much cheaper to decode the varint and
  use that, but not in Python.
  """

  start = pos
  while six.indexbytes(buffer, pos) & 0x80:
    pos += 1
  pos += 1
  return (six.binary_type(buffer[start:pos]), pos)


# -------------------------------------------------------------------- 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:decoder.py

示例3: ReadTag

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def ReadTag(buffer, pos):
  """Read a tag from the buffer, and return a (tag_bytes, new_pos) tuple.

  We return the raw bytes of the tag rather than decoding them.  The raw
  bytes can then be used to look up the proper decoder.  This effectively allows
  us to trade some work that would be done in pure-python (decoding a varint)
  for work that is done in C (searching for a byte string in a hash table).
  In a low-level language it would be much cheaper to decode the varint and
  use that, but not in Python.
  """

  start = pos
  while six.indexbytes(buffer, pos) & 0x80:
    pos += 1
  pos += 1
  return (buffer[start:pos], pos)


# -------------------------------------------------------------------- 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:decoder.py

示例4: parse_response_data

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def parse_response_data(resp_data):
    """
    According to https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-raw-message-formats.html#authentication-response-message-success
    the response is made up of
    0:      user presence byte
    1-4:    counter
    5-:     signature

    :param resp_data: response data from the FIDO U2F client
    :type resp_data: hex string
    :return: tuple of user_presence_byte(byte), counter(int),
        signature(hexstring)
    """
    resp_data_bin = binascii.unhexlify(resp_data)
    user_presence = six.int2byte(six.indexbytes(resp_data_bin, 0))
    signature = resp_data_bin[5:]
    counter = struct.unpack(">L", resp_data_bin[1:5])[0]
    return user_presence, counter, signature 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:20,代码来源:u2f.py

示例5: _load_ssh_ecdsa_public_key

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def _load_ssh_ecdsa_public_key(expected_key_type, decoded_data, backend):
    curve_name, rest = _ssh_read_next_string(decoded_data)
    data, rest = _ssh_read_next_string(rest)

    if expected_key_type != b"ecdsa-sha2-" + curve_name:
        raise ValueError(
            'Key header and key body contain different key type values.'
        )

    if rest:
        raise ValueError('Key body contains extra bytes.')

    curve = {
        b"nistp256": ec.SECP256R1,
        b"nistp384": ec.SECP384R1,
        b"nistp521": ec.SECP521R1,
    }[curve_name]()

    if six.indexbytes(data, 0) != 4:
        raise NotImplementedError(
            "Compressed elliptic curve points are not supported"
        )

    numbers = ec.EllipticCurvePublicNumbers.from_encoded_point(curve, data)
    return numbers.public_key(backend) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:serialization.py

示例6: _get_unverified_token_data

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def _get_unverified_token_data(token):
        if not isinstance(token, bytes):
            raise TypeError("token must be bytes.")

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

        if not data or six.indexbytes(data, 0) != 0x80:
            raise InvalidToken

        try:
            timestamp, = struct.unpack(">Q", data[1:9])
        except struct.error:
            raise InvalidToken
        return timestamp, data 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:fernet.py

示例7: _load_ssh_ecdsa_public_key

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def _load_ssh_ecdsa_public_key(expected_key_type, decoded_data, backend):
    curve_name, rest = _ssh_read_next_string(decoded_data)
    data, rest = _ssh_read_next_string(rest)

    if expected_key_type != b"ecdsa-sha2-" + curve_name:
        raise ValueError(
            'Key header and key body contain different key type values.'
        )

    if rest:
        raise ValueError('Key body contains extra bytes.')

    curve = {
        b"nistp256": ec.SECP256R1,
        b"nistp384": ec.SECP384R1,
        b"nistp521": ec.SECP521R1,
    }[curve_name]()

    if six.indexbytes(data, 0) != 4:
        raise NotImplementedError(
            "Compressed elliptic curve points are not supported"
        )

    return ec.EllipticCurvePublicKey.from_encoded_point(curve, data) 
开发者ID:tp4a,项目名称:teleport,代码行数:26,代码来源:ssh.py

示例8: enable

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def enable(self, cpuSet, events):
    """
    Enables pmu events in a set of target cpus

    :param cpuSet: A set of cpu cores to enable pmu
    :param events: A list of pmu events to be enabled

    """
    if not self.device:
      raise Exception('xpedite device not enabled - use "with PMUCtrl() as pmuCtrl:" to init device')

    eventSet = self.buildEventSet(self.eventsDb, cpuSet, events)
    for cpu in cpuSet:
      requestGroup = self.buildRequestGroup(cpu, eventSet)
      LOGGER.debug(
        'sending request (%d bytes) to xpedite ko [%s]',
        len(requestGroup), ':'.join('{:02x}'.format(six.indexbytes(requestGroup, i))
                                    for i in range(0, len(requestGroup)))
      )
      self.device.write(requestGroup)
      self.device.flush()
    return eventSet 
开发者ID:Morgan-Stanley,项目名称:Xpedite,代码行数:24,代码来源:pmuctrl.py

示例9: read_byte

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def read_byte(self):
        if self.__size < 1:
            raise IndexError('Buffer queue is empty')
        segments = self.__segments
        segment = segments[0]
        segment_len = len(segment)
        offset = self.__offset
        if BufferQueue.is_eof(segment):
            octet = _EOF
        else:
            octet = self.__ord(six.indexbytes(segment, offset))
        offset += 1
        if offset == segment_len:
            offset = 0
            segments.popleft()
        self.__offset = offset
        self.__size -= 1
        self.position += 1
        return octet 
开发者ID:amzn,项目名称:ion-python,代码行数:21,代码来源:reader.py

示例10: _int_factory

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def _int_factory(sign, data):
    def parse_int():
        value = 0
        length = len(data)
        while length >= 8:
            segment = _rslice(data, length, 8)
            value <<= 64
            value |= unpack('>Q', segment)[0]
            length -= 8
        if length >= 4:
            segment = _rslice(data, length, 4)
            value <<= 32
            value |= unpack('>I', segment)[0]
            length -= 4
        if length >= 2:
            segment = _rslice(data, length, 2)
            value <<= 16
            value |= unpack('>H', segment)[0]
            length -= 2
        if length == 1:
            value <<= 8
            value |= six.indexbytes(data, -length)
        return sign * value
    return parse_int 
开发者ID:amzn,项目名称:ion-python,代码行数:26,代码来源:reader_binary.py

示例11: parser

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def parser(cls, buf):
        (diag, flags, detect_mult, length, my_discr, your_discr,
         desired_min_tx_interval, required_min_rx_interval,
         required_min_echo_rx_interval) = \
            struct.unpack_from(cls._PACK_STR, buf[:cls._PACK_STR_LEN])

        ver = diag >> 5
        diag = diag & 0x1f
        state = flags >> 6
        flags = flags & 0x3f

        if flags & BFD_FLAG_AUTH_PRESENT:
            auth_type = six.indexbytes(buf, cls._PACK_STR_LEN)
            auth_cls = cls._auth_parsers[auth_type].\
                parser(buf[cls._PACK_STR_LEN:])[0]
        else:
            auth_cls = None

        msg = cls(ver, diag, state, flags, detect_mult,
                  my_discr, your_discr, desired_min_tx_interval,
                  required_min_rx_interval, required_min_echo_rx_interval,
                  auth_cls)

        return msg, None, None 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:26,代码来源:bfd.py

示例12: serialize

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def serialize(self):
        # fixup
        byte_length = (self.length + 7) // 8
        bin_addr = self._to_bin(self.addr)
        if (self.length % 8) == 0:
            bin_addr = bin_addr[:byte_length]
        else:
            # clear trailing bits in the last octet.
            # rfc doesn't require this.
            mask = 0xff00 >> (self.length % 8)
            last_byte = six.int2byte(
                six.indexbytes(bin_addr, byte_length - 1) & mask)
            bin_addr = bin_addr[:byte_length - 1] + last_byte
        self.addr = self._from_bin(bin_addr)

        buf = bytearray()
        msg_pack_into(self._PACK_STR, buf, 0, self.length)
        return buf + bytes(bin_addr) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:20,代码来源:bgp.py

示例13: is_compressed

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def is_compressed(serialized_data):
        """Check whatever the data was serialized with compression."""
        return six.indexbytes(serialized_data, 0) == ord("c") 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:5,代码来源:carbonara.py

示例14: xor

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def xor(key, data):
    """
    Perform cyclical exclusive or operations on ``data``.

    The ``key`` can be a an integer *(0 <= key < 256)* or a byte sequence. If
    the key is smaller than the provided ``data``, the ``key`` will be
    repeated.

    Args:
        key(int or bytes): The key to xor ``data`` with.
        data(bytes): The data to perform the xor operation on.

    Returns:
        bytes: The result of the exclusive or operation.

    Examples:
        >>> from pwny import *
        >>> xor(5, b'ABCD')
        b'DGFA'
        >>> xor(5, b'DGFA')
        b'ABCD'
        >>> xor(b'pwny', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
        b'15-=51)19=%5=9!)!%=-%!9!)-'
        >>> xor(b'pwny', b'15-=51)19=%5=9!)!%=-%!9!)-')
        b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    """

    if type(key) is int:
        key = six.int2byte(key)
    key_len = len(key)

    return b''.join(
        six.int2byte(c ^ six.indexbytes(key, i % key_len))
        for i, c in enumerate(six.iterbytes(data))
    ) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:37,代码来源:codec.py

示例15: bit

# 需要导入模块: import six [as 别名]
# 或者: from six import indexbytes [as 别名]
def bit(h, i):
    return (six.indexbytes(h, i // 8) >> (i % 8)) & 1 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:4,代码来源:ed25519.py


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