This action will force synchronization from OpenHarmony-SIG/python, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
"""Generate cryptographically strong pseudo-random numbers suitable formanaging secrets such as account authentication, tokens, and similar.See PEP 506 for more information.https://www.python.org/dev/peps/pep-0506/"""__all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom','token_bytes', 'token_hex', 'token_urlsafe','compare_digest',]import base64import binasciiimport osfrom hmac import compare_digestfrom random import SystemRandom_sysrand = SystemRandom()randbits = _sysrand.getrandbitschoice = _sysrand.choicedef randbelow(exclusive_upper_bound):"""Return a random int in the range [0, n)."""if exclusive_upper_bound <= 0:raise ValueError("Upper bound must be positive.")return _sysrand._randbelow(exclusive_upper_bound)DEFAULT_ENTROPY = 32 # number of bytes to return by defaultdef token_bytes(nbytes=None):"""Return a random byte string containing *nbytes* bytes.If *nbytes* is ``None`` or not supplied, a reasonabledefault is used.>>> token_bytes(16) #doctest:+SKIPb'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'"""if nbytes is None:nbytes = DEFAULT_ENTROPYreturn os.urandom(nbytes)def token_hex(nbytes=None):"""Return a random text string, in hexadecimal.The string has *nbytes* random bytes, each byte converted to twohex digits. If *nbytes* is ``None`` or not supplied, a reasonabledefault is used.>>> token_hex(16) #doctest:+SKIP'f9bf78b9a18ce6d46a0cd2b0b86df9da'"""return binascii.hexlify(token_bytes(nbytes)).decode('ascii')def token_urlsafe(nbytes=None):"""Return a random URL-safe text string, in Base64 encoding.The string has *nbytes* random bytes. If *nbytes* is ``None``or not supplied, a reasonable default is used.>>> token_urlsafe(16) #doctest:+SKIP'Drmhze6EPcv0fN_81Bj-nA'"""tok = token_bytes(nbytes)return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。