@@ -39,6 +39,13 @@ Copyright (c) Corporation for National Research Initiatives.
3939
4040/* --- Registry ----------------------------------------------------------- */
4141
42+ PyDoc_STRVAR (register__doc__ ,
43+ "register(search_function)\n\
44+ \n\
45+ Register a codec search function. Search functions are expected to take\n\
46+ one argument, the encoding name in all lower case letters, and return\n\
47+ a tuple of functions (encoder, decoder, stream_reader, stream_writer)." );
48+
4249static
4350PyObject * codecregister (PyObject * self , PyObject * args )
4451{
@@ -57,6 +64,12 @@ PyObject *codecregister(PyObject *self, PyObject *args)
5764 return NULL ;
5865}
5966
67+ PyDoc_STRVAR (lookup__doc__ ,
68+ "lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)\n\
69+ \n\
70+ Looks up a codec tuple in the Python codec registry and returns\n\
71+ a tuple of functions." );
72+
6073static
6174PyObject * codeclookup (PyObject * self , PyObject * args )
6275{
@@ -708,6 +721,15 @@ mbcs_encode(PyObject *self,
708721
709722/* --- Error handler registry --------------------------------------------- */
710723
724+ PyDoc_STRVAR (register_error__doc__ ,
725+ "register_error(errors, handler)\n\
726+ \n\
727+ Register the specified error handler under the name\n\
728+ errors. handler must be a callable object, that\n\
729+ will be called with an exception instance containing\n\
730+ information about the location of the encoding/decoding\n\
731+ error and must return a (replacement, new position) tuple." );
732+
711733static PyObject * register_error (PyObject * self , PyObject * args )
712734{
713735 const char * name ;
@@ -722,6 +744,12 @@ static PyObject *register_error(PyObject *self, PyObject *args)
722744 return Py_None ;
723745}
724746
747+ PyDoc_STRVAR (lookup_error__doc__ ,
748+ "lookup_error(errors) -> handler\n\
749+ \n\
750+ Return the error handler for the specified error handling name\n\
751+ or raise a LookupError, if no handler exists under this name." );
752+
725753static PyObject * lookup_error (PyObject * self , PyObject * args )
726754{
727755 const char * name ;
@@ -735,8 +763,10 @@ static PyObject *lookup_error(PyObject *self, PyObject *args)
735763/* --- Module API --------------------------------------------------------- */
736764
737765static PyMethodDef _codecs_functions [] = {
738- {"register" , codecregister , METH_VARARGS },
739- {"lookup" , codeclookup , METH_VARARGS },
766+ {"register" , codecregister , METH_VARARGS ,
767+ register__doc__ },
768+ {"lookup" , codeclookup , METH_VARARGS ,
769+ lookup__doc__ },
740770 {"escape_encode" , escape_encode , METH_VARARGS },
741771 {"escape_decode" , escape_decode , METH_VARARGS },
742772#ifdef Py_USING_UNICODE
@@ -770,8 +800,10 @@ static PyMethodDef _codecs_functions[] = {
770800 {"mbcs_decode" , mbcs_decode , METH_VARARGS },
771801#endif
772802#endif /* Py_USING_UNICODE */
773- {"register_error" , register_error , METH_VARARGS },
774- {"lookup_error" , lookup_error , METH_VARARGS },
803+ {"register_error" , register_error , METH_VARARGS ,
804+ register_error__doc__ },
805+ {"lookup_error" , lookup_error , METH_VARARGS ,
806+ lookup_error__doc__ },
775807 {NULL , NULL } /* sentinel */
776808};
777809
0 commit comments