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
c912a3a8
Commit
c912a3a8
authored
Sep 19, 2000
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement readlines function. Closes Bug #110686.
parent
e84b7403
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
Modules/cStringIO.c
Modules/cStringIO.c
+36
-0
No files found.
Modules/cStringIO.c
View file @
c912a3a8
...
...
@@ -224,6 +224,40 @@ O_readline(Oobject *self, PyObject *args) {
return
PyString_FromStringAndSize
(
output
,
n
);
}
static
char
O_readlines__doc__
[]
=
"readlines() -- Read all lines"
;
static
PyObject
*
O_readlines
(
Oobject
*
self
,
PyObject
*
args
)
{
int
n
;
char
*
output
;
PyObject
*
result
,
*
line
;
int
hint
=
0
,
length
=
0
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"|i:write"
,
&
hint
))
return
NULL
;
result
=
PyList_New
(
0
);
if
(
!
result
)
return
NULL
;
while
(
1
){
n
=
O_creadline
((
PyObject
*
)
self
,
&
output
);
if
(
n
==
0
)
break
;
line
=
PyString_FromStringAndSize
(
output
,
n
);
if
(
!
line
){
Py_DECREF
(
result
);
return
NULL
;
}
PyList_Append
(
result
,
line
);
Py_DECREF
(
line
);
length
+=
n
;
if
(
hint
>
0
&&
length
>=
hint
)
break
;
}
return
result
;
}
static
char
O_write__doc__
[]
=
"write(s) -- Write a string to the file"
"
\n\n
Note (hack:) writing None resets the buffer"
...
...
@@ -390,6 +424,7 @@ static struct PyMethodDef O_methods[] = {
{
"write"
,
(
PyCFunction
)
O_write
,
METH_VARARGS
,
O_write__doc__
},
{
"read"
,
(
PyCFunction
)
O_read
,
METH_VARARGS
,
O_read__doc__
},
{
"readline"
,
(
PyCFunction
)
O_readline
,
METH_VARARGS
,
O_readline__doc__
},
{
"readlines"
,
(
PyCFunction
)
O_readlines
,
METH_VARARGS
,
O_readlines__doc__
},
{
"reset"
,
(
PyCFunction
)
O_reset
,
METH_VARARGS
,
O_reset__doc__
},
{
"seek"
,
(
PyCFunction
)
O_seek
,
METH_VARARGS
,
O_seek__doc__
},
{
"tell"
,
(
PyCFunction
)
O_tell
,
METH_VARARGS
,
O_tell__doc__
},
...
...
@@ -522,6 +557,7 @@ I_seek(Oobject *self, PyObject *args) {
static
struct
PyMethodDef
I_methods
[]
=
{
{
"read"
,
(
PyCFunction
)
O_read
,
METH_VARARGS
,
O_read__doc__
},
{
"readline"
,
(
PyCFunction
)
O_readline
,
METH_VARARGS
,
O_readline__doc__
},
{
"readlines"
,
(
PyCFunction
)
O_readlines
,
METH_VARARGS
,
O_readlines__doc__
},
{
"reset"
,
(
PyCFunction
)
O_reset
,
METH_VARARGS
,
O_reset__doc__
},
{
"seek"
,
(
PyCFunction
)
I_seek
,
METH_VARARGS
,
O_seek__doc__
},
{
"tell"
,
(
PyCFunction
)
O_tell
,
METH_VARARGS
,
O_tell__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