changed repr and str to always convert unicode strings
to 8-bit strings, using the default encoding.
This commit is contained in:
parent
5069498884
commit
efecc7d05b
|
@ -265,6 +265,14 @@ PyObject_Repr(v)
|
||||||
res = (*v->ob_type->tp_repr)(v);
|
res = (*v->ob_type->tp_repr)(v);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (PyUnicode_Check(res)) {
|
||||||
|
PyObject* str;
|
||||||
|
str = PyUnicode_AsEncodedString(res, NULL, NULL);
|
||||||
|
if (str) {
|
||||||
|
Py_DECREF(res);
|
||||||
|
res = str;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!PyString_Check(res)) {
|
if (!PyString_Check(res)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__repr__ returned non-string (type %.200s)",
|
"__repr__ returned non-string (type %.200s)",
|
||||||
|
@ -302,6 +310,14 @@ PyObject_Str(v)
|
||||||
}
|
}
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (PyUnicode_Check(res)) {
|
||||||
|
PyObject* str;
|
||||||
|
str = PyUnicode_AsEncodedString(res, NULL, NULL);
|
||||||
|
if (str) {
|
||||||
|
Py_DECREF(res);
|
||||||
|
res = str;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!PyString_Check(res)) {
|
if (!PyString_Check(res)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__str__ returned non-string (type %.200s)",
|
"__str__ returned non-string (type %.200s)",
|
||||||
|
|
Loading…
Reference in New Issue