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
5475f239
Commit
5475f239
authored
Aug 08, 2003
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF bug #770485: cStringIO does not set closed attr
parent
6e13bcc7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
Lib/test/test_StringIO.py
Lib/test/test_StringIO.py
+10
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/cStringIO.c
Modules/cStringIO.c
+22
-2
No files found.
Lib/test/test_StringIO.py
View file @
5475f239
...
...
@@ -55,6 +55,16 @@ class TestGenericStringIO(unittest.TestCase):
f
.
close
()
self
.
assertRaises
(
ValueError
,
f
.
write
,
'frobnitz'
)
def
test_closed_flag
(
self
):
f
=
self
.
MODULE
.
StringIO
()
self
.
assertEqual
(
f
.
closed
,
False
)
f
.
close
()
self
.
assertEqual
(
f
.
closed
,
True
)
f
=
self
.
MODULE
.
StringIO
(
"abc"
)
self
.
assertEqual
(
f
.
closed
,
False
)
f
.
close
()
self
.
assertEqual
(
f
.
closed
,
True
)
def
test_iterator
(
self
):
eq
=
self
.
assertEqual
unless
=
self
.
failUnless
...
...
Misc/NEWS
View file @
5475f239
...
...
@@ -18,6 +18,8 @@ Core and builtins
Extension modules
-----------------
- cStringIO now supports the f.closed attribute.
- The signal module now exposes SIGRTMIN and SIGRTMAX (if available).
Library
...
...
Modules/cStringIO.c
View file @
5475f239
...
...
@@ -87,6 +87,22 @@ IO__opencheck(IOobject *self) {
return
1
;
}
static
PyObject
*
IO_get_closed
(
IOobject
*
self
,
void
*
closure
)
{
PyObject
*
result
=
Py_False
;
if
(
self
->
buf
==
NULL
)
result
=
Py_True
;
Py_INCREF
(
result
);
return
result
;
}
static
PyGetSetDef
file_getsetlist
[]
=
{
{
"closed"
,
(
getter
)
IO_get_closed
,
NULL
,
"True if the file is closed"
},
{
0
},
};
static
PyObject
*
IO_flush
(
IOobject
*
self
,
PyObject
*
unused
)
{
...
...
@@ -455,6 +471,7 @@ static struct PyMethodDef O_methods[] = {
static
PyMemberDef
O_memberlist
[]
=
{
{
"softspace"
,
T_INT
,
offsetof
(
Oobject
,
softspace
),
0
,
"flag indicating that a space needs to be printed; used by print"
},
/* getattr(f, "closed") is implemented without this table */
{
NULL
}
/* Sentinel */
};
...
...
@@ -498,7 +515,8 @@ static PyTypeObject Otype = {
PyObject_SelfIter
,
/*tp_iter */
(
iternextfunc
)
IO_iternext
,
/*tp_iternext */
O_methods
,
/*tp_methods */
O_memberlist
/*tp_members */
O_memberlist
,
/*tp_members */
file_getsetlist
,
/*tp_getset */
};
static
PyObject
*
...
...
@@ -614,7 +632,9 @@ static PyTypeObject Itype = {
0
,
/* tp_weaklistoffset */
PyObject_SelfIter
,
/* tp_iter */
(
iternextfunc
)
IO_iternext
,
/* tp_iternext */
I_methods
/* tp_methods */
I_methods
,
/* tp_methods */
0
,
/* tp_members */
file_getsetlist
,
/* tp_getset */
};
static
PyObject
*
...
...
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