From 6065d3232520b52f5196c31738dcbfb355ee9a4c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 20 Dec 2004 23:51:53 +0000 Subject: [PATCH] SF bug #951915: fix bug in StringIO.truncate - length not changed (Patch by Armin Rigo.) --- Lib/StringIO.py | 6 ++++++ Misc/NEWS | 3 +++ 2 files changed, 9 insertions(+) diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 1dfc8b4d07..5c463fbc1c 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -204,6 +204,7 @@ class StringIO: elif size < self.pos: self.pos = size self.buf = self.getvalue()[:size] + self.len = size def write(self, s): """Write a string to the file. @@ -312,6 +313,11 @@ def test(): print 'File length =', f.tell() if f.tell() != length: raise RuntimeError, 'bad length' + f.truncate(length/2) + f.seek(0, 2) + print 'Truncated length =', f.tell() + if f.tell() != length/2: + raise RuntimeError, 'truncate did not adjust length' f.close() if __name__ == '__main__': diff --git a/Misc/NEWS b/Misc/NEWS index 570addacff..ad0518b9a2 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,9 @@ Extension Modules Library ------- +- StringIO.truncate() now correctly adjusts the size attribute. + (Bug #951915). + - locale.py now uses an updated locale alias table (built using Tools/i18n/makelocalealias.py, a tool to parse the X11 locale alias file); the encoding lookup was enhanced to use Python's -- 2.49.0