mirror of https://github.com/python/cpython
gh-99305: Speed up secrets.token_hex() ~2x (#99306)
simple code modernization. Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
This commit is contained in:
parent
f531b6879b
commit
55c96e8053
|
@ -13,7 +13,6 @@ __all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom',
|
|||
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
|
||||
from hmac import compare_digest
|
||||
from random import SystemRandom
|
||||
|
@ -56,7 +55,7 @@ def token_hex(nbytes=None):
|
|||
'f9bf78b9a18ce6d46a0cd2b0b86df9da'
|
||||
|
||||
"""
|
||||
return binascii.hexlify(token_bytes(nbytes)).decode('ascii')
|
||||
return token_bytes(nbytes).hex()
|
||||
|
||||
def token_urlsafe(nbytes=None):
|
||||
"""Return a random URL-safe text string, in Base64 encoding.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Improve performance of :func:`secrets.token_hex`.
|
Loading…
Reference in New Issue