mirror of
https://github.com/python/cpython.git
synced 2025-07-13 22:35:18 +00:00
Issue #19619: Blacklist non-text codecs in method API
str.encode, bytes.decode and bytearray.decode now use an internal API to throw LookupError for known non-text encodings, rather than attempting the encoding or decoding operation and then throwing a TypeError for an unexpected output type. The latter mechanism remains in place for third party non-text encodings.
This commit is contained in:
parent
322f5ba0d8
commit
c72e4e6dcc
13 changed files with 291 additions and 93 deletions
|
@ -3044,7 +3044,7 @@ PyUnicode_Decode(const char *s,
|
|||
buffer = PyMemoryView_FromBuffer(&info);
|
||||
if (buffer == NULL)
|
||||
goto onError;
|
||||
unicode = PyCodec_Decode(buffer, encoding, errors);
|
||||
unicode = _PyCodec_DecodeText(buffer, encoding, errors);
|
||||
if (unicode == NULL)
|
||||
goto onError;
|
||||
if (!PyUnicode_Check(unicode)) {
|
||||
|
@ -3410,7 +3410,7 @@ PyUnicode_AsEncodedString(PyObject *unicode,
|
|||
}
|
||||
|
||||
/* Encode via the codec registry */
|
||||
v = PyCodec_Encode(unicode, encoding, errors);
|
||||
v = _PyCodec_EncodeText(unicode, encoding, errors);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue