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