summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-13 21:27:14 (GMT)
committerGitHub <noreply@github.com>2019-08-13 21:27:14 (GMT)
commit7f7f74734acd729d1f82b7cf672e064c9525fced (patch)
tree8c1067956a88bf7ea3867b441af17792f56d0302
parent6ad902a08814909b4d52c4000d5a10ce58516dac (diff)
downloadcpython-7f7f74734acd729d1f82b7cf672e064c9525fced.zip
cpython-7f7f74734acd729d1f82b7cf672e064c9525fced.tar.gz
cpython-7f7f74734acd729d1f82b7cf672e064c9525fced.tar.bz2
bpo-25172: Raise appropriate ImportError msg when crypt module used on Windows (GH-15149)
(cherry picked from commit f4e725f224b864bf9bf405ff7f863cda46fca1cd) Co-authored-by: shireenrao <shireenrao@gmail.com>
-rw-r--r--Lib/crypt.py11
-rw-r--r--Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst1
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/crypt.py b/Lib/crypt.py
index b0e47f4..8846602 100644
--- a/Lib/crypt.py
+++ b/Lib/crypt.py
@@ -1,6 +1,15 @@
"""Wrapper to the POSIX crypt library call and associated functionality."""
-import _crypt
+import sys as _sys
+
+try:
+ import _crypt
+except ModuleNotFoundError:
+ if _sys.platform == 'win32':
+ raise ImportError("The crypt module is not supported on Windows")
+ else:
+ raise ImportError("The required _crypt module was not built as part of CPython")
+
import string as _string
from random import SystemRandom as _SystemRandom
from collections import namedtuple as _namedtuple
diff --git a/Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst b/Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst
new file mode 100644
index 0000000..47106d8
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst
@@ -0,0 +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.