eq(f.getvalue(), 'abcde')
f.write('xyz')
eq(f.getvalue(), 'abcdexyz')
+ self.assertRaises(IOError, f.truncate, -1)
f.close()
self.assertRaises(ValueError, f.write, 'frobnitz')
Library
-------
+- cStringIO.truncate(-1) now raises an IOError, like StringIO and
+ regular files.
+
- Patch #1472877: Fix Tix subwidget name resolution.
- Patch #1594554: Always close a tkSimpleDialog on ok(), even
if (!IO__opencheck(self)) 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;
self->pos = self->string_size;