當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。