- 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.
This commit is contained in:
Antoine Pitrou 2010-01-31 22:26:04 +00:00
parent e70c72c06b
commit f3fa074703
12 changed files with 97 additions and 47 deletions

View file

@ -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: