mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
Issue #10233: Close file objects in a timely manner in the tarfile module
and its test suite.
This commit is contained in:
parent
749afa95ce
commit
e1eca4e3f5
3 changed files with 58 additions and 36 deletions
|
@ -1800,20 +1800,18 @@ class TarFile(object):
|
|||
except (ImportError, AttributeError):
|
||||
raise CompressionError("gzip module is not available")
|
||||
|
||||
if fileobj is None:
|
||||
fileobj = bltn_open(name, mode + "b")
|
||||
extfileobj = False
|
||||
else:
|
||||
extfileobj = True
|
||||
|
||||
extfileobj = fileobj is not None
|
||||
try:
|
||||
t = cls.taropen(name, mode,
|
||||
gzip.GzipFile(name, mode, compresslevel, fileobj),
|
||||
**kwargs)
|
||||
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
|
||||
t = cls.taropen(name, mode, fileobj, **kwargs)
|
||||
except IOError:
|
||||
if not extfileobj:
|
||||
fileobj.close()
|
||||
raise ReadError("not a gzip file")
|
||||
except:
|
||||
if not extfileobj:
|
||||
fileobj.close()
|
||||
raise
|
||||
t._extfileobj = extfileobj
|
||||
return t
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue