]> granicus.if.org Git - python/commitdiff
Issue #9632: Remove sys.setfilesystemencoding() function: use PYTHONFSENCODING
authorVictor Stinner <victor.stinner@haypocalc.com>
Fri, 10 Sep 2010 21:57:59 +0000 (21:57 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Fri, 10 Sep 2010 21:57:59 +0000 (21:57 +0000)
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.

Doc/library/sys.rst
Include/fileobject.h
Lib/test/test_sys.py
Misc/NEWS
Python/bltinmodule.c
Python/sysmodule.c

index 09dd8441b98c15691624936ab304c3947420d899..ad61377476a7628345947045c5d581c1ad0e86f3 100644 (file)
@@ -724,15 +724,6 @@ always available.
    :file:`/usr/include/dlfcn.h` using the :program:`h2py` script. Availability:
    Unix.
 
-.. function:: setfilesystemencoding(enc)
-
-   Set the encoding used when converting Python strings to file names to *enc*.
-   By default, Python tries to determine the encoding it should use automatically
-   on Unix; on Windows, it avoids such conversion completely. This function can
-   be used when Python's determination of the encoding needs to be overwritten,
-   e.g. when not all file names on disk can be decoded using the encoding that
-   Python had chosen.
-
 .. function:: setprofile(profilefunc)
 
    .. index::
index 6e0e55e3eec4a6d0241c3fe3248e3b7da7945fd4..20545fa85f0575b49f3d4e913a8f8508ab51b974 100644 (file)
@@ -21,7 +21,6 @@ PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
 */
 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
 PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding;
-PyAPI_FUNC(int) _Py_SetFileSystemEncoding(PyObject *);
 
 /* Internal API
 
index 8cfbaafd4e0bf5dcd9a7fca674c226192a87219f..639c9b0a60e3ce4cdc6f224e835a16cc2cee4e66 100644 (file)
@@ -630,17 +630,6 @@ class SysModuleTest(unittest.TestCase):
             env['PYTHONFSENCODING'] = encoding
             self.check_fsencoding(get_fsencoding(env), encoding)
 
-    def test_setfilesystemencoding(self):
-        old = sys.getfilesystemencoding()
-        try:
-            sys.setfilesystemencoding("iso-8859-1")
-            self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
-        finally:
-            sys.setfilesystemencoding(old)
-        try:
-            self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
-        finally:
-            sys.setfilesystemencoding(old)
 
 
 class SizeofTest(unittest.TestCase):
index 11a14f2790d70c375a380bbbc19a64562be9efaf..579fc045cecfdc130419308208367ce759ebb67e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,11 @@ Core and Builtins
 Library
 -------
 
+- 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.
+
 - Issue #9410: Various optimizations to the pickle module, leading to
   speedups up to 4x (depending on the benchmark).  Mostly ported from
   Unladen Swallow; initial patch by Alexandre Vassalotti.
index 3bcb08ee987cd7e4a1685140bbe439d7b947c462..60bceb758165dae3e85ba419837ab425091565d7 100644 (file)
@@ -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)
 {
index 90c165a495773c51f136b585e54431bfbbe448d6..4e428f0171df25f9c492160a7d5de38b03db63c4 100644 (file)
@@ -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,