Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7be0049b
Commit
7be0049b
authored
Apr 01, 2002
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert file.readinto() to stop using METH_OLDARGS & PyArg_Parse.
Add test for file.readinto().
parent
8e4135f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
Lib/test/test_file.py
Lib/test/test_file.py
+15
-0
Objects/fileobject.c
Objects/fileobject.c
+2
-2
No files found.
Lib/test/test_file.py
View file @
7be0049b
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'
...
...
Objects/fileobject.c
View file @
7be0049b
...
...
@@ -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_Parse
Tuple
(
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_
OLD
ARGS
,
readinto_doc
},
{
"readinto"
,
(
PyCFunction
)
file_readinto
,
METH_
VAR
ARGS
,
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
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment