Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4dbf192

Browse files
committed
Add next() and __iter__() methods to StreamReader, StreamReaderWriter
and StreamRecoder. This closes SF bug #634246.
1 parent 07e1476 commit 4dbf192

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lib/codecs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ def reset(self):
299299
"""
300300
pass
301301

302+
def next(self):
303+
304+
""" Return the next decoded line from the input stream."""
305+
line = self.readline()
306+
if line:
307+
return line
308+
raise StopIteration
309+
310+
def __iter__(self):
311+
return self
312+
302313
def __getattr__(self, name,
303314
getattr=getattr):
304315

@@ -351,6 +362,14 @@ def readlines(self, sizehint=None):
351362

352363
return self.reader.readlines(sizehint)
353364

365+
def next(self):
366+
367+
""" Return the next decoded line from the input stream."""
368+
return self.reader.next()
369+
370+
def __iter__(self):
371+
return self
372+
354373
def write(self, data):
355374

356375
return self.writer.write(data)
@@ -451,6 +470,14 @@ def readlines(self, sizehint=None):
451470
data, bytesencoded = self.encode(data, self.errors)
452471
return data.splitlines(1)
453472

473+
def next(self):
474+
475+
""" Return the next decoded line from the input stream."""
476+
return self.reader.next()
477+
478+
def __iter__(self):
479+
return self
480+
454481
def write(self, data):
455482

456483
data, bytesdecoded = self.decode(data, self.errors)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ Extension modules
362362
Library
363363
-------
364364

365+
- StreamReader, StreamReaderWriter and StreamRecoder in the codecs
366+
modules are iterators now.
367+
365368
- gzip.py now handles files exceeding 2GB. Files over 4GB also work
366369
now (provided the OS supports it, and Python is configured with large
367370
file support), but in that case the underlying gzip file format can

0 commit comments

Comments
 (0)