Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e50b0a4

Browse files
committed
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).
1 parent 777dcc6 commit e50b0a4

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/mailbox.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ def __init__(self, fp, start, stop):
4646
def read(self, length = None):
4747
if self.pos >= self.stop:
4848
return ''
49-
if length is None:
50-
length = self.stop - self.pos
49+
remaining = self.stop - self.pos
50+
if length is None or length < 0:
51+
length = remaining
52+
elif length > remaining:
53+
length = remaining
5154
self.fp.seek(self.pos)
5255
self.pos = self.pos + length
5356
return self.fp.read(length)

0 commit comments

Comments
 (0)