mirror of https://github.com/python/cpython
In class _Subfile, make sure read(n) can't read beyond EOF. Also
allow negative numbers to specify read until EOF (like for a regular file's read() method).
This commit is contained in:
parent
777dcc6b21
commit
e50b0a44cb
|
@ -46,8 +46,11 @@ class _Subfile:
|
|||
def read(self, length = None):
|
||||
if self.pos >= self.stop:
|
||||
return ''
|
||||
if length is None:
|
||||
length = self.stop - self.pos
|
||||
remaining = self.stop - self.pos
|
||||
if length is None or length < 0:
|
||||
length = remaining
|
||||
elif length > remaining:
|
||||
length = remaining
|
||||
self.fp.seek(self.pos)
|
||||
self.pos = self.pos + length
|
||||
return self.fp.read(length)
|
||||
|
|
Loading…
Reference in New Issue