summaryrefslogtreecommitdiff
path: root/Python/codecs.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/codecs.c')
-rw-r--r--Python/codecs.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 0f18c27e5f..ade1418720 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -50,6 +50,31 @@ int PyCodec_Register(PyObject *search_function)
return -1;
}
+int
+PyCodec_Unregister(PyObject *search_function)
+{
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ PyObject *codec_search_path = interp->codec_search_path;
+ /* Do nothing if codec_search_path is not created yet or was cleared. */
+ if (codec_search_path == NULL) {
+ return 0;
+ }
+
+ assert(PyList_CheckExact(codec_search_path));
+ Py_ssize_t n = PyList_GET_SIZE(codec_search_path);
+ for (Py_ssize_t i = 0; i < n; i++) {
+ PyObject *item = PyList_GET_ITEM(codec_search_path, i);
+ if (item == search_function) {
+ if (interp->codec_search_cache != NULL) {
+ assert(PyDict_CheckExact(interp->codec_search_cache));
+ PyDict_Clear(interp->codec_search_cache);
+ }
+ return PyList_SetSlice(codec_search_path, i, i+1, NULL);
+ }
+ }
+ return 0;
+}
+
extern int _Py_normalize_encoding(const char *, char *, size_t);
/* Convert a string to a normalized Python string(decoded from UTF-8): all characters are
@@ -183,31 +208,6 @@ PyObject *_PyCodec_Lookup(const char *encoding)
return NULL;
}
-int _PyCodec_Forget(const char *encoding)
-{
- PyObject *v;
- int result;
-
- PyInterpreterState *interp = _PyInterpreterState_GET();
- if (interp->codec_search_path == NULL) {
- return -1;
- }
-
- /* Convert the encoding to a normalized Python string: all
- characters are converted to lower case, spaces and hyphens are
- replaced with underscores. */
- v = normalizestring(encoding);
- if (v == NULL) {
- return -1;
- }
-
- /* Drop the named codec from the internal cache */
- result = PyDict_DelItem(interp->codec_search_cache, v);
- Py_DECREF(v);
-
- return result;
-}
-
/* Codec registry encoding check API. */
int PyCodec_KnownEncoding(const char *encoding)