Simplify rand_byte by creating a special case for Python 2

This commit is contained in:
Shadab Zafar 2016-06-02 13:34:18 +05:30
parent c4da7e026c
commit 75ce2498e8
1 changed files with 5 additions and 1 deletions

View File

@ -2,6 +2,8 @@ import string
import random
import mmap
import six
DATATYPES = dict(
ascii_letters=string.ascii_letters.encode(),
ascii_lowercase=string.ascii_lowercase.encode(),
@ -47,7 +49,9 @@ def rand_byte(chars):
"""
# bytearray has consistent behaviour on both Python 2 and 3
# while bytes does not
return bytes(bytearray([random.choice(chars)]))
if six.PY2:
return random.choice(chars)
return bytes([random.choice(chars)])
class RandomGenerator(object):