Add next() and __iter__() methods to StreamReader, StreamReaderWriter

and StreamRecoder.

This closes SF bug #634246.
This commit is contained in:
Walter Dörwald 2002-11-06 16:53:44 +00:00
parent 07e147667c
commit 4dbf192f2b
2 changed files with 30 additions and 0 deletions

View File

@ -299,6 +299,17 @@ class StreamReader(Codec):
"""
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 @@ class StreamReaderWriter:
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 @@ class StreamRecoder:
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)

View File

@ -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