mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +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
e70c72c06b
commit
f3fa074703
12 changed files with 97 additions and 47 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue