summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-03-03 08:17:42 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-03-03 08:17:42 (GMT)
commitdf24153f650f39ca82db143cc4a58062412a0896 (patch)
treeef25511e9b65ed1ef05a0848ef456d4e728f565f /Lib/tarfile.py
parent8ed338ab44daf3cd681d73156fd1d9b6bed53795 (diff)
downloadcpython-df24153f650f39ca82db143cc4a58062412a0896.zip
cpython-df24153f650f39ca82db143cc4a58062412a0896.tar.gz
cpython-df24153f650f39ca82db143cc4a58062412a0896.tar.bz2
Patch #1107973: tarfile.ExFileObject iterators.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 9d00615..9bfad25 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -616,6 +616,22 @@ class ExFileObject(object):
"""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
#------------------