[Python-checkins] r56150 - python/branches/cpy_merge/Modules/_bytes_iomodule.c
alexandre.vassalotti
python-checkins at python.org
Mon Jul 2 22:08:49 CEST 2007
Author: alexandre.vassalotti
Date: Mon Jul 2 22:08:49 2007
New Revision: 56150
Modified:
python/branches/cpy_merge/Modules/_bytes_iomodule.c
Log:
Add the readinto method.
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 Mon Jul 2 22:08:49 2007
@@ -278,6 +278,24 @@
}
static PyObject *
+bytes_io_readinto(BytesIOObject *self, PyObject *buffer)
+{
+ void *raw_buffer;
+ Py_ssize_t len;
+
+ if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &len) == -1)
+ return NULL;
+
+ if (len > self->string_size)
+ len = self->string_size;
+
+ memcpy(raw_buffer, self->buf + self->pos, len);
+ self->pos += len;
+
+ return PyInt_FromSsize_t(len);
+}
+
+static PyObject *
bytes_io_truncate(BytesIOObject *self, PyObject *args)
{
Py_ssize_t size;
@@ -517,6 +535,12 @@
"The optional size argument, if given, is an approximate bound on the\n"
"total number of bytes in the lines returned.\n");
+PyDoc_STRVAR(BytesIO_readinto_doc,
+"readinto(bytes) -> int. Read up to len(b) bytes into b.\n"
+"\n"
+"Returns number of bytes read (0 for EOF), or None if the object\n"
+"is set not to block as has no data to read."
+
PyDoc_STRVAR(BytesIO_tell_doc,
"tell() -> current file position, an integer\n");
@@ -579,6 +603,8 @@
BytesIO_readline_doc},
{"readlines", (PyCFunction) bytes_io_readlines, METH_VARARGS,
BytesIO_readlines_doc},
+ {"readinto", (PyCFunction) bytes_io_readinto, METH_O,
+ BytesIO_readinto_doc},
{"tell", (PyCFunction) bytes_io_tell, METH_NOARGS,
BytesIO_tell_doc},
{"truncate", (PyCFunction) bytes_io_truncate, METH_VARARGS,
More information about the Python-checkins
mailing list