From 1263bd8b6c507e15df7df506c94b54d9629a8ec8 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 7 Jul 2004 14:09:21 +0000 Subject: [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. --- Lib/mailbox.py | 21 ++++++++------------- 1 file 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 = [] -- cgit v0.12