From: Martin v. Löwis Date: Sat, 11 Aug 2007 15:36:45 +0000 (+0000) Subject: Fall back to ascii if the locale module cannot be loaded. X-Git-Tag: v3.0a1~447 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d78d3b4541e4549ef014325f965639ffbe962ea9;p=thirdparty%2FPython%2Fcpython.git Fall back to ascii if the locale module cannot be loaded. --- diff --git a/Lib/io.py b/Lib/io.py index 4ee7cef7198e..b24a21cf1d40 100644 --- a/Lib/io.py +++ b/Lib/io.py @@ -976,8 +976,13 @@ class TextIOWrapper(TextIOBase): except AttributeError: pass if encoding is None: - import locale - encoding = locale.getpreferredencoding() + try: + import locale + except ImportError: + # Importing locale may fail if Python is being built + encoding = "ascii" + else: + encoding = locale.getpreferredencoding() self.buffer = buffer self._encoding = encoding