Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.

Will backport to 2.5.
This commit is contained in:
Lars Gustäbel 2006-12-27 10:30:46 +00:00
parent 7166232399
commit a7ba6fc548
3 changed files with 17 additions and 0 deletions

View file

@ -1141,9 +1141,13 @@ class TarFile(object):
# Find out which *open() is appropriate for opening the file.
for comptype in cls.OPEN_METH:
func = getattr(cls, cls.OPEN_METH[comptype])
if fileobj is not None:
saved_pos = fileobj.tell()
try:
return func(name, "r", fileobj)
except (ReadError, CompressionError):
if fileobj is not None:
fileobj.seek(saved_pos)
continue
raise ReadError("file could not be opened successfully")