8000 gh-91952: Make TextIOWrapper.reconfigure() supports "locale" encoding by methane · Pull Request #91982 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-91952: Make TextIOWrapper.reconfigure() supports "locale" encoding #91982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TextIOWrapper.reconfigure() supports "locale" encoding.
  • Loading branch information
methane committed Apr 27, 2022
commit 64c514277840191fd139f9b2df31f0f4b5cbf289
2 changes: 2 additions & 0 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,8 @@ def reconfigure(self, *,
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
Expand Down
12 changes: 10 additions & 2 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
0