]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #951915: fix bug in StringIO.truncate - length not changed
authorRaymond Hettinger <python@rcn.com>
Mon, 20 Dec 2004 23:55:32 +0000 (23:55 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 20 Dec 2004 23:55:32 +0000 (23:55 +0000)
(Patch by Armin Rigo.)

Lib/StringIO.py
Misc/NEWS

index 1dfc8b4d070c7734e0cfc19509f110d862a43818..5c463fbc1c94cf09cd9f6e8e4166f928c32c2fa9 100644 (file)
@@ -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__':
index 706fd1faf9c987f580f1d347f315ae0105c2c748..b6a3a1bb51c9a2949a12dd8bc931ac1901f3727c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@ Core and builtins
 Library
 -------
 
+- StringIO.truncate() now correctly adjusts the size attribute.
+  (Bug #951915).
+
 - The decimal module wouldn't run on builds without threads (Bug #1083645).
 
 - Bug #1086555:  Fix leak in syslog module.