]> granicus.if.org Git - python/commitdiff
bpo-25172: Raise appropriate ImportError msg when crypt module used on Windows (GH...
authorshireenrao <shireenrao@gmail.com>
Thu, 8 Aug 2019 20:02:49 +0000 (16:02 -0400)
committerPaul Moore <p.f.moore@gmail.com>
Thu, 8 Aug 2019 20:02:49 +0000 (21:02 +0100)
Lib/crypt.py
Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst [new file with mode: 0644]

index b0e47f430c3cbc7a72c4ebfce30aed27967aa28b..8846602d7613ec76c365021ab500252a3f0546e9 100644 (file)
@@ -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 (file)
index 0000000..47106d8
--- /dev/null
@@ -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.