[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.
This commit is contained in:
Andrew M. Kuchling 2004-07-07 14:09:21 +00:00
parent 5a8b4593d3
commit 1263bd8b6c
1 changed files with 8 additions and 13 deletions

View File

@ -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 = []