diff options
author | NewUserHa <32261870+NewUserHa@users.noreply.github.com> | 2022-11-11 22:45:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 22:45:24 (GMT) |
commit | 55c96e8053689c29ae28a9d2117ae37934eace68 (patch) | |
tree | e3c4b63e257d9eb31db654666d2a296657609cda /Lib/secrets.py | |
parent | f531b6879b530515b009ac79767702829848cf07 (diff) | |
download | cpython-55c96e8053689c29ae28a9d2117ae37934eace68.zip cpython-55c96e8053689c29ae28a9d2117ae37934eace68.tar.gz cpython-55c96e8053689c29ae28a9d2117ae37934eace68.tar.bz2 |
gh-99305: Speed up secrets.token_hex() ~2x (#99306)
simple code modernization.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Diffstat (limited to 'Lib/secrets.py')
-rw-r--r-- | Lib/secrets.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Lib/secrets.py b/Lib/secrets.py index 900381a..566a09b 100644 --- a/Lib/secrets.py +++ b/Lib/secrets.py @@ -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. |