當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.bytes_to_native_str方法代碼示例

本文整理匯總了Python中future.utils.bytes_to_native_str方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.bytes_to_native_str方法的具體用法?Python utils.bytes_to_native_str怎麽用?Python utils.bytes_to_native_str使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在future.utils的用法示例。


在下文中一共展示了utils.bytes_to_native_str方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: do_POST

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def do_POST(self):
        self.logger.debug('Webhook triggered')
        try:
            self._validate_post()
            clen = self._get_content_len()
        except _InvalidPost as e:
            self.send_error(e.http_code)
            self.end_headers()
        else:
            buf = self.rfile.read(clen)
            json_string = bytes_to_native_str(buf)

            self.send_response(200)
            self.end_headers()

            self.logger.debug('Webhook received data: ' + json_string)

            update = Update.de_json(json.loads(json_string), self.server.bot)

            self.logger.debug('Received Update with ID %d on Webhook' % update.update_id)
            self.server.update_queue.put(update) 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:23,代碼來源:webhookhandler.py

示例2: multiply

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def multiply(s, pub, usehex, rawpub=True, return_serialized=True):
    '''Input binary compressed pubkey P(33 bytes)
    and scalar s(32 bytes), return s*P.
    The return value is a binary compressed public key,
    or a PublicKey object if return_serialized is False.
    Note that the called function does the type checking
    of the scalar s.
    ('raw' options passed in)
    '''
    newpub = secp256k1.PublicKey(pub)
    #see note to "tweak_mul" function in podle.py
    if sys.version_info >= (3,0):
        res = newpub.multiply(native_bytes(s))
    else:
        res = newpub.multiply(bytes_to_native_str(s))
    if not return_serialized:
        return res
    return res.format() 
開發者ID:JoinMarket-Org,項目名稱:joinmarket-clientserver,代碼行數:20,代碼來源:secp256k1_main.py

示例3: kms_encrypt

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def kms_encrypt(value, key, aws_config=None):
    """Encrypt and value with KMS key.

    Args:
        value (str): value to encrypt
        key (str): key id or alias
        aws_config (optional[dict]): aws credentials
            dict of arguments passed into boto3 session
            example:
                aws_creds = {'aws_access_key_id': aws_access_key_id,
                             'aws_secret_access_key': aws_secret_access_key,
                             'region_name': 'us-east-1'}

    Returns:
        str: encrypted cipher text
    """
    aws_config = aws_config or {}
    aws = boto3.session.Session(**aws_config)
    client = aws.client('kms')
    enc_res = client.encrypt(KeyId=key, Plaintext=value)
    return n(b64encode(enc_res['CiphertextBlob'])) 
開發者ID:theherk,項目名稱:figgypy,代碼行數:23,代碼來源:util.py

示例4: test_str_encode_decode_with_py2_str_arg

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def test_str_encode_decode_with_py2_str_arg(self):
        # Try passing a standard Py2 string (as if unicode_literals weren't imported)
        b = str(TEST_UNICODE_STR).encode(utils.bytes_to_native_str(b'utf-8'))
        self.assertTrue(isinstance(b, bytes))
        self.assertFalse(isinstance(b, str))
        s = b.decode(utils.bytes_to_native_str(b'utf-8'))
        self.assertTrue(isinstance(s, str))
        self.assertEqual(s, TEST_UNICODE_STR) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:10,代碼來源:test_str.py

示例5: privkey_to_pubkey_inner

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def privkey_to_pubkey_inner(priv, usehex):
    '''Take 32/33 byte raw private key as input.
    If 32 bytes, return compressed (33 byte) raw public key.
    If 33 bytes, read the final byte as compression flag,
    and return compressed/uncompressed public key as appropriate.'''
    compressed, priv = read_privkey(priv)
    #secp256k1 checks for validity of key value.
    if sys.version_info >= (3,0):
        newpriv = secp256k1.PrivateKey(secret=native_bytes(priv))
    else:
        newpriv = secp256k1.PrivateKey(secret=bytes_to_native_str(priv))
    return newpriv.public_key.format(compressed) 
開發者ID:JoinMarket-Org,項目名稱:joinmarket-clientserver,代碼行數:14,代碼來源:secp256k1_main.py

示例6: test_kms_encrypt

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def test_kms_encrypt(self):
        key = 'alias/figgypy-test'
        secret = 'correct horse battery staple'
        client = boto3.client('kms')
        encrypted = kms_encrypt(secret, key)
        dec_res = client.decrypt(CiphertextBlob=b64decode(encrypted))
        decrypted = n(dec_res['Plaintext'])
        assert decrypted == secret 
開發者ID:theherk,項目名稱:figgypy,代碼行數:10,代碼來源:util_test.py

示例7: __init__

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def __init__(self, uuid):
        self._uuid = copy(BLEUUID.BASE_UUID_BYTES)

        if isinstance(uuid, UUID):
            # Assume that the UUID is correct
            self._uuid = bytearray(uuid.bytes)
        elif isinstance(uuid, bytes):
            self._uuid[2:4] = bytearray(bytes_to_native_str(uuid))
        elif isinstance(uuid, str):
            if len(uuid) == 4:
                # 16-bit UUID
                part = int(uuid, 16).to_bytes(2, 'little')
                self._uuid[2:4] = bytearray(part)
            elif len(uuid) == 8:
                # 32-bit UUID
                part = int(uuid, 16).to_bytes(4, 'little')
                self._uuid[0:4] = bytearray(part)
            elif len(uuid) == 36:
                # 128-bit UUID
                self._uuid = bytearray(UUID(uuid).bytes)
            else:
                raise ValueError("Invalid UUID")
        elif isinstance(uuid, int):
            if uuid < 65536:
                # 16-bit UUID
                part = int(uuid).to_bytes(2, 'little')
                self._uuid[2:4] = bytearray(part)
            elif uuid < 2**32:
                # 32-bit UUID
                part = int(uuid).to_bytes(4, 'little')
                self._uuid[0:4] = bytearray(part)
            else:
                raise ValueError("Invalid UUID")
        else:
            raise ValueError("Invalid UUID (type error)") 
開發者ID:matthewelse,項目名稱:bleep,代碼行數:37,代碼來源:util.py

示例8: _write_handle

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import bytes_to_native_str [as 別名]
def _write_handle(self, handle, data, response=True):
        if response:
            return self.requester.write_by_handle(handle, bytes_to_native_str(data))
        else:
            return self.requester.write_without_response_by_handle(handle, bytes_to_native_str(data)) 
開發者ID:matthewelse,項目名稱:bleep,代碼行數:7,代碼來源:device.py


注:本文中的future.utils.bytes_to_native_str方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。