]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fall back to ascii if the locale module cannot be loaded.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 11 Aug 2007 15:36:45 +0000 (15:36 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 11 Aug 2007 15:36:45 +0000 (15:36 +0000)
Lib/io.py

index 4ee7cef7198eb960839e60cb11774bcec5f4ec0d..b24a21cf1d409c5145f9cf0fa1cd0cca422a2d5e 100644 (file)
--- 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