From: Fredrik Lundh Date: Sat, 1 Jul 2000 14:31:09 +0000 (+0000) Subject: changed repr and str to always convert unicode strings X-Git-Tag: v2.0b1~1138 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=efecc7d05bf674db579638e0a8e5b5496e1e0826;p=thirdparty%2FPython%2Fcpython.git changed repr and str to always convert unicode strings to 8-bit strings, using the default encoding. --- diff --git a/Objects/object.c b/Objects/object.c index 3052d38174c1..7f38dff6e29e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -265,6 +265,14 @@ PyObject_Repr(v) res = (*v->ob_type->tp_repr)(v); if (res == 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)) { PyErr_Format(PyExc_TypeError, "__repr__ returned non-string (type %.200s)", @@ -302,6 +310,14 @@ PyObject_Str(v) } if (res == 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)) { PyErr_Format(PyExc_TypeError, "__str__ returned non-string (type %.200s)",