*** tarfile.py.orig Sun Jan 23 14:26:41 2005 --- tarfile.py Sun Jan 23 14:29:44 2005 *************** *** 616,621 **** --- 616,637 ---- """Close the file object. """ self.closed = True + + def __iter__(self): + """Get an iterator over the file object. + """ + if self.closed: + raise ValueError("I/O operation on closed file") + return self + + def next(self): + """Get the next item from the file iterator. + """ + result = self.readline() + if not result: + raise StopIteration + return result + #class ExFileObject #------------------ *** test_tarfile.py.orig Sun Jan 23 14:55:53 2005 --- test_tarfile.py Sun Jan 23 14:34:07 2005 *************** *** 91,96 **** --- 91,106 ---- self.assert_(lines1 == lines2, "_FileObject.readline() does not work correctly") + def test_iter(self): + # Test iteration over ExFileObject. + if self.sep != "|": + filename = "0-REGTYPE-TEXT" + self.tar.extract(filename, dirname()) + lines1 = file(os.path.join(dirname(), filename), "rU").readlines() + lines2 = [line for line in self.tar.extractfile(filename)] + self.assert_(lines1 == lines2, + "ExFileObject iteration does not work correctly") + def test_seek(self): """Test seek() method of _FileObject, incl. random reading. """