diff --git a/Lib/_pyio.py b/Lib/_pyio.py index ec1b20d0426768..ed97263a7d65f7 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -2095,10 +2095,14 @@ 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.getencoding(). - - errors determines the strictness of encoding and decoding (see the - codecs.register) and defaults to "strict". + decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is + disabled, the encoding returned by locale.getencoding() is used + instead. See the codecs module for the list of supported + encodings. + + errors determines the strictness of encoding and decoding (see + help(codecs.Codec) or the documentation for codecs.register) and + defaults to "strict". newline can be None, '', '\n', '\r', or '\r\n'. It controls the handling of line endings. If it is None, universal newlines is diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 03e6fbe08889d4..0d28fe24fa0b3a 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -94,10 +94,7 @@ mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for creating and writing to a new file, 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: 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: +The available modes are: ========= ========================================================== Character Meaning @@ -122,8 +119,7 @@ even when the underlying operating system doesn't. Files opened in binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are -returned as strings, the bytes having been first decoded using a -platform-dependent encoding or using the specified encoding if given. +decoded using the encoding described below and returned as strings. buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to @@ -140,10 +136,11 @@ argument is given, the default buffering policy works as follows: use line buffering. Other text files use the policy described above for binary files. -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, but any encoding supported by Python can be -passed. See the codecs module for the list of supported encodings. +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 UTF-8; +if UTF-8 Mode is disabled, the encoding returned by +locale.getencoding() is used instead. See the codecs module for the +list of supported encodings. errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass @@ -200,7 +197,7 @@ static PyObject * _io_open_impl(PyObject *module, PyObject *file, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd, PyObject *opener) -/*[clinic end generated code: output=aefafc4ce2b46dc0 input=b3cefa70bef404b3]*/ +/*[clinic end generated code: output=aefafc4ce2b46dc0 input=5a005681afa02242]*/ { size_t i; diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index 0547982cad48cc..462597078b77d9 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -28,10 +28,7 @@ PyDoc_STRVAR(_io_open__doc__, "it already exists), \'x\' for creating and writing to a new file, and\n" "\'a\' for appending (which on some Unix systems, means that all writes\n" "append to the end of the file regardless of the current seek position).\n" -"In text mode, if encoding is not specified the encoding used is platform\n" -"dependent: locale.getencoding() is called to get the current locale\n" -"encoding. (For reading and writing raw bytes use binary mode and leave\n" -"encoding unspecified.) The available modes are:\n" +"The available modes are:\n" "\n" "========= ==========================================================\n" "Character Meaning\n" @@ -56,8 +53,7 @@ PyDoc_STRVAR(_io_open__doc__, "binary mode (appending \'b\' to the mode argument) return contents as\n" "bytes objects without any decoding. In text mode (the default, or when\n" "\'t\' is appended to the mode argument), the contents of the file are\n" -"returned as strings, the bytes having been first decoded using a\n" -"platform-dependent encoding or using the specified encoding if given.\n" +"decoded using the encoding described below and returned as strings.\n" "\n" "buffering is an optional integer used to set the buffering policy.\n" "Pass 0 to switch buffering off (only allowed in binary mode), 1 to\n" @@ -74,10 +70,11 @@ PyDoc_STRVAR(_io_open__doc__, " use line buffering. Other text files use the policy described above\n" " for binary files.\n" "\n" -"encoding is the name of the encoding used to decode or encode the\n" -"file. This should only be used in text mode. The default encoding is\n" -"platform dependent, but any encoding supported by Python can be\n" -"passed. See the codecs module for the list of supported encodings.\n" +"encoding is the name of the encoding used to decode or encode the file.\n" +"This should only be used in text mode. The default encoding is UTF-8;\n" +"if UTF-8 Mode is disabled, the encoding returned by\n" +"locale.getencoding() is used instead. See the codecs module for the\n" +"list of supported encodings.\n" "\n" "errors is an optional string that specifies how encoding errors are to\n" "be handled---this argument should not be used in binary mode. Pass\n" @@ -392,4 +389,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=4570f4466d711d60 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=517d977e17d38fce input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 51e75d05061799..a63c2d953e8a25 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -441,7 +441,10 @@ PyDoc_STRVAR(_io_TextIOWrapper___init____doc__, "Character and line based layer over a BufferedIOBase object, buffer.\n" "\n" "encoding gives the name of the encoding that the stream will be\n" -"decoded or encoded with. It defaults to locale.getencoding().\n" +"decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is\n" +"disabled, the encoding returned by locale.getencoding() is used\n" +"instead. See the codecs module for the list of supported\n" +"encodings.\n" "\n" "errors determines the strictness of encoding and decoding (see\n" "help(codecs.Codec) or the documentation for codecs.register) and\n" @@ -1261,4 +1264,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=f3dd3fff36cd2142 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9c9a0b205b58bdc0 input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 967392313bea20..a8605d21879bc2 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1150,7 +1150,10 @@ _io.TextIOWrapper.__init__ 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.getencoding(). +decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is +disabled, the encoding returned by locale.getencoding() is used +instead. See the codecs module for the list of supported +encodings. errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and @@ -1182,7 +1185,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, const char *encoding, PyObject *errors, const char *newline, int line_buffering, int write_through) -/*[clinic end generated code: output=72267c0c01032ed2 input=0f077220214c40a4]*/ +/*[clinic end generated code: output=72267c0c01032ed2 input=4f0bee5a0b2302fd]*/ { PyObject *raw, *codec_info = NULL; PyObject *res;