mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Patch 1012740: cStringIO's truncate doesn't
truncate() left the stream position unchanged, which meant the "truncated" data didn't go away: >>> io.write('abc') >>> io.truncate(0) >>> io.write('xyz') >>> io.getvalue() 'abcxyz' Patch by Dima Dorfman.
This commit is contained in:
parent
7109b287cf
commit
037b3ee44e
3 changed files with 9 additions and 2 deletions
|
@ -49,9 +49,10 @@ class TestGenericStringIO(unittest.TestCase):
|
||||||
f.seek(10)
|
f.seek(10)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
eq(f.getvalue(), 'abcdefghij')
|
eq(f.getvalue(), 'abcdefghij')
|
||||||
f.seek(0)
|
|
||||||
f.truncate(5)
|
f.truncate(5)
|
||||||
eq(f.getvalue(), 'abcde')
|
eq(f.getvalue(), 'abcde')
|
||||||
|
f.write('xyz')
|
||||||
|
eq(f.getvalue(), 'abcdexyz')
|
||||||
f.close()
|
f.close()
|
||||||
self.assertRaises(ValueError, f.write, 'frobnitz')
|
self.assertRaises(ValueError, f.write, 'frobnitz')
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ Core and builtins
|
||||||
Extension modules
|
Extension modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Patch 1012740: truncate() on a writeable cStringIO now resets the
|
||||||
|
position to the end of the stream. This is consistent with the original
|
||||||
|
StringIO module and avoids inadvertently resurrecting data that was
|
||||||
|
supposed to have been truncated away.
|
||||||
|
|
||||||
- Added socket.socketpair().
|
- Added socket.socketpair().
|
||||||
|
|
||||||
Library
|
Library
|
||||||
|
@ -59,7 +64,7 @@ Library
|
||||||
- A new function tkFont.nametofont was added to return an existing
|
- A new function tkFont.nametofont was added to return an existing
|
||||||
font. The Font class constructor now has an additional exists argument
|
font. The Font class constructor now has an additional exists argument
|
||||||
which, if True, requests to return/configure an existing font, rather
|
which, if True, requests to return/configure an existing font, rather
|
||||||
than creating a new one.
|
than creating a new one.
|
||||||
|
|
||||||
- Updated the decimal package's min() and max() methods to match the
|
- Updated the decimal package's min() and max() methods to match the
|
||||||
latest revision of the General Decimal Arithmetic Specification.
|
latest revision of the General Decimal Arithmetic Specification.
|
||||||
|
|
|
@ -289,6 +289,7 @@ IO_truncate(IOobject *self, PyObject *args) {
|
||||||
if (pos < 0) pos = self->pos;
|
if (pos < 0) pos = self->pos;
|
||||||
|
|
||||||
if (self->string_size > pos) self->string_size = pos;
|
if (self->string_size > pos) self->string_size = pos;
|
||||||
|
self->pos = self->string_size;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue