Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar

file with compression before trying to open it without compression.  Otherwise
it had 50% chance failed with ignore_zeros=True.
This commit is contained in:
Serhiy Storchaka 2016-10-30 20:52:29 +02:00
parent d1af5effc2
commit a89d22aff3
3 changed files with 14 additions and 2 deletions

View file

@ -1549,7 +1549,9 @@ class TarFile(object):
if mode in ("r", "r:*"):
# Find out which *open() is appropriate for opening the file.
for comptype in cls.OPEN_METH:
def not_compressed(comptype):
return cls.OPEN_METH[comptype] == 'taropen'
for comptype in sorted(cls.OPEN_METH, key=not_compressed):
func = getattr(cls, cls.OPEN_METH[comptype])
if fileobj is not None:
saved_pos = fileobj.tell()