MCPcopy Index your code
hub / github.com/python/cpython / _hashlib_new

Function _hashlib_new

Lib/test/support/hashlib_helper.py:597–617  ·  view source on GitHub ↗

Check availability of [hashlib|_hashlib].new(digestname, **kwargs). If *openssl* is True, module is "_hashlib" (C extension module), otherwise it is "hashlib" (pure Python interface). The constructor function is returned (without binding **kwargs), or SkipTest is raised if none exi

(digestname, openssl, /, **kwargs)

Source from the content-addressed store, hash-verified

595
596
597def _hashlib_new(digestname, openssl, /, **kwargs):
598 """Check availability of [hashlib|_hashlib].new(digestname, **kwargs).
599
600 If *openssl* is True, module is "_hashlib" (C extension module),
601 otherwise it is "hashlib" (pure Python interface).
602
603 The constructor function is returned (without binding **kwargs),
604 or SkipTest is raised if none exists.
605 """
606 assert isinstance(digestname, str), digestname
607 # Re-import 'hashlib' in case it was mocked, but propagate
608 # exceptions as it should be unconditionally available.
609 hashlib = importlib.import_module("hashlib")
610 # re-import '_hashlib' in case it was mocked
611 _hashlib = _import_module("_hashlib")
612 module = _hashlib if openssl and _hashlib is not None else hashlib
613 try:
614 module.new(digestname, **kwargs)
615 except ValueError as exc:
616 raise SkipNoHashInCall(f"{module.__name__}.new", digestname) from exc
617 return functools.partial(module.new, digestname)
618
619
620def _builtin_hash(module_name, digestname, /, **kwargs):

Callers

nothing calls this directly

Calls 6

_import_moduleFunction · 0.85
SkipNoHashInCallClass · 0.85
partialMethod · 0.80
wrappedFunction · 0.50
import_moduleMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…