]> granicus.if.org Git - python/commitdiff
Convert file.readinto() to stop using METH_OLDARGS & PyArg_Parse.
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 1 Apr 2002 00:09:00 +0000 (00:09 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 1 Apr 2002 00:09:00 +0000 (00:09 +0000)
Add test for file.readinto().

Lib/test/test_file.py
Objects/fileobject.c

index c00874d390a71df7da7ed4ffed97001d4c15ea83..33a923d78c1add4dec0000f04e79eb5c0ddfa4c6 100644 (file)
@@ -1,4 +1,5 @@
 import os
+from array import array
 
 from test_support import verify, TESTFN
 from UserList import UserList
@@ -13,6 +14,13 @@ buf = f.read()
 f.close()
 verify(buf == '12')
 
+# verify readinto
+a = array('c', 'x'*10)
+f = open(TESTFN, 'rb')
+n = f.readinto(a)
+f.close()
+verify(buf == a.tostring()[:n])
+
 # verify writelines with integers
 f = open(TESTFN, 'wb')
 try:
@@ -69,6 +77,13 @@ if f.isatty():
 if f.closed:
     raise TestError, 'file.closed should be false'
 
+try:
+    f.readinto("")
+except TypeError:
+    pass
+else:
+    raise TestError, 'file.readinto("") should raise a TypeError'
+
 f.close()
 if not f.closed:
     raise TestError, 'file.closed should be true'
index ebe0d2993c0fdcd4f6072e934889befd2ebe6c59..317957484e2c5a1b102f17d6713d2087488c9501 100644 (file)
@@ -686,7 +686,7 @@ file_readinto(PyFileObject *f, PyObject *args)
 
        if (f->f_fp == NULL)
                return err_closed();
-       if (!PyArg_Parse(args, "w#", &ptr, &ntodo))
+       if (!PyArg_ParseTuple(args, "w#", &ptr, &ntodo))
                return NULL;
        ndone = 0;
        while (ntodo > 0) {
@@ -1462,7 +1462,7 @@ static PyMethodDef file_methods[] = {
        {"truncate",    (PyCFunction)file_truncate,   METH_VARARGS, truncate_doc},
 #endif
        {"tell",        (PyCFunction)file_tell,       METH_NOARGS,  tell_doc},
-       {"readinto",    (PyCFunction)file_readinto,   METH_OLDARGS, readinto_doc},
+       {"readinto",    (PyCFunction)file_readinto,   METH_VARARGS, readinto_doc},
        {"readlines",   (PyCFunction)file_readlines,  METH_VARARGS, readlines_doc},
        {"xreadlines",  (PyCFunction)file_xreadlines, METH_NOARGS,  xreadlines_doc},
        {"writelines",  (PyCFunction)file_writelines, METH_O,       writelines_doc},