summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-18 14:14:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-18 14:14:49 (GMT)
commitaee0e63ed052ae891e4b5f342aae512787098fa4 (patch)
tree5c9b8a65a85398af239317bb84264f6141c7d439 /Lib/tarfile.py
parent7d68a1c921bb53c5b72fc7a884fc048185001f2c (diff)
parentc2d01423e02d9721f897812cf6a93e64c7d75c15 (diff)
downloadcpython-aee0e63ed052ae891e4b5f342aae512787098fa4.zip
cpython-aee0e63ed052ae891e4b5f342aae512787098fa4.tar.gz
cpython-aee0e63ed052ae891e4b5f342aae512787098fa4.tar.bz2
Issue #20243: TarFile no longer raise ReadError when opened in write mode.
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-xLib/tarfile.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index ec8af06..d914485 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1604,19 +1604,22 @@ class TarFile(object):
except (ImportError, AttributeError):
raise CompressionError("gzip module is not available")
- extfileobj = fileobj is not None
try:
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
+ except OSError:
+ if fileobj is not None and mode == 'r':
+ raise ReadError("not a gzip file")
+ raise
+
+ try:
t = cls.taropen(name, mode, fileobj, **kwargs)
except OSError:
- if not extfileobj and fileobj is not None:
- fileobj.close()
- if fileobj is None:
- raise
- raise ReadError("not a gzip file")
+ fileobj.close()
+ if mode == 'r':
+ raise ReadError("not a gzip file")
+ raise
except:
- if not extfileobj and fileobj is not None:
- fileobj.close()
+ fileobj.close()
raise
t._extfileobj = False
return t
@@ -1641,7 +1644,9 @@ class TarFile(object):
t = cls.taropen(name, mode, fileobj, **kwargs)
except (OSError, EOFError):
fileobj.close()
- raise ReadError("not a bzip2 file")
+ if mode == 'r':
+ raise ReadError("not a bzip2 file")
+ raise
t._extfileobj = False
return t
@@ -1664,7 +1669,9 @@ class TarFile(object):
t = cls.taropen(name, mode, fileobj, **kwargs)
except (lzma.LZMAError, EOFError):
fileobj.close()
- raise ReadError("not an lzma file")
+ if mode == 'r':
+ raise ReadError("not an lzma file")
+ raise
t._extfileobj = False
return t