mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
Issue #9632: Remove sys.setfilesystemencoding() function: use PYTHONFSENCODING
environment variable to set the filesystem encoding at Python startup. sys.setfilesystemencoding() creates inconsistencies because it is unable to reencode all filenames in all objects.
This commit is contained in:
parent
6246d6dcb0
commit
5b519e0201
6 changed files with 5 additions and 65 deletions
|
@ -33,29 +33,6 @@ const char *Py_FileSystemDefaultEncoding = "utf-8";
|
|||
int Py_HasFileSystemDefaultEncoding = 1;
|
||||
#endif
|
||||
|
||||
int
|
||||
_Py_SetFileSystemEncoding(PyObject *s)
|
||||
{
|
||||
PyObject *defenc, *codec;
|
||||
if (!PyUnicode_Check(s)) {
|
||||
PyErr_BadInternalCall();
|
||||
return -1;
|
||||
}
|
||||
defenc = _PyUnicode_AsDefaultEncodedString(s, NULL);
|
||||
if (!defenc)
|
||||
return -1;
|
||||
codec = _PyCodec_Lookup(PyBytes_AsString(defenc));
|
||||
if (codec == NULL)
|
||||
return -1;
|
||||
Py_DECREF(codec);
|
||||
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding)
|
||||
/* A file system encoding was set at run-time */
|
||||
free((char*)Py_FileSystemDefaultEncoding);
|
||||
Py_FileSystemDefaultEncoding = strdup(PyBytes_AsString(defenc));
|
||||
Py_HasFileSystemDefaultEncoding = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
|
|
|
@ -198,25 +198,6 @@ Return the encoding used to convert Unicode filenames in\n\
|
|||
operating system filenames."
|
||||
);
|
||||
|
||||
static PyObject *
|
||||
sys_setfilesystemencoding(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *new_encoding;
|
||||
if (!PyArg_ParseTuple(args, "U:setfilesystemencoding", &new_encoding))
|
||||
return NULL;
|
||||
if (_Py_SetFileSystemEncoding(new_encoding))
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(setfilesystemencoding_doc,
|
||||
"setfilesystemencoding(string) -> None\n\
|
||||
\n\
|
||||
Set the encoding used to convert Unicode filenames in\n\
|
||||
operating system filenames."
|
||||
);
|
||||
|
||||
static PyObject *
|
||||
sys_intern(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
@ -1012,8 +993,6 @@ static PyMethodDef sys_methods[] = {
|
|||
#ifdef USE_MALLOPT
|
||||
{"mdebug", sys_mdebug, METH_VARARGS},
|
||||
#endif
|
||||
{"setfilesystemencoding", sys_setfilesystemencoding, METH_VARARGS,
|
||||
setfilesystemencoding_doc},
|
||||
{"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
|
||||
setcheckinterval_doc},
|
||||
{"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue