]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
changed repr and str to always convert unicode strings
authorFredrik Lundh <fredrik@pythonware.com>
Sat, 1 Jul 2000 14:31:09 +0000 (14:31 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Sat, 1 Jul 2000 14:31:09 +0000 (14:31 +0000)
to 8-bit strings, using the default encoding.

Objects/object.c

index 3052d38174c162a7dabe945b26e704567086848f..7f38dff6e29ea4840be96fcb3f269d1799f3a8db 100644 (file)
@@ -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)",