utils.py 文件源码

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

项目:pywsse 作者: PrincetonUniversity 项目源码 文件源码
def _get_digest_algorithm(name = None):
    '''
    Get the digest algorithm to use based on the settings.

    :param name: name of algorithm to use
    :type name: str

    :return: digest algorithm
    :rtype: class
    '''
    if name:
        possible_algorithms = [name.lower()]
    else:
        possible_algorithms = filter(lambda a: a in hashlib.algorithms_available,
            (map(str.lower, settings.ALLOWED_DIGEST_ALGORITHMS)))

    for algo_name in possible_algorithms:
        if hasattr(hashlib, algo_name):
            return getattr(hashlib, algo_name)

    logger.error('No algorithm from %r found in hashlib %r',
        settings.ALLOWED_DIGEST_ALGORITHMS, hashlib.algorithms_available)
    raise exceptions.AlgorithmNotSupported('No suitable algorithm found.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号