mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Make cStringIO.truncate raise IOError for negative
arguments (even for -1). Fixes the last bit of #1359365.
This commit is contained in:
parent
283a1353a0
commit
cffcc8b195
3 changed files with 15 additions and 1 deletions
|
@ -62,6 +62,7 @@ class TestGenericStringIO(unittest.TestCase):
|
||||||
eq(f.getvalue(), 'abcde')
|
eq(f.getvalue(), 'abcde')
|
||||||
f.write('xyz')
|
f.write('xyz')
|
||||||
eq(f.getvalue(), 'abcdexyz')
|
eq(f.getvalue(), 'abcdexyz')
|
||||||
|
self.assertRaises(IOError, f.truncate, -1)
|
||||||
f.close()
|
f.close()
|
||||||
self.assertRaises(ValueError, f.write, 'frobnitz')
|
self.assertRaises(ValueError, f.write, 'frobnitz')
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,9 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- cStringIO.truncate(-1) now raises an IOError, like StringIO and
|
||||||
|
regular files.
|
||||||
|
|
||||||
- Patch #1472877: Fix Tix subwidget name resolution.
|
- Patch #1472877: Fix Tix subwidget name resolution.
|
||||||
|
|
||||||
- Patch #1594554: Always close a tkSimpleDialog on ok(), even
|
- Patch #1594554: Always close a tkSimpleDialog on ok(), even
|
||||||
|
|
|
@ -289,7 +289,17 @@ IO_truncate(IOobject *self, PyObject *args) {
|
||||||
|
|
||||||
if (!IO__opencheck(self)) return NULL;
|
if (!IO__opencheck(self)) return NULL;
|
||||||
if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
|
if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
|
||||||
if (pos < 0) pos = self->pos;
|
|
||||||
|
if (PyTuple_Size(args) == 0) {
|
||||||
|
/* No argument passed, truncate to current position */
|
||||||
|
pos = self->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos < 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (self->string_size > pos) self->string_size = pos;
|
if (self->string_size > pos) self->string_size = pos;
|
||||||
self->pos = self->string_size;
|
self->pos = self->string_size;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue