r56002 - python/branches/cpy_merge/Modules/_bytes_iomodule.c python/branches/cpy_merge/Modules/_string_iomodule.c
Author: alexandre.vassalotti Date: Sat Jun 16 02:01:57 2007 New Revision: 56002 Modified: python/branches/cpy_merge/Modules/_bytes_iomodule.c python/branches/cpy_merge/Modules/_string_iomodule.c Log: Changes for compatibility with PEP 3116. * The truncate method of BytesIO and StringIO now return the new size of the internal buffer. * Make writable, readable and seekable methods, instead of properties. Modified: python/branches/cpy_merge/Modules/_bytes_iomodule.c ============================================================================== --- python/branches/cpy_merge/Modules/_bytes_iomodule.c (original) +++ python/branches/cpy_merge/Modules/_bytes_iomodule.c Sat Jun 16 02:01:57 2007 @@ -115,7 +115,7 @@ /* Generic getter for the writable, readable and seekable properties */ static PyObject * -bytes_io_get_true(BytesIOObject *self) +generic_true(BytesIOObject *self) { Py_RETURN_TRUE; } @@ -269,7 +269,7 @@ self->string_size = size; self->pos = self->string_size; - Py_RETURN_NONE; + return PyInt_FromSsize_t(self->string_size); } static PyObject * @@ -490,11 +490,10 @@ "tell() -> current file position, an integer\n"); PyDoc_STRVAR(BytesIO_truncate_doc, -"truncate([size]) -> None. Truncate the file to at most size bytes.\n" +"truncate([size]) -> int. Truncate the file to at most size bytes.\n" "\n" "Size defaults to the current file position, as returned by tell().\n" -"If the specified size exceeds the file's current size, the file\n" -"remains unchanged."); +"Returns the new size."); PyDoc_STRVAR(BytesIO_close_doc, "close() -> None. Close the file and release the resources held."); @@ -519,20 +518,22 @@ "Note that newlines are not added. The sequence can be any iterable object\n" "producing strings. This is equivalent to calling write() for each string."); +PyDoc_STRVAR(generic_true_doc, "Always True."); + static PyGetSetDef BytesIO_getsetlist[] = { {"closed", (getter) bytes_io_get_closed, NULL, "True if the file is closed."}, - {"writeable", (getter) bytes_io_get_true, NULL, - "Always True."}, - {"readable", (getter) bytes_io_get_true, NULL, - "Always True."}, - {"seekable", (getter) bytes_io_get_true, NULL, - "Always True."}, {0}, /* sentinel */ }; static struct PyMethodDef BytesIO_methods[] = { + {"readable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, + {"seekable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, + {"writable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, {"flush", (PyCFunction) bytes_io_flush, METH_NOARGS, BytesIO_flush_doc}, {"getvalue", (PyCFunction) bytes_io_getvalue, METH_VARARGS, Modified: python/branches/cpy_merge/Modules/_string_iomodule.c ============================================================================== --- python/branches/cpy_merge/Modules/_string_iomodule.c (original) +++ python/branches/cpy_merge/Modules/_string_iomodule.c Sat Jun 16 02:01:57 2007 @@ -118,7 +118,7 @@ /* Generic getter for the writable, readable and seekable properties */ static PyObject * -string_io_get_true(StringIOObject *self) +generic_true(StringIOObject *self) { Py_RETURN_TRUE; } @@ -272,7 +272,7 @@ self->string_size = size; self->pos = self->string_size; - Py_RETURN_NONE; + return PyInt_FromSsize_t(self->string_size); } static PyObject * @@ -500,11 +500,10 @@ "tell() -> current file position, an integer\n"); PyDoc_STRVAR(StringIO_truncate_doc, -"truncate([size]) -> None. Truncate the file to at most size bytes.\n" +"truncate([size]) -> int. Truncate the file to at most size bytes.\n" "\n" "Size defaults to the current file position, as returned by tell().\n" -"If the specified size exceeds the file's current size, the file\n" -"remains unchanged."); +"Returns the new size."); PyDoc_STRVAR(StringIO_close_doc, "close() -> None. Close the file and release the resources held."); @@ -529,20 +528,22 @@ "Note that newlines are not added. The sequence can be any iterable object\n" "producing strings. This is equivalent to calling write() for each string."); +PyDoc_STRVAR(generic_true_doc, "Always True."); + static PyGetSetDef StringIO_getsetlist[] = { {"closed", (getter) string_io_get_closed, NULL, "True if the file is closed"}, - {"writeable", (getter) string_io_get_true, NULL, - "Always True."}, - {"readable", (getter) string_io_get_true, NULL, - "Always True."}, - {"seekable", (getter) string_io_get_true, NULL, - "Always True."}, {0}, /* sentinel */ }; static struct PyMethodDef StringIO_methods[] = { + {"readable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, + {"seekable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, + {"writable", (PyCFunction) generic_true, METH_NOARGS, + generic_true_doc}, {"flush", (PyCFunction) string_io_flush, METH_NOARGS, StringIO_flush_doc}, {"getvalue", (PyCFunction) string_io_getvalue, METH_VARARGS,
participants (1)
-
alexandre.vassalotti