summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-11 15:36:45 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-08-11 15:36:45 (GMT)
commitd78d3b4541e4549ef014325f965639ffbe962ea9 (patch)
tree986ec64bba7146ecfbfc078fc4c45a0e755ca18e /Lib
parent10f07c41e60d2323c3dc1f69be14b5a30b7400c6 (diff)
downloadcpython-d78d3b4541e4549ef014325f965639ffbe962ea9.zip
cpython-d78d3b4541e4549ef014325f965639ffbe962ea9.tar.gz
cpython-d78d3b4541e4549ef014325f965639ffbe962ea9.tar.bz2
Fall back to ascii if the locale module cannot be loaded.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/io.py9
1 files 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