Commit 71202199 authored by Victor Stinner's avatar Victor Stinner

_pyio: Fix TextIOWrapper constructor: os has no device_encoding() function

_io module doesn't call this function which was introduced in Python3.
parent 268e4872
...@@ -1438,17 +1438,12 @@ class TextIOWrapper(TextIOBase): ...@@ -1438,17 +1438,12 @@ class TextIOWrapper(TextIOBase):
raise ValueError("illegal newline value: %r" % (newline,)) raise ValueError("illegal newline value: %r" % (newline,))
if encoding is None: if encoding is None:
try: try:
encoding = os.device_encoding(buffer.fileno()) import locale
except (AttributeError, UnsupportedOperation): except ImportError:
pass # Importing locale may fail if Python is being built
if encoding is None: encoding = "ascii"
try: else:
import locale encoding = locale.getpreferredencoding()
except ImportError:
# Importing locale may fail if Python is being built
encoding = "ascii"
else:
encoding = locale.getpreferredencoding()
if not isinstance(encoding, basestring): if not isinstance(encoding, basestring):
raise ValueError("invalid encoding: %r" % encoding) raise ValueError("invalid encoding: %r" % encoding)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment