From d78d3b4541e4549ef014325f965639ffbe962ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 11 Aug 2007 15:36:45 +0000 Subject: Fall back to ascii if the locale module cannot be loaded. --- Lib/io.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/io.py b/Lib/io.py index 4ee7cef..b24a21c 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 -- cgit v0.12