make 'generate_token()' compatible with Python 3.4
This commit is contained in:
parent
1fdecfa269
commit
91308140ec
@ -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):
|
||||||
|
@ -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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user