summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-11 14:02:14 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-08-11 14:02:14 (GMT)
commitd1cd4d41762ba55bfa121875fbcbde19fb6a35f1 (patch)
treeefc776f69cdf44259a96e12ada8ea14dbe9e0362 /Lib
parent79c320898d43eaafa28c1c67a105a17cb9b233bf (diff)
downloadcpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.zip
cpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.tar.gz
cpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.tar.bz2
Set sys.stdout.encoding properly.
Always set LC_CTYPE on interpreter startup. Add device_encoding function.
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 1ee465a..4ee7cef 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -971,8 +971,13 @@ class TextIOWrapper(TextIOBase):
if newline not in (None, "\n", "\r\n"):
raise ValueError("illegal newline value: %r" % (newline,))
if encoding is None:
- # XXX This is questionable
- encoding = sys.getfilesystemencoding() or "latin-1"
+ try:
+ encoding = os.device_encoding(buffer.fileno())
+ except AttributeError:
+ pass
+ if encoding is None:
+ import locale
+ encoding = locale.getpreferredencoding()
self.buffer = buffer
self._encoding = encoding