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


Python six.int2byte方法代码示例

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


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

示例1: _SignedVarintEncoder

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

  def EncodeSignedVarint(write, value, unused_deterministic=None):
    if value < 0:
      value += (1 << 64)
    bits = value & 0x7f
    value >>= 7
    while value:
      write(six.int2byte(0x80|bits))
      bits = value & 0x7f
      value >>= 7
    return write(six.int2byte(bits))

  return EncodeSignedVarint 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:encoder.py

示例2: _SignedVarintEncoder

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

  def EncodeSignedVarint(write, value):
    if value < 0:
      value += (1 << 64)
    bits = value & 0x7f
    value >>= 7
    while value:
      write(six.int2byte(0x80|bits))
      bits = value & 0x7f
      value >>= 7
    return write(six.int2byte(bits))

  return EncodeSignedVarint 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:encoder.py

示例3: parse_response_data

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [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

示例4: set_alpn_protos

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def set_alpn_protos(self, protos):
        """
        Specify the clients ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        """
        # Take the list of protocols and join them together, prefixing them
        # with their lengths.
        protostr = b''.join(
            chain.from_iterable((int2byte(len(p)), p) for p in protos)
        )

        # Build a C string from the list. We don't need to save this off
        # because OpenSSL immediately copies the data out.
        input_str = _ffi.new("unsigned char[]", protostr)
        input_str_len = _ffi.cast("unsigned", len(protostr))
        _lib.SSL_CTX_set_alpn_protos(self._context, input_str, input_str_len) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:23,代码来源:SSL.py

示例5: _truncate_digest

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def _truncate_digest(digest, order_bits):
    digest_len = len(digest)

    if 8 * digest_len > order_bits:
        digest_len = (order_bits + 7) // 8
        digest = digest[:digest_len]

    if 8 * digest_len > order_bits:
        rshift = 8 - (order_bits & 0x7)
        assert 0 < rshift < 8

        mask = 0xFF >> rshift << rshift

        # Set the bottom rshift bits to 0
        digest = digest[:-1] + six.int2byte(six.indexbytes(digest, -1) & mask)

    return digest 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:19,代码来源:utils.py

示例6: btc_tx_der_encode_integer

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def btc_tx_der_encode_integer(r):
    """
    Return a DER-encoded integer

    Based on code from python-ecdsa (https://github.com/warner/python-ecdsa)
    by Brian Warner.  Subject to the MIT license.
    """
    # borrowed from python-ecdsa
    if r < 0:
        raise ValueError('cannot support negative numbers')

    h = ("%x" % r).encode()
    if len(h) % 2:
        h = b("0") + h
    s = binascii.unhexlify(h)
    num = s[0] if isinstance(s[0], integer_types) else ord(s[0])
    if num <= 0x7f:
        return b("\x02") + int2byte(len(s)) + s
    else:
        # DER integers are two's complement, so if the first byte is
        # 0x80-0xff then we need an extra 0x00 byte to prevent it from
        # looking negative.
        return b("\x02") + int2byte(len(s)+1) + b("\x00") + s 
开发者ID:blockstack,项目名称:virtualchain,代码行数:25,代码来源:bits.py

示例7: btc_tx_der_encode_length

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def btc_tx_der_encode_length(l):
    """
    Return a DER-encoded length field

    Based on code from python-ecdsa (https://github.com/warner/python-ecdsa)
    by Brian Warner.  Subject to the MIT license.
    """
    if l < 0:
        raise ValueError("length cannot be negative")

    if l < 0x80:
        return int2byte(l)
    s = ("%x" % l).encode()
    if len(s) % 2:
        s = b("0") + s
    s = binascii.unhexlify(s)
    llen = len(s)
    return int2byte(0x80 | llen) + s 
开发者ID:blockstack,项目名称:virtualchain,代码行数:20,代码来源:bits.py

示例8: _bytes_text

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def _bytes_text(code_point_iter, quote, prefix=b'', suffix=b''):
    quote_code_point = None if len(quote) == 0 else six.byte2int(quote)
    buf = BytesIO()
    buf.write(prefix)
    buf.write(quote)
    for code_point in code_point_iter:
        if code_point == quote_code_point:
            buf.write(b'\\' + quote)
        elif code_point == six.byte2int(b'\\'):
            buf.write(b'\\\\')
        elif _is_printable_ascii(code_point):
            buf.write(six.int2byte(code_point))
        else:
            buf.write(_escape(code_point))
    buf.write(quote)
    buf.write(suffix)
    return buf.getvalue() 
开发者ID:amzn,项目名称:ion-python,代码行数:19,代码来源:writer_text.py

示例9: _normalize_user

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def _normalize_user(oxx, mod, k, uv):
    try:
        from_user = getattr(mod, oxx + '_from_user')
        (n, v, m) = from_user(k, uv)
    except:
        return (k, uv)
    # apply mask
    if m is not None:
        v = b''.join(six.int2byte(_ord(x) & _ord(y)) for (x, y) in zip(v, m))
    try:
        to_user = getattr(mod, oxx + '_to_user')
        (k2, uv2) = to_user(n, v, m)
    except:
        return (k, uv)
    assert k2 == k
    return (k2, uv2) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:18,代码来源:oxx_fields.py

示例10: decode

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def decode(self, ids, strip_extraneous=False):
    if strip_extraneous:
      ids = strip_ids(ids, list(range(self._num_reserved_ids or 0)))
    numres = self._num_reserved_ids
    decoded_ids = []
    int2byte = six.int2byte
    for id_ in ids:
      if 0 <= id_ < numres:
        decoded_ids.append(RESERVED_TOKENS_BYTES[int(id_)])
      else:
        decoded_ids.append(int2byte(id_ - numres))
    if six.PY2:
      return "".join(decoded_ids)
    # Python3: join byte arrays and then decode string
    return b"".join(decoded_ids).decode("utf-8", "replace") 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:17,代码来源:text_encoder.py

示例11: decode_list

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def decode_list(self, ids):
    numres = self._num_reserved_ids
    decoded_ids = []
    int2byte = six.int2byte
    for id_ in ids:
      if 0 <= id_ < numres:
        decoded_ids.append(RESERVED_TOKENS_BYTES[int(id_)])
      else:
        decoded_ids.append(int2byte(id_ - numres))
    # Python3: join byte arrays and then decode string
    return decoded_ids 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:13,代码来源:text_encoder.py

示例12: xor

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [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

示例13: encodeint

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def encodeint(y):
    bits = [(y >> i) & 1 for i in range(b)]
    return b''.join([
        six.int2byte(sum([bits[i * 8 + j] << j for j in range(8)]))
        for i in range(b//8)
    ]) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:8,代码来源:ed25519.py

示例14: encodepoint

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def encodepoint(P):
    (x, y, z, t) = P
    zi = inv(z)
    x = (x * zi) % q
    y = (y * zi) % q
    bits = [(y >> i) & 1 for i in range(b - 1)] + [x & 1]
    return b''.join([
        six.int2byte(sum([bits[i * 8 + j] << j for j in range(8)]))
        for i in range(b // 8)
    ]) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:12,代码来源:ed25519.py

示例15: quote_chinese

# 需要导入模块: import six [as 别名]
# 或者: from six import int2byte [as 别名]
def quote_chinese(url, encodeing="utf-8"):
    """Quote non-ascii characters"""
    if isinstance(url, six.text_type):
        return quote_chinese(url.encode(encodeing))
    if six.PY3:
        res = [six.int2byte(b).decode('latin-1') if b < 128 else '%%%02X' % b for b in url]
    else:
        res = [b if ord(b) < 128 else '%%%02X' % ord(b) for b in url]
    return "".join(res) 
开发者ID:binux,项目名称:pyspider,代码行数:11,代码来源:url.py


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