[pypy-svn] r61414 - pypy/trunk/pypy/lib

afa at codespeak.net afa at codespeak.net
Wed Jan 28 00:23:10 CET 2009


Author: afa
Date: Wed Jan 28 00:23:07 2009
New Revision: 61414

Modified:
   pypy/trunk/pypy/lib/_hashlib.py
   pypy/trunk/pypy/lib/hashlib.py
Log:
- Ensure that "import _hashlib" raises ImportError when OpenSSL cannot be found.
- Fix hashlib to expose our builtin implementations in this case.

This should fix the "import urllib" failures on the win32 buildbot.


Modified: pypy/trunk/pypy/lib/_hashlib.py
==============================================================================
--- pypy/trunk/pypy/lib/_hashlib.py	(original)
+++ pypy/trunk/pypy/lib/_hashlib.py	Wed Jan 28 00:23:07 2009
@@ -4,6 +4,8 @@
 
 # Note: OpenSSL on OS X only provides md5 and sha1
 libpath = ctypes.util.find_library('ssl')
+if not libpath:
+    raise ImportError('could not find OpenSSL library')
 lib = CDLL(libpath) # Linux, OS X
 lib.EVP_get_digestbyname.restype = c_void_p
 lib.EVP_DigestInit.argtypes = [c_void_p, c_void_p]

Modified: pypy/trunk/pypy/lib/hashlib.py
==============================================================================
--- pypy/trunk/pypy/lib/hashlib.py	(original)
+++ pypy/trunk/pypy/lib/hashlib.py	Wed Jan 28 00:23:07 2009
@@ -50,8 +50,10 @@
     'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
 
 """
-import _hashlib
-
+try:
+    import _hashlib
+except ImportError:
+    _hashlib = None
 
 def __get_builtin_constructor(name):
     if name in ('SHA1', 'sha1'):
@@ -73,13 +75,16 @@
     optionally initialized with a string.
     """
     try:
-        return _hashlib.new(name, string)
+        if _hashlib:
+            return _hashlib.new(name, string)
     except ValueError:
         # If the _hashlib module (OpenSSL) doesn't support the named
         # hash, try using our builtin implementations.
         # This allows for SHA224/256 and SHA384/512 support even though
         # the OpenSSL library prior to 0.9.8 doesn't provide them.
-        return __get_builtin_constructor(name)(string)
+        pass
+
+    return __get_builtin_constructor(name)(string)
 
 new = __hash_new
 
@@ -105,4 +110,13 @@
                 # this one has no builtin implementation, don't define it
                 pass
 
-_setfuncs()
+if _hashlib:
+    _setfuncs()
+else:
+    # lookup the C function to use directly for the named constructors
+    md5 = __get_builtin_constructor('md5')
+    sha1 = __get_builtin_constructor('sha1')
+    sha224 = __get_builtin_constructor('sha224')
+    sha256 = __get_builtin_constructor('sha256')
+    #sha384 = __get_builtin_constructor('sha384')
+    #sha512 = __get_builtin_constructor('sha512')



More information about the Pypy-commit mailing list