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

Function token_urlsafe

Lib/secrets.py:60–71  ·  view source on GitHub ↗

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'

(nbytes=None)

Source from the content-addressed store, hash-verified

58 return token_bytes(nbytes).hex()
59
60def token_urlsafe(nbytes=None):
61 """Return a random URL-safe text string, in Base64 encoding.
62
63 The string has *nbytes* random bytes. If *nbytes* is ``None``
64 or not supplied, a reasonable default is used.
65
66 >>> token_urlsafe(16) #doctest:+SKIP
67 'Drmhze6EPcv0fN_81Bj-nA'
68
69 """
70 tok = token_bytes(nbytes)
71 return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii')

Callers

nothing calls this directly

Calls 3

token_bytesFunction · 0.85
decodeMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…