实际上,sha模块是由shamodule.c提供的,_md5是由md5module.c和md5.c提供的,只有在Python默认不是用OpenSSL编译的情况下才会构建这两个模块。在
您可以在Python源代码tarball的setup.py中找到详细信息。在if COMPILED_WITH_PYDEBUG or not have_usable_openssl:
# The _sha module implements the SHA1 hash algorithm.
exts.append( Extension('_sha', ['shamodule.c']) )
# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321. The
# necessary files md5.c and md5.h are included here.
exts.append( Extension('_md5',
sources = ['md5module.c', 'md5.c'],
depends = ['md5.h']) )
通常,Python是用Openssl库构建的,在这种情况下,这些函数是由Openssl库本身提供的。在
现在,如果您想单独使用它们,那么您可以不使用OpenSSL构建Python,或者更好,可以使用pydebug选项构建并拥有它们。在
从Python源代码tarball:
^{pr2}$
你就这样:>>> import _sha
[38571 refs]
>>> _sha.__file__
'/home/senthil/python/release27-maint/build/lib.linux-i686-2.7-pydebug/_sha.so'
[38573 refs]