utils.py 文件源码

python
阅读 51 收藏 0 点赞 0 评论 0

项目:pywsse 作者: PrincetonUniversity 项目源码 文件源码
def _random_string(length = None, allowed_chars = None):
    '''
    Generate a random string of the given length.

    :param length: length of the string (defaults to settings.NONCE_LENGTH)
    :rtype length: int

    :param allowed_chars: characters to allow in string
    :rtype allowed_chars: str

    :return: generated string
    :rtype: str
    '''
    if allowed_chars is None:
        try:
            allowed_chars = string.letters
        except AttributeError:
            allowed_chars = string.ascii_letters

    if length is None:
        length = settings.NONCE_LENGTH

    s = ''.join(random.choice(allowed_chars) for _ in range(length))
    return s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号