diff options
author | Guido van Rossum <guido@python.org> | 2007-11-03 00:24:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-03 00:24:24 (GMT) |
commit | a6c04bed1ed51e87bf9a24bc4b9ab9364821aef5 (patch) | |
tree | 9309c1d5e15fbc9990b914f1d78d93912780b720 /Objects | |
parent | 2cc30daa863dfc73dba3f60d0102685949538624 (diff) | |
download | cpython-a6c04bed1ed51e87bf9a24bc4b9ab9364821aef5.zip cpython-a6c04bed1ed51e87bf9a24bc4b9ab9364821aef5.tar.gz cpython-a6c04bed1ed51e87bf9a24bc4b9ab9364821aef5.tar.bz2 |
Patch 1171 by mfenniak -- allow subclassing of bytes.
I suspect this has some problems when the subclass is evil,
but that's for later.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 2595ff2..3f2dbc2 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2921,13 +2921,21 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyObject * bytes_reduce(PyBytesObject *self) { - PyObject *latin1; + PyObject *latin1, *dict; if (self->ob_bytes) latin1 = PyUnicode_DecodeLatin1(self->ob_bytes, Py_Size(self), NULL); else latin1 = PyUnicode_FromString(""); - return Py_BuildValue("(O(Ns))", Py_Type(self), latin1, "latin-1"); + + dict = PyObject_GetAttrString((PyObject *)self, "__dict__"); + if (dict == NULL) { + PyErr_Clear(); + dict = Py_None; + Py_INCREF(dict); + } + + return Py_BuildValue("(O(Ns)N)", Py_Type(self), latin1, "latin-1", dict); } static PySequenceMethods bytes_as_sequence = { @@ -3045,8 +3053,7 @@ PyTypeObject PyBytes_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ &bytes_as_buffer, /* tp_as_buffer */ - /* bytes is 'final' or 'sealed' */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ bytes_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ |