MCPcopy Create free account
hub / github.com/doraemonext/wechat-python-sdk / to_binary

Function to_binary

wechat_sdk/utils.py:24–39  ·  view source on GitHub ↗

将 values 转为 bytes,默认编码 utf-8 :param value: 待转换的值 :param encoding: 编码

(value, encoding='utf-8')

Source from the content-addressed store, hash-verified

22
23
24def to_binary(value, encoding='utf-8'):
25 """将 values 转为 bytes,默认编码 utf-8
26
27 :param value: 待转换的值
28 :param encoding: 编码
29 """
30 if not value:
31 return b''
32 if isinstance(value, six.binary_type):
33 return value
34 if isinstance(value, six.text_type):
35 return value.encode(encoding)
36
37 if six.PY3:
38 return six.binary_type(str(value), encoding) # For Python 3
39 return six.binary_type(value)
40
41
42def disable_urllib3_warning():

Callers 10

get_random_strMethod · 0.90
__str__Method · 0.90
__str__Method · 0.90
get_sha1_signatureFunction · 0.90
encryptMethod · 0.90
__init__Method · 0.90
_encrypt_messageMethod · 0.90
_decrypt_messageMethod · 0.90
encodeMethod · 0.90
_encrypt_responseMethod · 0.85

Calls 1

encodeMethod · 0.45

Tested by 1

get_random_strMethod · 0.72