(original) (raw)

changeset: 103229:47b4dbd451f5 user: Steve Dower steve.dower@microsoft.com date: Wed Sep 07 09:31:52 2016 -0700 files: Lib/encodings/__init__.py Lib/test/test_io.py description: Issue #27959: Prevent ImportError from escaping codec search function diff -r f6412378821c -r 47b4dbd451f5 Lib/encodings/__init__.py --- a/Lib/encodings/__init__.py Wed Sep 07 09:26:18 2016 -0700 +++ b/Lib/encodings/__init__.py Wed Sep 07 09:31:52 2016 -0700 @@ -155,9 +155,13 @@ if sys.platform == 'win32': def _alias_mbcs(encoding): - import _bootlocale - if encoding == _bootlocale.getpreferredencoding(False): - import encodings.mbcs - return encodings.mbcs.getregentry() + try: + import _bootlocale + if encoding == _bootlocale.getpreferredencoding(False): + import encodings.mbcs + return encodings.mbcs.getregentry() + except ImportError: + # Imports may fail while we are shutting down + pass codecs.register(_alias_mbcs) diff -r f6412378821c -r 47b4dbd451f5 Lib/test/test_io.py --- a/Lib/test/test_io.py Wed Sep 07 09:26:18 2016 -0700 +++ b/Lib/test/test_io.py Wed Sep 07 09:31:52 2016 -0700 @@ -3230,8 +3230,7 @@ class CTextIOWrapperTest(TextIOWrapperTest): io = io - shutdown_error = ("ImportError: sys.meta_path is None" - if os.name == "nt" else "RuntimeError: could not find io module state") + shutdown_error = "RuntimeError: could not find io module state" def test_initialization(self): r = self.BytesIO(b"\xc3\xa9\n\n") /steve.dower@microsoft.com