diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 14:55:16 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 14:55:16 -0800 |
commit | b53654b6dbfce8318a7d4d1cdaddca7a7fec194b (patch) | |
tree | 204df61b2fb23424603db767732db35a687529c6 /Lib/encodings/__init__.py | |
parent | e1ac7d87afad9c07ec25e5705bb135b71347b581 (diff) | |
parent | 2296b978597ce62ec2185b78a43811610af2c0ea (diff) | |
download | cpython-b53654b6dbfce8318a7d4d1cdaddca7a7fec194b.tar.gz |
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
Diffstat (limited to 'Lib/encodings/__init__.py')
-rw-r--r-- | Lib/encodings/__init__.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index 8dd713056e..aa2fb7c2b9 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -29,6 +29,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). """#" import codecs +import sys from . import aliases _cache = {} @@ -54,6 +55,7 @@ def normalize_encoding(encoding): """ if isinstance(encoding, bytes): encoding = str(encoding, "ascii") + chars = [] punct = False for c in encoding: @@ -97,6 +99,8 @@ def search_function(encoding): mod = __import__('encodings.' + modname, fromlist=_import_tail, level=0) except ImportError: + # ImportError may occur because 'encodings.(modname)' does not exist, + # or because it imports a name that does not exist (see mbcs and oem) pass else: break @@ -150,3 +154,16 @@ def search_function(encoding): # Register the search_function in the Python codec registry codecs.register(search_function) + +if sys.platform == 'win32': + def _alias_mbcs(encoding): + 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) |