mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
_pyio: Fix TextIOWrapper constructor: os has no device_encoding() function
_io module doesn't call this function which was introduced in Python3.
This commit is contained in:
parent
268e4872d3
commit
7120219918
1 changed files with 6 additions and 11 deletions
17
Lib/_pyio.py
17
Lib/_pyio.py
|
@ -1438,17 +1438,12 @@ class TextIOWrapper(TextIOBase):
|
|||
raise ValueError("illegal newline value: %r" % (newline,))
|
||||
if encoding is None:
|
||||
try:
|
||||
encoding = os.device_encoding(buffer.fileno())
|
||||
except (AttributeError, UnsupportedOperation):
|
||||
pass
|
||||
if encoding is None:
|
||||
try:
|
||||
import locale
|
||||
except ImportError:
|
||||
# Importing locale may fail if Python is being built
|
||||
encoding = "ascii"
|
||||
else:
|
||||
encoding = locale.getpreferredencoding()
|
||||
import locale
|
||||
except ImportError:
|
||||
# Importing locale may fail if Python is being built
|
||||
encoding = "ascii"
|
||||
else:
|
||||
encoding = locale.getpreferredencoding()
|
||||
|
||||
if not isinstance(encoding, basestring):
|
||||
raise ValueError("invalid encoding: %r" % encoding)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue