本文整理汇总了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)
示例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()
示例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']))
示例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)
示例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)
示例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
示例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)")
示例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))