summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-07-01 14:31:09 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2000-07-01 14:31:09 (GMT)
commitefecc7d05bf674db579638e0a8e5b5496e1e0826 (patch)
tree3fa3522773569b43c846a7a06a4af42774e32a48 /Objects
parent50694988844e76f3b532a6d6dc461096d0ef622e (diff)
downloadcpython-efecc7d05bf674db579638e0a8e5b5496e1e0826.zip
cpython-efecc7d05bf674db579638e0a8e5b5496e1e0826.tar.gz
cpython-efecc7d05bf674db579638e0a8e5b5496e1e0826.tar.bz2
changed repr and str to always convert unicode strings
to 8-bit strings, using the default encoding.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 3052d38..7f38dff 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)",