summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-05-09 19:57:01 (GMT)
committerFred Drake <fdrake@acm.org>2000-05-09 19:57:01 (GMT)
commit8b4d01d9f93068ec08abf62f5307d9391fe6740a (patch)
tree556203bae14e3089e2e3e4cecc99d85ceb4ee1fa /Python/sysmodule.c
parent766de83ab1b4752e9322b2b915d5aaf881b0ed9f (diff)
downloadcpython-8b4d01d9f93068ec08abf62f5307d9391fe6740a.zip
cpython-8b4d01d9f93068ec08abf62f5307d9391fe6740a.tar.gz
cpython-8b4d01d9f93068ec08abf62f5307d9391fe6740a.tar.bz2
M.-A. Lemburg <mal@lemburg.com>:
Added APIs to allow setting and querying the system's current string encoding: sys.set_string_encoding() and sys.get_string_encoding().
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 34f7c96..ebe9a94 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -143,6 +143,41 @@ If it is another kind of object, it will be printed and the system\n\
exit status will be one (i.e., failure).";
static PyObject *
+sys_get_string_encoding(self, args)
+ PyObject *self;
+ PyObject *args;
+{
+ if (!PyArg_ParseTuple(args, ":get_string_encoding"))
+ return NULL;
+ return PyString_FromString(PyUnicode_GetDefaultEncoding());
+}
+
+static char get_string_encoding_doc[] =
+"get_string_encoding() -> string\n\
+\n\
+Return the current default string encoding used by the Unicode \n\
+implementation.";
+
+static PyObject *
+sys_set_string_encoding(self, args)
+ PyObject *self;
+ PyObject *args;
+{
+ char *encoding;
+ if (!PyArg_ParseTuple(args, "s:set_string_encoding", &encoding))
+ return NULL;
+ if (PyUnicode_SetDefaultEncoding(encoding))
+ return NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static char set_string_encoding_doc[] =
+"set_string_encoding(encoding)\n\
+\n\
+Set the current default string encoding used by the Unicode implementation.";
+
+static PyObject *
sys_settrace(self, args)
PyObject *self;
PyObject *args;
@@ -266,6 +301,7 @@ static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
{"exc_info", sys_exc_info, 1, exc_info_doc},
{"exit", sys_exit, 0, exit_doc},
+ {"get_string_encoding", sys_get_string_encoding, 1, get_string_encoding_doc},
#ifdef COUNT_ALLOCS
{"getcounts", sys_getcounts, 1},
#endif
@@ -279,6 +315,7 @@ static PyMethodDef sys_methods[] = {
#ifdef USE_MALLOPT
{"mdebug", sys_mdebug, 1},
#endif
+ {"set_string_encoding", sys_set_string_encoding, 1, set_string_encoding_doc},
{"setcheckinterval", sys_setcheckinterval, 1, setcheckinterval_doc},
{"setprofile", sys_setprofile, 0, setprofile_doc},
{"settrace", sys_settrace, 0, settrace_doc},