diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/_iomodule.c | 8 | ||||
-rw-r--r-- | Modules/_io/clinic/_iomodule.c.h | 8 | ||||
-rw-r--r-- | Modules/_io/clinic/textio.c.h | 4 | ||||
-rw-r--r-- | Modules/_io/textio.c | 18 |
4 files changed, 23 insertions, 15 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 065f5e2..38ef246 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -92,9 +92,9 @@ 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.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: +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: ========= =============================================================== Character Meaning @@ -196,7 +196,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=1543f4511d2356a5]*/ +/*[clinic end generated code: output=aefafc4ce2b46dc0 input=5bb37f174cb2fb11]*/ { unsigned i; diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index e4a6b8c..1fdbe68 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -22,9 +22,9 @@ PyDoc_STRVAR(_io_open__doc__, "\'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.getpreferredencoding(False) is called to get the\n" -"current locale encoding. (For reading and writing raw bytes use binary\n" -"mode and leave encoding unspecified.) The available modes are:\n" +"dependent: locale.getencoding() is called to get the current locale encoding.\n" +"(For reading and writing raw bytes use binary mode and leave encoding\n" +"unspecified.) The available modes are:\n" "\n" "========= ===============================================================\n" "Character Meaning\n" @@ -355,4 +355,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=1a7fd7755c9a9609 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e562f29e3c2533a6 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 0b047ac..7e81eb3 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -146,7 +146,7 @@ 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.getpreferredencoding(False).\n" +"decoded or encoded with. It defaults to locale.getencoding().\n" "\n" "errors determines the strictness of encoding and decoding (see\n" "help(codecs.Codec) or the documentation for codecs.register) and\n" @@ -671,4 +671,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=2604c8f3a45b9a03 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e88abad34e31c0cb input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 0e20741..6ba7393 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1023,7 +1023,7 @@ _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.getpreferredencoding(False). +decoded or encoded with. It defaults to locale.getencoding(). errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and @@ -1055,12 +1055,12 @@ _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=77d8696d1a1f460b]*/ +/*[clinic end generated code: output=72267c0c01032ed2 input=72590963698f289b]*/ { PyObject *raw, *codec_info = NULL; - _PyIO_State *state = NULL; PyObject *res; int r; + int use_locale_encoding = 0; // Use locale encoding even in UTF-8 mode. self->ok = 0; self->detached = 0; @@ -1076,6 +1076,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } else if (strcmp(encoding, "locale") == 0) { encoding = NULL; + use_locale_encoding = 1; } if (errors == Py_None) { @@ -1113,10 +1114,15 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, self->encodefunc = NULL; self->b2cratio = 0.0; +#ifdef MS_WINDOWS + // os.device_encoding() on Unix is the locale encoding or UTF-8 + // according to UTF-8 Mode. + // Since UTF-8 mode shouldn't affect `encoding="locale"`, we call + // os.device_encoding() only on Windows. if (encoding == NULL) { /* Try os.device_encoding(fileno) */ PyObject *fileno; - state = IO_STATE(); + _PyIO_State *state = IO_STATE(); if (state == NULL) goto error; fileno = PyObject_CallMethodNoArgs(buffer, &_Py_ID(fileno)); @@ -1144,8 +1150,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, Py_CLEAR(self->encoding); } } +#endif + if (encoding == NULL && self->encoding == NULL) { - if (_PyRuntime.preconfig.utf8_mode) { + if (_PyRuntime.preconfig.utf8_mode && !use_locale_encoding) { _Py_DECLARE_STR(utf_8, "utf-8"); self->encoding = Py_NewRef(&_Py_STR(utf_8)); } |