summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-31 22:26:04 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-31 22:26:04 (GMT)
commitf3fa07470381b4f54b2d3f911fc22624e9b0b27d (patch)
tree5368b993641d34b3824a79896bf18c8f9097ce5c /Lib/_pyio.py
parente70c72c06b169a36170ab68ec52bda9a87c16274 (diff)
downloadcpython-f3fa07470381b4f54b2d3f911fc22624e9b0b27d.zip
cpython-f3fa07470381b4f54b2d3f911fc22624e9b0b27d.tar.gz
cpython-f3fa07470381b4f54b2d3f911fc22624e9b0b27d.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/_pyio.py')
-rw-r--r--Lib/_pyio.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 49fbe19..a1c21d3 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -867,7 +867,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
@@ -1226,8 +1226,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:
@@ -1727,8 +1726,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 detach(self):
if self.buffer is None: