mirror of
https://github.com/python/cpython
synced 2026-09-29 08:45:29 +03: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
|
|
@ -800,9 +800,10 @@ are always available. They are listed here in alphabetical order.
|
|||
already exists), ``'x'`` for exclusive creation and ``'a'`` for appending
|
||||
(which on *some* Unix systems, means that *all* writes append to the end of
|
||||
the file regardless of the current seek position). In text mode, if
|
||||
*encoding* is not specified the encoding used is platform dependent. (For
|
||||
reading and writing raw bytes use binary mode and leave *encoding*
|
||||
unspecified.) The available modes are:
|
||||
*encoding* is not specified the encoding used is platform dependent:
|
||||
``locale.getpreferredencoding(False)`` is called to get the current locale
|
||||
encoding. (For reading and writing raw bytes use binary mode and leave
|
||||
*encoding* unspecified.) The available modes are:
|
||||
|
||||
========= ===============================================================
|
||||
Character Meaning
|
||||
|
|
|
|||
|
|
@ -752,7 +752,7 @@ Text I/O
|
|||
It inherits :class:`TextIOBase`.
|
||||
|
||||
*encoding* gives the name of the encoding that the stream will be decoded or
|
||||
encoded with. It defaults to :func:`locale.getpreferredencoding`.
|
||||
encoded with. It defaults to ``locale.getpreferredencoding(False)``.
|
||||
|
||||
*errors* is an optional string that specifies how encoding and decoding
|
||||
errors are to be handled. Pass ``'strict'`` to raise a :exc:`ValueError`
|
||||
|
|
@ -784,6 +784,12 @@ Text I/O
|
|||
.. versionchanged:: 3.3
|
||||
The *write_through* argument has been added.
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
The default *encoding* is now ``locale.getpreferredencoding(False)``
|
||||
instead of ``locale.getpreferredencoding()``. Don't change temporary the
|
||||
locale encoding using :func:`locale.setlocale`, use the current locale
|
||||
encoding instead of the user preferred encoding.
|
||||
|
||||
:class:`TextIOWrapper` provides one attribute in addition to those of
|
||||
:class:`TextIOBase` and its parents:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue