Commit fe8f4c9e authored by Steve Dower's avatar Steve Dower

Issue #27959: Prevent ImportError from escaping codec search function

parent 2f8bfef1
...@@ -155,9 +155,13 @@ codecs.register(search_function) ...@@ -155,9 +155,13 @@ codecs.register(search_function)
if sys.platform == 'win32': if sys.platform == 'win32':
def _alias_mbcs(encoding): def _alias_mbcs(encoding):
import _bootlocale try:
if encoding == _bootlocale.getpreferredencoding(False): import _bootlocale
import encodings.mbcs if encoding == _bootlocale.getpreferredencoding(False):
return encodings.mbcs.getregentry() import encodings.mbcs
return encodings.mbcs.getregentry()
except ImportError:
# Imports may fail while we are shutting down
pass
codecs.register(_alias_mbcs) codecs.register(_alias_mbcs)
...@@ -3230,8 +3230,7 @@ def _to_memoryview(buf): ...@@ -3230,8 +3230,7 @@ def _to_memoryview(buf):
class CTextIOWrapperTest(TextIOWrapperTest): class CTextIOWrapperTest(TextIOWrapperTest):
io = io io = io
shutdown_error = ("ImportError: sys.meta_path is None" shutdown_error = "RuntimeError: could not find io module state"
if os.name == "nt" else "RuntimeError: could not find io module state")
def test_initialization(self): def test_initialization(self):
r = self.BytesIO(b"\xc3\xa9\n\n") r = self.BytesIO(b"\xc3\xa9\n\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment