diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2004-07-07 14:09:21 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2004-07-07 14:09:21 (GMT) |
commit | 1263bd8b6c507e15df7df506c94b54d9629a8ec8 (patch) | |
tree | dc8addf462b9ec1ab3b817d13b786ca24793cd67 /Lib/mailbox.py | |
parent | 5a8b4593d3d426ef58109a6d1cdb208917128b50 (diff) | |
download | cpython-1263bd8b6c507e15df7df506c94b54d9629a8ec8.zip cpython-1263bd8b6c507e15df7df506c94b54d9629a8ec8.tar.gz cpython-1263bd8b6c507e15df7df506c94b54d9629a8ec8.tar.bz2 |
[Bug #925107] Make .readline() consider self.stop. This makes read() and readline() very similar, so they're refactored into _read. Patch by Johannes Gijsbers.
2.3 bugfix candidate.
Diffstat (limited to 'Lib/mailbox.py')
-rwxr-xr-x | Lib/mailbox.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 258b657..dbb2724 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -43,28 +43,23 @@ class _Subfile: self.stop = stop self.pos = self.start - def read(self, length = None): + + def _read(self, length, read_function): if self.pos >= self.stop: return '' remaining = self.stop - self.pos - if length is None or length < 0: - length = remaining - elif length > remaining: + if length is None or length < 0 or length > remaining: length = remaining self.fp.seek(self.pos) - data = self.fp.read(length) + data = read_function(length) self.pos = self.fp.tell() return data + def read(self, length = None): + self._read(length, self.fp.read) + def readline(self, length = None): - if self.pos >= self.stop: - return '' - if length is None: - length = self.stop - self.pos - self.fp.seek(self.pos) - data = self.fp.readline(length) - self.pos = self.fp.tell() - return data + self._read(length, self.fp.readline) def readlines(self, sizehint = -1): lines = [] |