diff cutils/util/__init__.py @ 365:d5c920ace3cb

treesum: FIX: Python<2.7.9 has no hashlib.algorithms_available: fall back to hashlib.algorithms in this case
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 09 Apr 2025 22:14:49 +0200
parents 48430941c18c
children bfe1160fbfd3
line wrap: on
line diff
--- a/cutils/util/__init__.py	Fri Apr 04 19:14:20 2025 +0200
+++ b/cutils/util/__init__.py	Wed Apr 09 22:14:49 2025 +0200
@@ -83,9 +83,17 @@
     Does not consider :mod:`pyblake2` if it is available eventually.
 
     """
-    if "blake2b" in hashlib.algorithms_available:
+    # Python <2.7.9 has no algorithms_available: fall back to algorithms
+    try:
+        algos = hashlib.algorithms_available
+    except AttributeError:
+        try:
+            algos = hashlib.algorithms
+        except AttributeError:
+            algos = []
+    if "blake2b" in algos:
         return "BLAKE2b-256"
-    if "sha256" in hashlib.algorithms_available:
+    if "sha256" in algos:
         return "SHA256"
     return "SHA1"