diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-29 23:49:49 +0000 |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-29 23:49:49 +0000 |
| commit | e1eca4e3f58bc221cea828a58a27088bc9258157 (patch) | |
| tree | 7b5885aa5871819997df93be6a760612f1528203 /Lib/tarfile.py | |
| parent | 749afa95ce28ffded9c6f75c776dae15cade6ecb (diff) | |
| download | cpython-git-e1eca4e3f58bc221cea828a58a27088bc9258157.tar.gz | |
Issue #10233: Close file objects in a timely manner in the tarfile module
and its test suite.
Diffstat (limited to 'Lib/tarfile.py')
| -rw-r--r-- | Lib/tarfile.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index e33b982081..d49e82ff4a 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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 |
