mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Close #11022: TextIOWrapper doesn't call locale.setlocale() anymore
open() and io.TextIOWrapper are now calling locale.getpreferredencoding(False) instead of locale.getpreferredencoding() in text mode if the encoding is not specified. Don't change temporary the locale encoding using locale.setlocale(), use the current locale encoding instead of the user preferred encoding. Explain also in open() documentation that locale.getpreferredencoding(False) is called if the encoding is not specified.
This commit is contained in:
parent
91c5a34613
commit
f86a5e8a93
8 changed files with 84 additions and 29 deletions
|
@ -1448,7 +1448,7 @@ class TextIOWrapper(TextIOBase):
|
|||
r"""Character and line based layer over a BufferedIOBase object, buffer.
|
||||
|
||||
encoding gives the name of the encoding that the stream will be
|
||||
decoded or encoded with. It defaults to locale.getpreferredencoding.
|
||||
decoded or encoded with. It defaults to locale.getpreferredencoding(False).
|
||||
|
||||
errors determines the strictness of encoding and decoding (see the
|
||||
codecs.register) and defaults to "strict".
|
||||
|
@ -1487,7 +1487,7 @@ class TextIOWrapper(TextIOBase):
|
|||
# Importing locale may fail if Python is being built
|
||||
encoding = "ascii"
|
||||
else:
|
||||
encoding = locale.getpreferredencoding()
|
||||
encoding = locale.getpreferredencoding(False)
|
||||
|
||||
if not isinstance(encoding, str):
|
||||
raise ValueError("invalid encoding: %r" % encoding)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue