[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

STINNER Victor report at bugs.python.org
Tue Nov 19 15:27:23 CET 2013


STINNER Victor added the comment:

+    /* A set would be faster, but when to build it, where to store it? */
+    if (_PyUnicode_CompareWithId(codec_name, &PyId_base64) == 0 ||
+        _PyUnicode_CompareWithId(codec_name, &PyId_uu) == 0 ||
+        _PyUnicode_CompareWithId(codec_name, &PyId_quopri) == 0 ||
+        _PyUnicode_CompareWithId(codec_name, &PyId_hex) == 0 ||
+        _PyUnicode_CompareWithId(codec_name, &PyId_bz2) == 0 ||
+        _PyUnicode_CompareWithId(codec_name, &PyId_zlib) == 0 ||
+        PyUnicode_CompareWithASCIIString(codec_name, "rot-13") == 0
+       ) {
+        is_text_codec = 0;
+    }

This is slow and not future proof. It would be faster and simpler to have two registries: a register only for bytes.decode()/str.encode() and another for "custom codecs" for codecs.encode/decode (or (bytes|str).transform()/untransform()).

So "abc".encode("rot13") would simply fail with a LookupError.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19619>
_______________________________________


More information about the Python-bugs-list mailing list