Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ whose size is determined when the object is allocated.
*/
typedef struct _object {
PyObject_HEAD
Py_ssize_t ob_bstate;
} PyObject;

typedef struct {
Expand Down
32 changes: 29 additions & 3 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,12 +1209,32 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
return PyObject_Unicode(obj);
}
#else
#endif

// if (PyUnicode_Check(obj)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just delete this chunk?

// PyErr_SetString(PyExc_TypeError,
// "'decode()' is not supported on Unicode in 3.x: convert the string to bytes.");
// obj->ob_bstate = BSTATE_BYTE;
// if ((obj->ob_bstate == BSTATE_BYTE) &&
// PyErr_WarnPy3k(
// "'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
// return NULL;
// }
// return NULL;
// return PyObject_Unicode(obj);
// }

if (PyUnicode_Check(obj)) {
obj->ob_bstate = BSTATE_BYTE;
if ((obj->ob_bstate == BSTATE_BYTE) &&
PyErr_WarnPy3k(
"'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
return NULL;
}
PyErr_SetString(PyExc_TypeError,
"decoding Unicode is not supported");
return NULL;
}
#endif

/* Coerce object */
if (PyString_Check(obj)) {
Expand Down Expand Up @@ -1304,8 +1324,14 @@ PyObject *PyUnicode_AsDecodedObject(PyObject *unicode,
goto onError;
}

if (PyErr_WarnPy3k("decoding Unicode is not supported in 3.x", 1) < 0)
goto onError;
if (PyString_CheckExact(unicode)) {
unicode->ob_bstate = BSTATE_BYTE;
}

if ((unicode->ob_bstate == BSTATE_BYTE) &&
PyErr_WarnPy3k("'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
return NULL;
}

if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
Expand Down