]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
In class _Subfile, make sure read(n) can't read beyond EOF. Also
authorGuido van Rossum <guido@python.org>
Wed, 17 Jun 1998 18:34:40 +0000 (18:34 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 17 Jun 1998 18:34:40 +0000 (18:34 +0000)
allow negative numbers to specify read until EOF (like for a regular
file's read() method).

Lib/mailbox.py

index dd8e5e1dbaba9f4e7acd937729a4e7d82f8dcabf..0ea4a5811d74b06a517c7450ecf59baf5596c848 100755 (executable)
@@ -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)