checksum.py: handle pycrypto breakage
authorZac Medico <zmedico@gentoo.org>
Sun, 13 Nov 2011 20:33:43 +0000 (12:33 -0800)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 Nov 2011 20:33:43 +0000 (12:33 -0800)
pym/portage/checksum.py

index 8e5abfff219a9aa57d46c93cdc18d7ca26b43ea3..f10fc4d55a05e99c33370e73ef373b6179257b48 100644 (file)
@@ -99,10 +99,18 @@ except ImportError:
        pass
 
 # Use pycrypto when available, prefer it over the internal fallbacks
+# Check for 'new' attributes, since they can be missing if the module
+# is broken somehow.
 try:
        from Crypto.Hash import SHA256, RIPEMD
-       sha256hash = _generate_hash_function("SHA256", SHA256.new, origin="pycrypto")
-       rmd160hash = _generate_hash_function("RMD160", RIPEMD.new, origin="pycrypto")
+       sha256hash = getattr(SHA256, 'new', None)
+       if sha256hash is not None:
+               sha256hash = _generate_hash_function("SHA256",
+                       sha256hash, origin="pycrypto")
+       rmd160hash = getattr(RIPEMD, 'new', None)
+       if rmd160hash is not None:
+               rmd160hash = _generate_hash_function("RMD160",
+                       rmd160hash, origin="pycrypto")
 except ImportError:
        pass