diff options
author | Guido van Rossum <guido@python.org> | 1998-06-17 18:34:40 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-06-17 18:34:40 (GMT) |
commit | e50b0a44cb60f41e2cd8d30c920079a95b5c1965 (patch) | |
tree | d117c98ab676fc0ea2ae24c42d77643d9af9727c /Lib | |
parent | 777dcc6b21573056ec51b5642ca989581140c4d9 (diff) | |
download | cpython-e50b0a44cb60f41e2cd8d30c920079a95b5c1965.zip cpython-e50b0a44cb60f41e2cd8d30c920079a95b5c1965.tar.gz cpython-e50b0a44cb60f41e2cd8d30c920079a95b5c1965.tar.bz2 |
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).
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/mailbox.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index dd8e5e1..0ea4a58 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -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) |