mirror of https://github.com/python/cpython
gh-91952: Make TextIOWrapper.reconfigure() supports "locale" encoding (GH-91982)
This commit is contained in:
parent
b9636180b3
commit
0729b31a8b
|
@ -1038,6 +1038,9 @@ Text I/O
|
|||
|
||||
.. versionadded:: 3.7
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
The method supports ``encoding="locale"`` option.
|
||||
|
||||
|
||||
.. class:: StringIO(initial_value='', newline='\\n')
|
||||
|
||||
|
|
|
@ -2161,6 +2161,8 @@ class TextIOWrapper(TextIOBase):
|
|||
else:
|
||||
if not isinstance(encoding, str):
|
||||
raise TypeError("invalid encoding: %r" % encoding)
|
||||
if encoding == "locale":
|
||||
encoding = locale.getencoding()
|
||||
|
||||
if newline is Ellipsis:
|
||||
newline = self._readnl
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Add ``encoding="locale"`` support to :meth:`TextIOWrapper.reconfigure`.
|
|
@ -1248,8 +1248,16 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
|
|||
errors = self->errors;
|
||||
}
|
||||
}
|
||||
else if (errors == Py_None) {
|
||||
errors = &_Py_ID(strict);
|
||||
else {
|
||||
if (_PyUnicode_EqualToASCIIString(encoding, "locale")) {
|
||||
encoding = _Py_GetLocaleEncodingObject();
|
||||
if (encoding == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (errors == Py_None) {
|
||||
errors = &_Py_ID(strict);
|
||||
}
|
||||
}
|
||||
|
||||
const char *c_errors = PyUnicode_AsUTF8(errors);
|
||||
|
|
Loading…
Reference in New Issue