Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 12649:c92668766f5d legacy-trunk
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().
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 09 May 2000 19:57:01 +0000 |
| parents | 2392d10e21f1 |
| children | 78231bbe605d |
line wrap: on
line diff
--- a/Python/sysmodule.c Tue May 09 19:55:59 2000 +0000 +++ b/Python/sysmodule.c Tue May 09 19:57:01 2000 +0000 @@ -143,6 +143,41 @@ 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 @@ /* 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 @@ #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},
