| 1 |
"""Platform-specific fallback for importing `md5`. |
| 2 |
|
| 3 |
It ensures compatibility on systems where the `hashlib` module is unavailable |
| 4 |
by attempting to use the `_md5` module as a fallback, except on macOS (darwin) |
| 5 |
and Windows (win32), where such fallback is not supported. |
| 6 |
""" |
| 7 |
|
| 8 |
from sys import platform |
| 9 |
|
| 10 |
if platform not in ("darwin", "win32"): |
| 11 |
try: |
| 12 |
import _md5 |
| 13 |
except ImportError: |
| 14 |
_md5 = None |
| 15 |
try: |
| 16 |
from hashlib import md5 |
| 17 |
except ImportError as exception: |
| 18 |
if platform not in ("darwin", "win32") and _md5: |
| 19 |
md5 = _md5 |
| 20 |
else: |
| 21 |
raise exception |