summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-18 02:28:27 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-07-18 02:28:27 (GMT)
commit10a60b3ec0cdf7eeac98258fc53a33b7026f8ff3 (patch)
tree533e2a67c2c082cd9534c70293977f9245425188 /Objects/exceptions.c
parent6f2df4d5e193d54244b0c2de91ef0ab1604b9243 (diff)
downloadcpython-10a60b3ec0cdf7eeac98258fc53a33b7026f8ff3.zip
cpython-10a60b3ec0cdf7eeac98258fc53a33b7026f8ff3.tar.gz
cpython-10a60b3ec0cdf7eeac98258fc53a33b7026f8ff3.tar.bz2
Change Py_BuildValue to generate Unicode objects for
's' and 'c' codes. Change pickle to dump bytes objects using the 'S' code, and to load the 'S' code as byte objects. Change datetime and array to generate and expect bytes objects in reduce/unreduce.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 1df0ea0..a401806 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -831,28 +831,32 @@ my_basename(char *name)
static PyObject *
SyntaxError_str(PySyntaxErrorObject *self)
{
- int have_filename = 0;
int have_lineno = 0;
+ char *filename = 0;
/* XXX -- do all the additional formatting with filename and
lineno here */
- have_filename = (self->filename != NULL) &&
- PyString_Check(self->filename);
+ if (self->filename) {
+ if (PyString_Check(self->filename))
+ filename = PyString_AsString(self->filename);
+ else if (PyUnicode_Check(self->filename))
+ filename = PyUnicode_AsString(self->filename);
+ }
have_lineno = (self->lineno != NULL) && PyInt_CheckExact(self->lineno);
- if (!have_filename && !have_lineno)
+ if (!filename && !have_lineno)
return PyObject_Unicode(self->msg ? self->msg : Py_None);
- if (have_filename && have_lineno)
+ if (filename && have_lineno)
return PyUnicode_FromFormat("%S (%s, line %ld)",
self->msg ? self->msg : Py_None,
- my_basename(PyString_AS_STRING(self->filename)),
+ my_basename(filename),
PyInt_AsLong(self->lineno));
- else if (have_filename)
+ else if (filename)
return PyUnicode_FromFormat("%S (%s)",
self->msg ? self->msg : Py_None,
- my_basename(PyString_AS_STRING(self->filename)));
+ my_basename(filename));
else /* only have_lineno */
return PyUnicode_FromFormat("%S (line %ld)",
self->msg ? self->msg : Py_None,