MCPcopy Index your code
hub / github.com/python/cpython / token_bytes

Function token_bytes

Lib/secrets.py:33–45  ·  view source on GitHub ↗

Return a random byte string containing *nbytes* bytes. If *nbytes* is ``None`` or not supplied, a reasonable default is used. >>> token_bytes(16) #doctest:+SKIP b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'

(nbytes=None)

Source from the content-addressed store, hash-verified

31DEFAULT_ENTROPY = 32 # number of bytes to return by default
32
33def token_bytes(nbytes=None):
34 """Return a random byte string containing *nbytes* bytes.
35
36 If *nbytes* is ``None`` or not supplied, a reasonable
37 default is used.
38
39 >>> token_bytes(16) #doctest:+SKIP
40 b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'
41
42 """
43 if nbytes is None:
44 nbytes = DEFAULT_ENTROPY
45 return _sysrand.randbytes(nbytes)
46
47def token_hex(nbytes=None):
48 """Return a random text string, in hexadecimal.

Callers 2

token_hexFunction · 0.85
token_urlsafeFunction · 0.85

Calls 1

randbytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…