summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-27 21:48:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-27 21:48:46 (GMT)
commitca5a06aaa968ae767329f8afedbaf17fc337416f (patch)
tree1c0f8bfdd0469ce707d41b99371855f6f3f8ae91 /Lib/io.py
parentf3330144679453a66b9baf54963462d8cbd095f8 (diff)
downloadcpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.zip
cpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.tar.gz
cpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.tar.bz2
Issue #6939: Fix file I/O objects in the `io` module to keep the original
file position when calling `truncate()`. It would previously change the file position to the given argument, which goes against the tradition of `ftruncate()` and other truncation APIs. Patch by Pascal Chambon.
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 70f2aba..d090eec 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -880,7 +880,7 @@ class _BytesIO(BufferedIOBase):
elif pos < 0:
raise ValueError("negative truncate position %r" % (pos,))
del self._buffer[pos:]
- return self.seek(pos)
+ return pos
def readable(self):
return True
@@ -1215,8 +1215,7 @@ class BufferedRandom(BufferedWriter, BufferedReader):
if pos is None:
pos = self.tell()
# Use seek to flush the read buffer.
- self.seek(pos)
- return BufferedWriter.truncate(self)
+ return BufferedWriter.truncate(self, pos)
def read(self, n=None):
if n is None:
@@ -1667,8 +1666,7 @@ class TextIOWrapper(TextIOBase):
self.flush()
if pos is None:
pos = self.tell()
- self.seek(pos)
- return self.buffer.truncate()
+ return self.buffer.truncate(pos)
def seek(self, cookie, whence=0):
if self.closed: