diff -r 8bb426d386a5 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Wed Oct 12 20:18:33 2016 +0200 +++ b/Objects/unicodeobject.c Thu Oct 13 12:49:08 2016 +0300 @@ -3232,6 +3232,28 @@ PyUnicode_AsDecodedObject(PyObject *unic const char *encoding, const char *errors) { + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); + return NULL; + } + + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyUnicode_AsDecodedObject() is deprecated; " + "use PyCodec_Decode() to decode from str", 1) < 0) + return NULL; + + if (encoding == NULL) + encoding = PyUnicode_GetDefaultEncoding(); + + /* Decode via the codec registry */ + return PyCodec_Decode(unicode, encoding, errors); +} + +PyObject * +PyUnicode_AsDecodedUnicode(PyObject *unicode, + const char *encoding, + const char *errors) +{ PyObject *v; if (!PyUnicode_Check(unicode)) { @@ -3239,30 +3261,10 @@ PyUnicode_AsDecodedObject(PyObject *unic goto onError; } - if (encoding == NULL) - encoding = PyUnicode_GetDefaultEncoding(); - - /* Decode via the codec registry */ - v = PyCodec_Decode(unicode, encoding, errors); - if (v == NULL) - goto onError; - return unicode_result(v); - - onError: - return NULL; -} - -PyObject * -PyUnicode_AsDecodedUnicode(PyObject *unicode, - const char *encoding, - const char *errors) -{ - PyObject *v; - - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); - goto onError; - } + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyUnicode_AsDecodedUnicode() is deprecated; " + "use PyCodec_Decode() to decode from str to str", 1) < 0) + return NULL; if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -3639,6 +3641,11 @@ PyUnicode_AsEncodedUnicode(PyObject *uni goto onError; } + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyUnicode_AsEncodedUnicode() is deprecated; " + "use PyCodec_Encode() to encode from str to str", 1) < 0) + return NULL; + if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding();