mirror of
https://github.com/python/cpython.git
synced 2025-08-16 23:01:34 +00:00
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:
parent
f333014467
commit
ca5a06aaa9
7 changed files with 81 additions and 28 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue