You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
421 B

5 years ago
  1. # -*- coding: utf-8 -*-
  2. from random import SystemRandom
  3. def random_token(length, byte_filter):
  4. allowed_bytes = ''.join(c for c in map(chr, range(128)) if byte_filter(c))
  5. random = SystemRandom()
  6. return ''.join([random.choice(allowed_bytes) for _ in range(length)])
  7. def alpha_numeric(length):
  8. return random_token(length, str.isalnum)
  9. def lower_case(length):
  10. return random_token(length, str.islower)