mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Begin incorporating Python unit tests into build
We now build a separate APE binary for each test so they can run in parallel. We've got 148 tests running fast and stable so far.
This commit is contained in:
parent
51904e2687
commit
b5f743cdc3
121 changed files with 4995 additions and 4767 deletions
71
third_party/python/Lib/hashlib.py
vendored
71
third_party/python/Lib/hashlib.py
vendored
|
@ -11,7 +11,10 @@ new(name, data=b'', **kwargs) - returns a new hash object implementing the
|
|||
Named constructor functions are also available, these are faster
|
||||
than using new(name):
|
||||
|
||||
md5(), sha1(), sha224(), sha256(), sha384(), sha512(), and blake2b256().
|
||||
md5(), sha1(), sha224(), sha256(), sha384(), sha512(), sha3_224(),
|
||||
sha3_256(), sha3_384(), sha3_512(), shake_128(), shake_256(), and
|
||||
finally blake2b256() which is an Actually Portable Python feature
|
||||
courtesy of the BoringSSL project at Google, and we thank ARM too
|
||||
|
||||
More algorithms may be available on your platform but the above are guaranteed
|
||||
to exist. See the algorithms_guaranteed and algorithms_available attributes
|
||||
|
@ -52,10 +55,22 @@ More condensed:
|
|||
|
||||
"""
|
||||
|
||||
# import _hashlib as _prevent_recursive_loading
|
||||
# del _prevent_recursive_loading
|
||||
# if __name__ == 'PYOBJ.COM': import _sha3, _hashlib # static-only
|
||||
|
||||
if __name__ == 'PYOBJ.COM':
|
||||
import _md5
|
||||
import _sha1
|
||||
import _sha256
|
||||
import _sha512
|
||||
|
||||
# This tuple and __get_builtin_constructor() must be modified if a new
|
||||
# always available algorithm is added.
|
||||
__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
|
||||
'blake2b256')
|
||||
# 'sha3_224', 'sha3_256', 'sha3_384',
|
||||
# 'sha3_512', 'shake_128', 'shake_256'
|
||||
)
|
||||
|
||||
algorithms_guaranteed = set(__always_supported)
|
||||
algorithms_available = set(__always_supported)
|
||||
|
@ -70,12 +85,23 @@ def __get_builtin_constructor(name):
|
|||
constructor = cache.get(name)
|
||||
if constructor is not None:
|
||||
return constructor
|
||||
if name in ('MD5', 'md5'):
|
||||
import _md5
|
||||
cache['MD5'] = cache['md5'] = _md5.md5
|
||||
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
|
||||
'shake_128', 'shake_256'}:
|
||||
try:
|
||||
try:
|
||||
if name in ('SHA1', 'sha1'):
|
||||
import _sha1
|
||||
cache['SHA1'] = cache['sha1'] = _sha1.sha1
|
||||
elif name in ('MD5', 'md5'):
|
||||
import _md5
|
||||
cache['MD5'] = cache['md5'] = _md5.md5
|
||||
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
|
||||
import _sha256
|
||||
cache['SHA224'] = cache['sha224'] = _sha256.sha224
|
||||
cache['SHA256'] = cache['sha256'] = _sha256.sha256
|
||||
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
|
||||
import _sha512
|
||||
cache['SHA384'] = cache['sha384'] = _sha512.sha384
|
||||
cache['SHA512'] = cache['sha512'] = _sha512.sha512
|
||||
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
|
||||
'shake_128', 'shake_256'}:
|
||||
import _sha3
|
||||
cache['sha3_224'] = _sha3.sha3_224
|
||||
cache['sha3_256'] = _sha3.sha3_256
|
||||
|
@ -83,11 +109,13 @@ def __get_builtin_constructor(name):
|
|||
cache['sha3_512'] = _sha3.sha3_512
|
||||
cache['shake_128'] = _sha3.shake_128
|
||||
cache['shake_256'] = _sha3.shake_256
|
||||
except ImportError:
|
||||
raise ValueError('unsupported hash type ' + name)
|
||||
except ImportError:
|
||||
pass # no extension module, this hash is unsupported.
|
||||
|
||||
constructor = cache.get(name)
|
||||
if constructor is not None:
|
||||
return constructor
|
||||
|
||||
raise ValueError('unsupported hash type ' + name)
|
||||
|
||||
|
||||
|
@ -125,11 +153,15 @@ def __hash_new(name, data=b'', **kwargs):
|
|||
return __get_builtin_constructor(name)(data)
|
||||
|
||||
|
||||
import _hashlib
|
||||
new = __hash_new
|
||||
__get_hash = __get_mbedtls_constructor
|
||||
algorithms_available = algorithms_available.union(
|
||||
_hashlib.mbedtls_md_meth_names)
|
||||
try:
|
||||
import _hashlib
|
||||
new = __hash_new
|
||||
__get_hash = __get_mbedtls_constructor
|
||||
algorithms_available = algorithms_available.union(
|
||||
_hashlib.mbedtls_md_meth_names)
|
||||
except ImportError as e:
|
||||
new = __py_new
|
||||
__get_hash = __get_builtin_constructor
|
||||
|
||||
try:
|
||||
# Mbedtls's PKCS5_PBKDF2_HMAC requires Mbedtls 1.0+ with HMAC and SHA
|
||||
|
@ -201,13 +233,20 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
md5 = __get_hash('md5')
|
||||
sha1 = __get_hash('sha1')
|
||||
sha224 = __get_hash('sha224')
|
||||
sha256 = __get_hash('sha256')
|
||||
sha384 = __get_hash('sha384')
|
||||
sha512 = __get_hash('sha512')
|
||||
blake2b256 = __get_hash('blake2b256')
|
||||
# sha3_224 = __get_hash('sha3_224')
|
||||
# sha3_256 = __get_hash('sha3_256')
|
||||
# sha3_384 = __get_hash('sha3_384')
|
||||
# sha3_512 = __get_hash('sha3_512')
|
||||
# shake_128 = __get_hash('shake_128')
|
||||
# shake_256 = __get_hash('shake_256')
|
||||
|
||||
|
||||
# Cleanup locals()
|
||||
del __always_supported, __get_hash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue