summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-04-09 00:54:54 (GMT)
committerGitHub <noreply@github.com>2022-04-09 00:54:54 (GMT)
commit677320348728ce058fa3579017e985af74a236d4 (patch)
tree944297b71196964eab27a3336918c5a8f1e6a17d /Modules
parentcd29bd13ef1fe18970c5d43b66c545dd03117cb9 (diff)
downloadcpython-677320348728ce058fa3579017e985af74a236d4.zip
cpython-677320348728ce058fa3579017e985af74a236d4.tar.gz
cpython-677320348728ce058fa3579017e985af74a236d4.tar.bz2
bpo-47000: Add `locale.getencoding()` (GH-32068)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/textio.c8
-rw-r--r--Modules/_localemodule.c8
-rw-r--r--Modules/clinic/_localemodule.c.h16
3 files changed, 19 insertions, 13 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index d9d1c88..0e20741 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1145,7 +1145,13 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
}
if (encoding == NULL && self->encoding == NULL) {
- self->encoding = _Py_GetLocaleEncodingObject();
+ if (_PyRuntime.preconfig.utf8_mode) {
+ _Py_DECLARE_STR(utf_8, "utf-8");
+ self->encoding = Py_NewRef(&_Py_STR(utf_8));
+ }
+ else {
+ self->encoding = _Py_GetLocaleEncodingObject();
+ }
if (self->encoding == NULL) {
goto error;
}
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 564f559..23c38e1 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -773,14 +773,14 @@ _locale_bind_textdomain_codeset_impl(PyObject *module, const char *domain,
/*[clinic input]
-_locale._get_locale_encoding
+_locale.getencoding
Get the current locale encoding.
[clinic start generated code]*/
static PyObject *
-_locale__get_locale_encoding_impl(PyObject *module)
-/*[clinic end generated code: output=e8e2f6f6f184591a input=513d9961d2f45c76]*/
+_locale_getencoding_impl(PyObject *module)
+/*[clinic end generated code: output=86b326b971872e46 input=6503d11e5958b360]*/
{
return _Py_GetLocaleEncodingObject();
}
@@ -811,7 +811,7 @@ static struct PyMethodDef PyLocale_Methods[] = {
_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#endif
#endif
- _LOCALE__GET_LOCALE_ENCODING_METHODDEF
+ _LOCALE_GETENCODING_METHODDEF
{NULL, NULL}
};
diff --git a/Modules/clinic/_localemodule.c.h b/Modules/clinic/_localemodule.c.h
index 703d034..2958127 100644
--- a/Modules/clinic/_localemodule.c.h
+++ b/Modules/clinic/_localemodule.c.h
@@ -545,22 +545,22 @@ exit:
#endif /* defined(HAVE_LIBINTL_H) && defined(HAVE_BIND_TEXTDOMAIN_CODESET) */
-PyDoc_STRVAR(_locale__get_locale_encoding__doc__,
-"_get_locale_encoding($module, /)\n"
+PyDoc_STRVAR(_locale_getencoding__doc__,
+"getencoding($module, /)\n"
"--\n"
"\n"
"Get the current locale encoding.");
-#define _LOCALE__GET_LOCALE_ENCODING_METHODDEF \
- {"_get_locale_encoding", (PyCFunction)_locale__get_locale_encoding, METH_NOARGS, _locale__get_locale_encoding__doc__},
+#define _LOCALE_GETENCODING_METHODDEF \
+ {"getencoding", (PyCFunction)_locale_getencoding, METH_NOARGS, _locale_getencoding__doc__},
static PyObject *
-_locale__get_locale_encoding_impl(PyObject *module);
+_locale_getencoding_impl(PyObject *module);
static PyObject *
-_locale__get_locale_encoding(PyObject *module, PyObject *Py_UNUSED(ignored))
+_locale_getencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return _locale__get_locale_encoding_impl(module);
+ return _locale_getencoding_impl(module);
}
#ifndef _LOCALE_STRCOLL_METHODDEF
@@ -602,4 +602,4 @@ _locale__get_locale_encoding(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#endif /* !defined(_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF) */
-/*[clinic end generated code: output=cd703c8a3a75fcf4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ea71e9b94bdaa47d input=a9049054013a1b77]*/