사실, _sha 모듈이 shamodule.c 및 _md5에 의해 제공됩니다 md5module.c 및 md5.c에 의해 제공되며 파이썬 컴파일되지 않은 경우 모두에만 건설 될 예정 기본적으로 OpenSSL을 사용합니다.
파이썬 소스 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 옵션을 사용하여 빌드하고 가져올 수 있습니다. 파이썬 소스 타르볼에서
:
./configure --with-pydebug
make
그리고 거기 당신은 간다 : 그래서
>>> import _sha
[38571 refs]
>>> _sha.__file__
'/home/senthil/python/release27-maint/build/lib.linux-i686-2.7-pydebug/_sha.so'
[38573 refs]
, 내가 hashlib 외부에서 해당 모듈 형태의 가져 오기를 할 수있는 방법이? – FernandoEscher
예,'_hashlib'을 가져옵니다 (밑줄을 참고하십시오). '_sha'는'_hashlib'가 설치되어 있지 않은 레거시 인터페이스 인 것 같습니다. 호기심에서 왜 그것을 수입하고 싶습니까? – albertov
나는 호기심 XD이었다. 그러나 지금 나는 그것이 어떻게 작동하는지 알아 낸다! 도와 주셔서 감사합니다! : P – FernandoEscher