summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2008-07-08 14:08:04 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2008-07-08 14:08:04 (GMT)
commit524b7773ccf6f462444c22da19cf138f0c6416e4 (patch)
tree12d989a7fb762bb204889e285c6119c7ad8bd7cb /Objects/exceptions.c
parentdbc5987e2fef558cd1410f79dbec4262b8a80d66 (diff)
downloadcpython-524b7773ccf6f462444c22da19cf138f0c6416e4.zip
cpython-524b7773ccf6f462444c22da19cf138f0c6416e4.tar.gz
cpython-524b7773ccf6f462444c22da19cf138f0c6416e4.tar.bz2
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 48b47b0..c0254ff 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -117,6 +117,28 @@ BaseException_str(PyBaseExceptionObject *self)
return out;
}
+#ifdef Py_USING_UNICODE
+static PyObject *
+BaseException_unicode(PyBaseExceptionObject *self)
+{
+ PyObject *out;
+
+ switch (PyTuple_GET_SIZE(self->args)) {
+ case 0:
+ out = PyUnicode_FromString("");
+ break;
+ case 1:
+ out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0));
+ break;
+ default:
+ out = PyObject_Unicode(self->args);
+ break;
+ }
+
+ return out;
+}
+#endif
+
static PyObject *
BaseException_repr(PyBaseExceptionObject *self)
{
@@ -181,6 +203,9 @@ BaseException_setstate(PyObject *self, PyObject *state)
static PyMethodDef BaseException_methods[] = {
{"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS },
{"__setstate__", (PyCFunction)BaseException_setstate, METH_O },
+#ifdef Py_USING_UNICODE
+ {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS },
+#endif
{NULL, NULL, 0, NULL},
};