summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-10-03 16:09:28 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-10-03 16:09:28 (GMT)
commit04dc25c53728f5c2fe66d9e66af67da0c9b8959d (patch)
tree89a6a5bfc7567d3f5deba78bd96fedd2e167e2ce /Python/bltinmodule.c
parentefb14a8857c57e446477ecb964b301b041527c50 (diff)
downloadcpython-04dc25c53728f5c2fe66d9e66af67da0c9b8959d.zip
cpython-04dc25c53728f5c2fe66d9e66af67da0c9b8959d.tar.gz
cpython-04dc25c53728f5c2fe66d9e66af67da0c9b8959d.tar.bz2
Issue #3187: Add sys.setfilesystemencoding.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 0b96dc1..8159fe8 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -17,15 +17,34 @@
*/
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
const char *Py_FileSystemDefaultEncoding = "mbcs";
-const int Py_HasFileSystemDefaultEncoding = 1;
+int Py_HasFileSystemDefaultEncoding = 1;
#elif defined(__APPLE__)
const char *Py_FileSystemDefaultEncoding = "utf-8";
-const int Py_HasFileSystemDefaultEncoding = 1;
+int Py_HasFileSystemDefaultEncoding = 1;
#else
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
-const int Py_HasFileSystemDefaultEncoding = 0;
+int Py_HasFileSystemDefaultEncoding = 0;
#endif
+int
+_Py_SetFileSystemEncoding(PyObject *s)
+{
+ PyObject *defenc;
+ if (!PyUnicode_Check(s)) {
+ PyErr_BadInternalCall();
+ return -1;
+ }
+ defenc = _PyUnicode_AsDefaultEncodedString(s, NULL);
+ if (!defenc)
+ return -1;
+ 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)
{