Commit 59f5042b authored by Guido van Rossum's avatar Guido van Rossum

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).
parent db6a21fa
...@@ -46,8 +46,11 @@ class _Subfile: ...@@ -46,8 +46,11 @@ class _Subfile:
def read(self, length = None): def read(self, length = None):
if self.pos >= self.stop: if self.pos >= self.stop:
return '' return ''
if length is None: remaining = self.stop - self.pos
length = self.stop - self.pos if length is None or length < 0:
length = remaining
elif length > remaining:
length = remaining
self.fp.seek(self.pos) self.fp.seek(self.pos)
self.pos = self.pos + length self.pos = self.pos + length
return self.fp.read(length) return self.fp.read(length)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment