def randstr(length=32):
    """
    Generates a random string of the given length. Defaults to 32 characters.

    """

    if not isinstance(length, int):
        raise ValueError

    if length < 1:
        return ''

    invalid_chars_re = re.compile(r'[\'"\\]*')

    chars = string.digits + string.letters + string.punctuation
    chars = ''.join(invalid_chars_re.split(chars))

    return ''.join(random.choice(chars) for _ in range(length))
dataset/ETHPy150Open tooxie/shiva-server/shiva/utils.py/randstr/original