# HG changeset patch # User Franz Glasner # Date 1650493489 -7200 # Node ID f69353f269374688bd5a694ba7922122cc41acc2 # Parent b46673c428949fe06d073963426c48f78fd4468e Support for using the pyblake2 package if native support for BLAKE2 is not available in hashlib. This is to support BLAKE2 on Python2 and pre-Python 3.6. diff -r b46673c42894 -r f69353f26937 cutils/shasum.py --- a/cutils/shasum.py Thu Apr 21 00:09:17 2022 +0200 +++ b/cutils/shasum.py Thu Apr 21 00:24:49 2022 +0200 @@ -382,19 +382,37 @@ def get_blake2b(): """Get the factory for blake2b""" - return hashlib.blake2b + try: + return hashlib.blake2b + except AttributeError: + import pyblake2 + return pyblake2.blake2b def get_blake2s(): """Get the factory for blake2s""" - return hashlib.blake2s + try: + return hashlib.blake2s + except AttributeError: + import pyblake2 + return pyblake2.blake2s def get_blake2_256(): """Get the factory for blake2-256""" - def _get_blake(): - return hashlib.blake2b(digest_size=32) + try: + hashlib.blake2b + except AttributeError: + import pyblake2 + + def _get_blake(): + return pyblake2.blake2b(digest_size=32) + + else: + + def _get_blake(): + return hashlib.blake2b(digest_size=32) return _get_blake