Issue #23099: Closing io.BytesIO with exported buffer is rejected now to

prevent corrupting exported buffer.
This commit is contained in:
Serhiy Storchaka 2015-02-03 09:30:51 +02:00
commit 32ca3dcb97
5 changed files with 23 additions and 7 deletions

View file

@ -852,8 +852,14 @@ class BytesIO(BufferedIOBase):
def getbuffer(self):
"""Return a readable and writable view of the buffer.
"""
if self.closed:
raise ValueError("getbuffer on closed file")
return memoryview(self._buffer)
def close(self):
self._buffer.clear()
super().close()
def read(self, size=None):
if self.closed:
raise ValueError("read from closed file")