Python hashlib 模块,algorithms_guaranteed() 实例源码

我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用hashlib.algorithms_guaranteed()

项目:proxenos    作者:darvid    | 项目源码 | 文件源码
def hashex(method,    # type: HashMethod
           key,       # type: KeyType
           **options  # type: typing.Any
           ):
    # type: (...) -> int
    if isinstance(key, six.text_type):
        key = key.encode('utf-8')
    if method.name.lower() in hashlib.algorithms_guaranteed:
        return int(hashlib.new(method.name.lower(), key).hexdigest(), 16)
    elif method == HashMethod.MMH3_32:
        return hash_murmur3(key, size=32, **options)
    elif method == HashMethod.MMH3_64:
        return hash_murmur3(key, size=64, **options)
    elif method == HashMethod.MMH3_128:
        return hash_murmur3(key, size=128, **options)
    elif method == HashMethod.SIPHASH:
        return hash_siphash(key, **options)
项目:proxenos    作者:darvid    | 项目源码 | 文件源码
def test_hashex_hashlib():
    for algorithm in hashlib.algorithms_guaranteed:
        method = getattr(proxenos.rendezvous.HashMethod, algorithm.upper())
        assert (proxenos.rendezvous.hashex(method, 'secret') ==
                int(hashlib.new(algorithm, b'secret').hexdigest(), 16))
项目:rehash    作者:kislyuk    | 项目源码 | 文件源码
def test_basic_statements(self):
        for algorithm in hashlib.algorithms_guaranteed:
            if algorithm.startswith("blake2") or algorithm.startswith("sha3") or algorithm.startswith("shake"):
                with self.assertRaises(Exception):
                    rehash.ResumableHasher(algorithm.lower())
            else:
                print(algorithm)
                self.assert_resumable(rehash.new(algorithm.lower()))
                self.assert_resumable(rehash.new(algorithm.lower(), b"initial_data"))
                self.assert_resumable(rehash.ResumableHasher(algorithm.lower()))
                self.assert_resumable(rehash.ResumableHasher(algorithm.lower(), b"initial_data"))
                self.assert_resumable(getattr(rehash, algorithm)())
                self.assert_resumable(getattr(rehash, algorithm)(b"initial_data"))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:deb-python-proliantutils    作者:openstack    | 项目源码 | 文件源码
def _get_hash_object(hash_algo_name):
    """Create a hash object based on given algorithm.

    :param hash_algo_name: name of the hashing algorithm.
    :raises: InvalidInputError, on unsupported or invalid input.
    :returns: a hash object based on the given named algorithm.
    """
    algorithms = (hashlib.algorithms_guaranteed if six.PY3
                  else hashlib.algorithms)
    if hash_algo_name not in algorithms:
        msg = ("Unsupported/Invalid hash name '%s' provided."
               % hash_algo_name)
        raise exception.InvalidInputError(msg)

    return getattr(hashlib, hash_algo_name)()
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:ricedb    作者:TheReverend403    | 项目源码 | 文件源码
def hash(self, mask, target, args):
        """Hash text.

            %%hash (--md5 | --sha1 | --sha256 | --sha512) <string>...
        """
        available_algorithms = hashlib.algorithms_guaranteed
        text = ' '.join(args['<string>']).encode('UTF-8')
        for algo in available_algorithms:
            flag = '--{0}'.format(algo)
            if flag in args and args[flag]:
                hash_object = hashlib.new(algo)
                hash_object.update(text)
                return '{0}: {1}'.format(mask.nick, hash_object.hexdigest())
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_algorithms_guaranteed(self):
        self.assertEqual(hashlib.algorithms_guaranteed,
            set(_algo for _algo in self.supported_hash_names
                  if _algo.islower()))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_algorithms_available(self):
        self.assertTrue(set(hashlib.algorithms_guaranteed).
                            issubset(hashlib.algorithms_available))