summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-04-22 01:39:24 (GMT)
committerGitHub <noreply@github.com>2022-04-22 01:39:24 (GMT)
commit1317b70f89606bd14597116b7ab68a968ea6c017 (patch)
tree84cefd08afe31ffeb3f7a1f7ad1c9d2688abb168 /Doc
parentefe7fd4170bb809ed46cac35c6a9007d5b794e7e (diff)
downloadcpython-1317b70f89606bd14597116b7ab68a968ea6c017.zip
cpython-1317b70f89606bd14597116b7ab68a968ea6c017.tar.gz
cpython-1317b70f89606bd14597116b7ab68a968ea6c017.tar.bz2
gh-91156: Use `locale.getencoding()` instead of getpreferredencoding (GH-91732)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/curses.rst3
-rw-r--r--Doc/library/csv.rst2
-rw-r--r--Doc/library/curses.rst18
-rw-r--r--Doc/library/functions.rst11
-rw-r--r--Doc/library/os.rst6
5 files changed, 12 insertions, 28 deletions
diff --git a/Doc/howto/curses.rst b/Doc/howto/curses.rst
index c0149ff..26c4ece 100644
--- a/Doc/howto/curses.rst
+++ b/Doc/howto/curses.rst
@@ -299,8 +299,7 @@ The :meth:`~curses.window.addstr` method takes a Python string or
bytestring as the value to be displayed. The contents of bytestrings
are sent to the terminal as-is. Strings are encoded to bytes using
the value of the window's :attr:`encoding` attribute; this defaults to
-the default system encoding as returned by
-:func:`locale.getpreferredencoding`.
+the default system encoding as returned by :func:`locale.getencoding`.
The :meth:`~curses.window.addch` methods take a character, which can be
either a string of length 1, a bytestring of length 1, or an integer.
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 3a7817c..9dec724 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -542,7 +542,7 @@ The corresponding simplest possible writing example is::
Since :func:`open` is used to open a CSV file for reading, the file
will by default be decoded into unicode using the system default
-encoding (see :func:`locale.getpreferredencoding`). To decode a file
+encoding (see :func:`locale.getencoding`). To decode a file
using a different encoding, use the ``encoding`` argument of open::
import csv
diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst
index 37e822c..a7cc495 100644
--- a/Doc/library/curses.rst
+++ b/Doc/library/curses.rst
@@ -27,20 +27,6 @@ Linux and the BSD variants of Unix.
Whenever the documentation mentions a *character string* it can be specified
as a Unicode string or a byte string.
-.. note::
-
- Since version 5.4, the ncurses library decides how to interpret non-ASCII data
- using the ``nl_langinfo`` function. That means that you have to call
- :func:`locale.setlocale` in the application and encode Unicode strings
- using one of the system's available encodings. This example uses the
- system's default encoding::
-
- import locale
- locale.setlocale(locale.LC_ALL, '')
- code = locale.getpreferredencoding()
-
- Then use *code* as the encoding for :meth:`str.encode` calls.
-
.. seealso::
Module :mod:`curses.ascii`
@@ -923,8 +909,8 @@ the following methods and attributes:
Encoding used to encode method arguments (Unicode strings and characters).
The encoding attribute is inherited from the parent window when a subwindow
- is created, for example with :meth:`window.subwin`. By default, the locale
- encoding is used (see :func:`locale.getpreferredencoding`).
+ is created, for example with :meth:`window.subwin`.
+ By default, current locale encoding is used (see :func:`locale.getencoding`).
.. versionadded:: 3.3
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index e6fd0bb..f3b8e40 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1123,8 +1123,8 @@ are always available. They are listed here in alphabetical order.
(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:
- ``locale.getpreferredencoding(False)`` is called to get the current locale
- encoding. (For reading and writing raw bytes use binary mode and leave
+ :func:`locale.getencoding()` 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:
.. _filemodes:
@@ -1183,10 +1183,9 @@ are always available. They are listed here in alphabetical order.
*encoding* is the name of the encoding used to decode or encode the file.
This should only be used in text mode. The default encoding is platform
- dependent (whatever :func:`locale.getpreferredencoding` returns), but any
- :term:`text encoding` supported by Python
- can be used. See the :mod:`codecs` module for
- the list of supported encodings.
+ dependent (whatever :func:`locale.getencoding` returns), but any
+ :term:`text encoding` supported by Python can be used.
+ See the :mod:`codecs` module for the list of supported encodings.
*errors* is an optional string that specifies how encoding and decoding
errors are to be handled—this cannot be used in binary mode.
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index c22bf56..471890e 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -105,15 +105,15 @@ of the UTF-8 encoding:
* Use UTF-8 as the :term:`filesystem encoding <filesystem encoding and error
handler>`.
-* :func:`sys.getfilesystemencoding()` returns ``'UTF-8'``.
-* :func:`locale.getpreferredencoding()` returns ``'UTF-8'`` (the *do_setlocale*
+* :func:`sys.getfilesystemencoding()` returns ``'utf-8'``.
+* :func:`locale.getpreferredencoding()` returns ``'utf-8'`` (the *do_setlocale*
argument has no effect).
* :data:`sys.stdin`, :data:`sys.stdout`, and :data:`sys.stderr` all use
UTF-8 as their text encoding, with the ``surrogateescape``
:ref:`error handler <error-handlers>` being enabled for :data:`sys.stdin`
and :data:`sys.stdout` (:data:`sys.stderr` continues to use
``backslashreplace`` as it does in the default locale-aware mode)
-* On Unix, :func:`os.device_encoding` returns ``'UTF-8'`` rather than the
+* On Unix, :func:`os.device_encoding` returns ``'utf-8'`` rather than the
device encoding.
Note that the standard stream settings in UTF-8 mode can be overridden by