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: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e2525fd3cb841cf4850a81c7bb95e97230c6964;p=thirdparty%2FPython%2Fcpython.git Patch by Lars Wirzenius to allow f.readline(length). --- diff --git a/Lib/StringIO.py b/Lib/StringIO.py index bbd942854139..dba38e42c0a0 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