This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Iterating closed StringIO.StringIO
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: doerwalter, georg.brandl, gvanrossum, loewis
Priority: normal Keywords: patch

Created on 2005-11-18 00:03 by doerwalter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
StringIO.diff doerwalter, 2005-11-18 00:03
Messages (11)
msg49054 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2005-11-18 00:03
This patch changes StringIO.StringIO.next to raise a
ValueError when the stream is closed. This is the same
behaviour as for cStringIO.StringIO and real files.
msg49055 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2005-11-29 16:36
Logged In: YES 
user_id=89016

There are other discrepancies between StringIO.StringIO and
cString.StringIO: isatty() raises a ValueError() for a
closed StringIO.StringIO and a closed file, but not for a
closed cStringIO.StringIO. And the truncate() method when
called with a negative argument raised an IOError for
StringIO.StringIO and real files, but not for
cStringIO.StringIO.
msg49056 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-03-15 05:31
Logged In: YES 
user_id=6380

Please check this in if you haven't already done so.

I need to shed load!
msg49057 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2006-03-15 08:25
Logged In: YES 
user_id=89016

Checked in as r43039. What do we do with the other
discrepancies. Change cStringIO for both the isatty() and
the truncate() problems?
msg49058 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-03-15 17:37
Logged In: YES 
user_id=6380

Sure.
msg49059 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2006-03-15 22:14
Logged In: YES 
user_id=89016

Checked in a fix for cStringIO.StringIO.isatty() as r43054.
msg49060 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-12 18:51
Logged In: YES 
user_id=21627

What is the status of this patch? Is there any further
action necessary?
msg49061 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2006-11-13 15:50
Logged In: YES 
user_id=89016

truncate() hasn't been changed yet:
cStringIO.StringIO.truncate() treats a negative argument as
"truncate to the current position". file.truncate() raises a
"IOError: [Errno 22] Invalid argument". In this case the
StringIO behaviour seems to be the preferable one.
msg49062 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-11-13 16:46
Logged In: YES 
user_id=849994

Well, standard C specifies to return EINVAL on negative
length. I'm not sure if we should deviate from that behavior
as long as files are a quite thin wrapper around standard C
files.
msg49063 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2006-11-13 17:39
Logged In: YES 
user_id=89016

Calling file.truncate() without a argument does a "truncate
to current position" so maybe StringIO should raise
IOError(EINVAL) on truncate(-1) and both should truncate to
the current position on truncate(None)?
msg49064 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-19 10:45
doerwalter: I think it should. StringIO was already behaving that way,
so only cStringIO needed to distinguish between -1 and no argument
(passing None isn't supported - it isn't for regular files, either).

I committed this as r52788, and think that this issue can now be
closed. I don't think this change should be backported, as it may
break applications, for no good reason.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42605
2005-11-18 00:03:07doerwaltercreate