make 'generate_token()' compatible with Python 3.4

This commit is contained in:
Mike Fährmann 2021-01-14 03:40:08 +01:00
parent 1fdecfa269
commit 91308140ec
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 3 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import shutil
import string import string
import _string import _string
import sqlite3 import sqlite3
import binascii
import datetime import datetime
import operator import operator
import itertools import itertools
@ -73,7 +74,8 @@ def raises(cls):
def generate_token(size=16): def generate_token(size=16):
"""Generate a random token with hexadecimal digits""" """Generate a random token with hexadecimal digits"""
return random.getrandbits(size * 8).to_bytes(size, "big").hex() data = random.getrandbits(size * 8).to_bytes(size, "big")
return binascii.hexlify(data).decode()
def combine_dict(a, b): def combine_dict(a, b):

View File

@ -474,7 +474,6 @@ class TestOther(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
func(3) func(3)
@unittest.skipIf(sys.hexversion < 0x3050000, "missing bytes.hex()")
def test_generate_token(self): def test_generate_token(self):
tokens = set() tokens = set()
for _ in range(100): for _ in range(100):