]> granicus.if.org Git - python/commitdiff
Add next() and __iter__() methods to StreamReader, StreamReaderWriter
authorWalter Dörwald <walter@livinglogic.de>
Wed, 6 Nov 2002 16:53:44 +0000 (16:53 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 6 Nov 2002 16:53:44 +0000 (16:53 +0000)
and StreamRecoder.

This closes SF bug #634246.

Lib/codecs.py
Misc/NEWS

index 40f0a2e2262b30332a2611cda4ecba6fa397450f..0b43a72d709d083a5d65389bc9a599d0dbdc7ca8 100644 (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)
index cccaff546c3d5a1c2c7186b341756229c770aaa1..4fc52ea5694bd2b26d68f3917efd12d44dd4bdc1 100644 (file)
--- 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