[Patches] [ python-Patches-1012740 ] cStringIO's truncate doesn't

SourceForge.net noreply at sourceforge.net
Fri Aug 20 09:39:47 CEST 2004


Patches item #1012740, was opened at 2004-08-20 07:39
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1012740&group_id=5470

Category: Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dima Dorfman (ddorfman)
Assigned to: Nobody/Anonymous (nobody)
Summary: cStringIO's truncate doesn't

Initial Comment:
truncate on a writeable cStringIO doesn't reset the cursor,
and when another write occurs, the old data magically comes
back:

>>> io = cStringIO.StringIO()
>>> io.write('abc')
>>> io.truncate(0)
>>> io.write('xyz')
>>> io.getvalue()
'abcxyz'

Using the original StringIO module, the latter value is
'xyz', as expected. As far as I can tell, this can't be used
to crash the interpreter because cStringIO never shrinks its
buffer, so the old position is still in bounds. (It probably
should shrink its buffer, but that can be fixed later, if
desired, since it would not change the perceived behavior.)

Even though this introduces a user-visible change, it should
be safe to fix this for 2.4. Anyone that relies on this
wacky behavior already has it coming, and we're not even in
beta yet.

The patch includes a test case that used to succeed with
StringIO but fail with cStringIO. An update to NEWS is also
included since this does, after all, introduce a visible
change.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1012740&group_id=5470


More information about the Patches mailing list