summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index e33b982..d49e82f 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