mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
6f2df4d5e1
commit
10a60b3ec0
8 changed files with 166 additions and 45 deletions
|
@ -2724,6 +2724,9 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
|||
static PyObject *
|
||||
bytes_reduce(PyBytesObject *self)
|
||||
{
|
||||
/* XXX: This currently returns a Py_UNICODE-widened string
|
||||
in the tuple which is completely useless. Pickle stopped
|
||||
using it for that reason. */
|
||||
return Py_BuildValue("(O(s#))",
|
||||
self->ob_type,
|
||||
self->ob_bytes == NULL ? "" : self->ob_bytes,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue