From 56611ca490a35c5c7225163d6aaacc2d7c9fb310 Mon Sep 17 00:00:00 2001 From: Srinivas Date: Tue, 6 Aug 2019 13:45:50 -0400 Subject: [PATCH 1/5] Raise appropriate ImportError msg when crypt used on Windows --- Lib/crypt.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/crypt.py b/Lib/crypt.py index b0e47f430c3cbc..a7d35c3a5ea2e5 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 From f8a78cffb2a59d91b0d0e14eef391b32a2c4185c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 6 Aug 2019 18:09:20 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst 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 00000000000000..c4d6ca46d2e339 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst @@ -0,0 +1 @@ +The crypt module is not supported on Windows. If anybody tries to use it by importing the module, they will see an ImportError with a message saying its not supported on Windows. One will also see an appropriate error message on any other platform if the crypt module is not found or built. \ No newline at end of file From ecf99c8d862bdd6ba613340b13c7244364b140b4 Mon Sep 17 00:00:00 2001 From: shireenrao Date: Tue, 6 Aug 2019 14:49:56 -0400 Subject: [PATCH 3/5] Update blurb based on review --- .../next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c4d6ca46d2e339..c48b893df3b083 100644 --- 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 @@ -1 +1 @@ -The crypt module is not supported on Windows. If anybody tries to use it by importing the module, they will see an ImportError with a message saying its not supported on Windows. One will also see an appropriate error message on any other platform if the crypt module is not found or built. \ No newline at end of file +Trying to import the crypt module on Windows will result in an 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. From 4b3881e4aa301219eb5062b18925a47d34b91459 Mon Sep 17 00:00:00 2001 From: Srinivas Date: Tue, 6 Aug 2019 15:18:10 -0400 Subject: [PATCH 4/5] Remove whitespace causing CI failures --- Lib/crypt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/crypt.py b/Lib/crypt.py index a7d35c3a5ea2e5..8846602d7613ec 100644 --- a/Lib/crypt.py +++ b/Lib/crypt.py @@ -9,7 +9,7 @@ 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 From 808cf390778d11b95c54fc63a62c0c15045129af Mon Sep 17 00:00:00 2001 From: shireenrao Date: Tue, 6 Aug 2019 16:08:35 -0400 Subject: [PATCH 5/5] Update Misc/NEWS.d/next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst Co-Authored-By: Steve Dower --- .../next/Windows/2019-08-06-18-09-18.bpo-25172.Akreij.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c48b893df3b083..47106d8879217f 100644 --- 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 @@ -1 +1 @@ -Trying to import the crypt module on Windows will result in an 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. +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.