diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-09-05 17:09:48 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-09-05 17:09:48 (GMT) |
commit | 7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf (patch) | |
tree | ed1541d4f1e8ed463f1bfbee97bd9793d62d2ae5 /Modules/_localemodule.c | |
parent | 044d95e9f7e0c9d5840c623350df339526f037af (diff) | |
download | cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.zip cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.tar.gz cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.tar.bz2 |
Patch #449815: Set filesystemencoding based on CODESET.
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r-- | Modules/_localemodule.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 7f7bdd2..a3a1d12 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -153,7 +153,10 @@ fixup_ulcase(void) PyDict_SetItemString(string, "letters", ulo); Py_DECREF(ulo); } - + +#if defined(HAVE_LANGINFO_H) && defined(CODESET) +static int fileencoding_uses_locale = 0; +#endif static PyObject* PyLocale_setlocale(PyObject* self, PyObject* args) @@ -203,6 +206,22 @@ PyLocale_setlocale(PyObject* self, PyObject* args) fixup_ulcase(); /* things that got wrong up to here are ignored */ PyErr_Clear(); +#if defined(HAVE_LANGINFO_H) && defined(CODESET) + if (Py_FileSystemDefaultEncoding == NULL) + fileencoding_uses_locale = 1; + if (fileencoding_uses_locale) { + char *codeset = nl_langinfo(CODESET); + PyObject *enc = NULL; + if (*codeset && (enc = PyCodec_Encoder(codeset))) { + /* Release previous file encoding */ + if (Py_FileSystemDefaultEncoding) + free (Py_FileSystemDefaultEncoding); + Py_FileSystemDefaultEncoding = strdup(codeset); + Py_DECREF(enc); + } else + PyErr_Clear(); + } +#endif } else { /* get locale */ /* restore LC_NUMERIC first, if appropriate */ |