cpython: 1c6a1427353b (original) (raw)
Mercurial > cpython
changeset 83694:1c6a1427353b
Issue #16601: Restarting iteration over tarfile no more continues from where it left off. Patch by Michael Birtwell. [#16601]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Thu, 09 May 2013 14:36:58 +0300 |
parents | 375d4fed4cf2(current diff)9ed127d8ad61(diff) |
children | 489f075430de |
files | Lib/tarfile.py Lib/test/test_tarfile.py Misc/ACKS Misc/NEWS |
diffstat | 4 files changed, 19 insertions(+), 5 deletions(-)[+] [-] Lib/tarfile.py 12 Lib/test/test_tarfile.py 8 Misc/ACKS 1 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2397,16 +2397,18 @@ class TarIter: # Fix for SF #1100429: Under rare circumstances it can # happen that getmembers() is called during iteration, # which will cause TarIter to stop prematurely.
if not self.tarfile._loaded:[](#l1.7)
if self.index == 0 and self.tarfile.firstmember is not None:[](#l1.9)
tarinfo = self.tarfile.next()[](#l1.10)
elif self.index < len(self.tarfile.members):[](#l1.11)
tarinfo = self.tarfile.members[self.index][](#l1.12)
elif not self.tarfile._loaded:[](#l1.13) tarinfo = self.tarfile.next()[](#l1.14) if not tarinfo:[](#l1.15) self.tarfile._loaded = True[](#l1.16) raise StopIteration[](#l1.17) else:[](#l1.18)
try:[](#l1.19)
tarinfo = self.tarfile.members[self.index][](#l1.20)
except IndexError:[](#l1.21)
raise StopIteration[](#l1.22)
raise StopIteration[](#l1.23) self.index += 1[](#l1.24) return tarinfo[](#l1.25)
--- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -415,6 +415,14 @@ class MiscReadTest(CommonReadTest): finally: support.unlink(empty)
- def test_parallel_iteration(self):
# Issue #16601: Restarting iteration over tarfile continued[](#l2.8)
# from where it left off.[](#l2.9)
with tarfile.open(self.tarname) as tar:[](#l2.10)
for m1, m2 in zip(tar, tar):[](#l2.11)
self.assertEqual(m1.offset, m2.offset)[](#l2.12)
self.assertEqual(m1.get_info(), m2.get_info())[](#l2.13)
+ class StreamReadTest(CommonReadTest):
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -118,6 +118,7 @@ Adrian von Bidder David Binger Dominic Binks Philippe Biondi +Michael Birtwell Stuart Bishop Roy Bixler Daniel Black
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,9 @@ Core and Builtins Library ------- +- Issue #16601: Restarting iteration over tarfile no more continues from where