From: Guido van Rossum Date: Fri, 25 Jul 1997 14:56:01 +0000 (+0000) Subject: Patch by Lars Wirzenius to allow f.readline(length). X-Git-Tag: v1.5a3~180 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e2525fd3cb841cf4850a81c7bb95e97230c6964;p=python Patch by Lars Wirzenius to allow f.readline(length). --- diff --git a/Lib/StringIO.py b/Lib/StringIO.py index bbd9428541..dba38e42c0 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -64,7 +64,7 @@ class StringIO: r = self.buf[self.pos:newpos] self.pos = newpos return r - def readline(self): + def readline(self, length=None): if self.buflist: self.buf = self.buf + string.joinfields(self.buflist, '') self.buflist = [] @@ -73,6 +73,9 @@ class StringIO: newpos = self.len else: newpos = i+1 + if length is not None: + if self.pos + length < newpos: + newpos = self.pos + length r = self.buf[self.pos:newpos] self.pos = newpos return r