diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-08-11 15:36:45 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-08-11 15:36:45 (GMT) |
commit | d78d3b4541e4549ef014325f965639ffbe962ea9 (patch) | |
tree | 986ec64bba7146ecfbfc078fc4c45a0e755ca18e | |
parent | 10f07c41e60d2323c3dc1f69be14b5a30b7400c6 (diff) | |
download | cpython-d78d3b4541e4549ef014325f965639ffbe962ea9.zip cpython-d78d3b4541e4549ef014325f965639ffbe962ea9.tar.gz cpython-d78d3b4541e4549ef014325f965639ffbe962ea9.tar.bz2 |
Fall back to ascii if the locale module cannot be loaded.
-rw-r--r-- | Lib/io.py | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 |