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)
| 595 | |
| 596 | |
| 597 | def _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 | |
| 620 | def _builtin_hash(module_name, digestname, /, **kwargs): |
nothing calls this directly
no test coverage detected
searching dependent graphs…