mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Backport from rev. 53161.
This commit is contained in:
parent
12e087a1b1
commit
f9a2c63c79
3 changed files with 16 additions and 0 deletions
|
@ -1133,9 +1133,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")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue