bpo-41842: Add codecs.unregister() function (GH-22360)

Add codecs.unregister() and PyCodec_Unregister() functions
to unregister a codec search function.
This commit is contained in:
Hai Shi 2020-09-29 05:41:11 +08:00 committed by GitHub
parent 24ba3b0df5
commit d332e7b816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 108 additions and 5 deletions

View file

@ -68,6 +68,27 @@ _codecs_register(PyObject *module, PyObject *search_function)
Py_RETURN_NONE;
}
/*[clinic input]
_codecs.unregister
search_function: object
/
Unregister a codec search function and clear the registry's cache.
If the search function is not registered, do nothing.
[clinic start generated code]*/
static PyObject *
_codecs_unregister(PyObject *module, PyObject *search_function)
/*[clinic end generated code: output=1f0edee9cf246399 input=dd7c004c652d345e]*/
{
if (PyCodec_Unregister(search_function) < 0) {
return NULL;
}
Py_RETURN_NONE;
}
/*[clinic input]
_codecs.lookup
encoding: str
@ -992,6 +1013,7 @@ _codecs_lookup_error_impl(PyObject *module, const char *name)
static PyMethodDef _codecs_functions[] = {
_CODECS_REGISTER_METHODDEF
_CODECS_UNREGISTER_METHODDEF
_CODECS_LOOKUP_METHODDEF
_CODECS_ENCODE_METHODDEF
_CODECS_DECODE_METHODDEF