[Python-checkins] r55973 - python/branches/cpy_merge/Modules/_bytes_iomodule.c python/branches/cpy_merge/Modules/_string_iomodule.c

alexandre.vassalotti python-checkins at python.org
Thu Jun 14 22:26:10 CEST 2007


Author: alexandre.vassalotti
Date: Thu Jun 14 22:26:06 2007
New Revision: 55973
Modified:
 python/branches/cpy_merge/Modules/_bytes_iomodule.c
 python/branches/cpy_merge/Modules/_string_iomodule.c
Log:
Change the write method to return the number of bytes/characters written.
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	Thu Jun 14 22:26:06 2007
@@ -337,7 +337,7 @@
 bytes_io_write(BytesIOObject *self, PyObject *args)
 {
 const char *bytes;
- Py_ssize_t n;
+ Py_ssize_t len, n;
 
 if (self->buf == NULL)
 return err_closed();
@@ -345,10 +345,11 @@
 if (!PyArg_ParseTuple(args, "t#:write", &bytes, &n))
 return NULL;
 
- if (write_bytes(self, bytes, n) == -1)
+ len = write_bytes(self, bytes, n);
+ if (len == -1)
 return NULL;
 
- Py_RETURN_NONE;
+ return PyInt_FromSsize_t(len);
 }
 
 static PyObject *
@@ -508,7 +509,9 @@
 "Returns the new absolute position.");
 
 PyDoc_STRVAR(BytesIO_write_doc,
-"write(str) -> None. Write string str to file.");
+"write(str) -> int. Write string str to file.\n"
+"\n"
+"Return the number of bytes written.");
 
 PyDoc_STRVAR(BytesIO_writelines_doc,
 "writelines(sequence_of_strings) -> None. Write the strings to the file.\n"
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	Thu Jun 14 22:26:06 2007
@@ -340,7 +340,7 @@
 string_io_write(StringIOObject *self, PyObject *args)
 {
 const Py_UNICODE *ustr;
- Py_ssize_t n;
+ Py_ssize_t len, n;
 
 if (self->buf == NULL)
 return err_closed();
@@ -350,10 +350,11 @@
 " unicode strings", &ustr, &n))
 return NULL;
 
- if (write_str(self, ustr, n) == -1)
+ len = write_str(self, ustr, n);
+ if (len == -1)
 return NULL;
 
- Py_RETURN_NONE;
+ return PyInt_FromSsize_t(len);
 }
 
 static PyObject *
@@ -518,7 +519,9 @@
 "Returns the new absolute position.");
 
 PyDoc_STRVAR(StringIO_write_doc,
-"write(str) -> None. Write string str to file.");
+"write(str) -> int. Write string str to file.\n"
+"\n"
+"Return the number of characters written.");
 
 PyDoc_STRVAR(StringIO_writelines_doc,
 "writelines(sequence_of_strings) -> None. Write the strings to the file.\n"


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /