Skip to content

Commit f4e725f

Browse files
shireenraopfmoore
authored andcommitted
bpo-25172: Raise appropriate ImportError msg when crypt module used on Windows (GH-15149)
1 parent 2a570af commit f4e725f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Lib/crypt.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
"""Wrapper to the POSIX crypt library call and associated functionality."""
22

3-
import _crypt
3+
import sys as _sys
4+
5+
try:
6+
import _crypt
7+
except ModuleNotFoundError:
8+
if _sys.platform == 'win32':
9+
raise ImportError("The crypt module is not supported on Windows")
10+
else:
11+
raise ImportError("The required _crypt module was not built as part of CPython")
12+
413
import string as _string
514
from random import SystemRandom as _SystemRandom
615
from collections import namedtuple as _namedtuple
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Trying to import the :mod:`crypt` module on Windows will result in an :exc:`ImportError` with a message explaining that the module isn't supported on Windows. On other platforms, if the underlying ``_crypt`` module is not available, the ImportError will include a message explaining the problem.

0 commit comments

Comments
 (0)