mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 06:18:08 -05:00
randstr: Allow specifying valid chars directly
Removes the "really_random" argument from the randstr util function, and replaces it with an argument that allows specifying the character choices instead of just having the two options available.
This commit is contained in:
@@ -54,16 +54,10 @@ from r2.lib.utils._utils import *
|
||||
|
||||
iters = (list, tuple, set)
|
||||
|
||||
def randstr(len, reallyrandom = False):
|
||||
"""If reallyrandom = False, generates a random alphanumeric string
|
||||
(base-36 compatible) of length len. If reallyrandom, add
|
||||
uppercase and punctuation (which we'll call 'base-93' for the sake
|
||||
of argument) and suitable for use as salt."""
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
if reallyrandom:
|
||||
alphabet += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&\()*+,-./:;<=>?@[\\]^_{|}~'
|
||||
return ''.join(random.choice(alphabet)
|
||||
for i in range(len))
|
||||
def randstr(length,
|
||||
alphabet='abcdefghijklmnopqrstuvwxyz0123456789'):
|
||||
"""Return a string made up of random chars from alphabet."""
|
||||
return ''.join(random.choice(alphabet) for _ in xrange(length))
|
||||
|
||||
class Storage(dict):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user