From 4dbf192f2b7d267636244de70faf8c5d78790655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Wed, 6 Nov 2002 16:53:44 +0000 Subject: [PATCH] Add next() and __iter__() methods to StreamReader, StreamReaderWriter and StreamRecoder. This closes SF bug #634246. --- Lib/codecs.py | 27 +++++++++++++++++++++++++++ Misc/NEWS | 3 +++ 2 files changed, 30 insertions(+) diff --git a/Lib/codecs.py b/Lib/codecs.py index 40f0a2e2262..0b43a72d709 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -299,6 +299,17 @@ def reset(self): """ pass + def next(self): + + """ Return the next decoded line from the input stream.""" + line = self.readline() + if line: + return line + raise StopIteration + + def __iter__(self): + return self + def __getattr__(self, name, getattr=getattr): @@ -351,6 +362,14 @@ def readlines(self, sizehint=None): return self.reader.readlines(sizehint) + def next(self): + + """ Return the next decoded line from the input stream.""" + return self.reader.next() + + def __iter__(self): + return self + def write(self, data): return self.writer.write(data) @@ -451,6 +470,14 @@ def readlines(self, sizehint=None): data, bytesencoded = self.encode(data, self.errors) return data.splitlines(1) + def next(self): + + """ Return the next decoded line from the input stream.""" + return self.reader.next() + + def __iter__(self): + return self + def write(self, data): data, bytesdecoded = self.decode(data, self.errors) diff --git a/Misc/NEWS b/Misc/NEWS index cccaff546c3..4fc52ea5694 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -362,6 +362,9 @@ Extension modules Library ------- +- StreamReader, StreamReaderWriter and StreamRecoder in the codecs + modules are iterators now. + - gzip.py now handles files exceeding 2GB. Files over 4GB also work now (provided the OS supports it, and Python is configured with large file support), but in that case the underlying gzip file format can