Mercurial > cpython-lru_cache-weakref
diff Modules/_codecsmodule.c @ 25091:0337dad8403e legacy-trunk
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Mon, 02 Sep 2002 13:14:32 +0000 |
| parents | ab63af3ec349 |
| children | 040af9c736bb |
line wrap: on
line diff
--- a/Modules/_codecsmodule.c Mon Sep 02 12:29:11 2002 +0000 +++ b/Modules/_codecsmodule.c Mon Sep 02 13:14:32 2002 +0000 @@ -706,6 +706,32 @@ #endif /* MS_WINDOWS */ #endif /* Py_USING_UNICODE */ +/* --- Error handler registry --------------------------------------------- */ + +static PyObject *register_error(PyObject *self, PyObject *args) +{ + const char *name; + PyObject *handler; + + if (!PyArg_ParseTuple(args, "sO:register_error", + &name, &handler)) + return NULL; + if (PyCodec_RegisterError(name, handler)) + return NULL; + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *lookup_error(PyObject *self, PyObject *args) +{ + const char *name; + + if (!PyArg_ParseTuple(args, "s:lookup_error", + &name)) + return NULL; + return PyCodec_LookupError(name); +} + /* --- Module API --------------------------------------------------------- */ static PyMethodDef _codecs_functions[] = { @@ -744,6 +770,8 @@ {"mbcs_decode", mbcs_decode, METH_VARARGS}, #endif #endif /* Py_USING_UNICODE */ + {"register_error", register_error, METH_VARARGS}, + {"lookup_error", lookup_error, METH_VARARGS}, {NULL, NULL} /* sentinel */ };
