[Python-checkins] r52788 - in python/trunk: Lib/test/test_StringIO.py Misc/NEWS Modules/cStringIO.c

martin.v.loewis python-checkins at python.org
Sun Nov 19 11:41:42 CET 2006


Author: martin.v.loewis
Date: Sun Nov 19 11:41:41 2006
New Revision: 52788
Modified:
 python/trunk/Lib/test/test_StringIO.py
 python/trunk/Misc/NEWS
 python/trunk/Modules/cStringIO.c
Log:
Make cStringIO.truncate raise IOError for negative
arguments (even for -1). Fixes the last bit of
#1359365.
Modified: python/trunk/Lib/test/test_StringIO.py
==============================================================================
--- python/trunk/Lib/test/test_StringIO.py	(original)
+++ python/trunk/Lib/test/test_StringIO.py	Sun Nov 19 11:41:41 2006
@@ -62,6 +62,7 @@
 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')
 
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Nov 19 11:41:41 2006
@@ -101,6 +101,9 @@
 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
Modified: python/trunk/Modules/cStringIO.c
==============================================================================
--- python/trunk/Modules/cStringIO.c	(original)
+++ python/trunk/Modules/cStringIO.c	Sun Nov 19 11:41:41 2006
@@ -289,7 +289,17 @@
 	
 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;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /