Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
aee0e63e
Commit
aee0e63e
authored
Jan 18, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #20243: TarFile no longer raise ReadError when opened in write mode.
parents
7d68a1c9
c2d01423
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
10 deletions
+35
-10
Lib/tarfile.py
Lib/tarfile.py
+17
-10
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+16
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/tarfile.py
View file @
aee0e63e
...
...
@@ -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
...
...
Lib/test/test_tarfile.py
View file @
aee0e63e
...
...
@@ -1157,6 +1157,22 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
os
.
chdir
(
cwd
)
def
test_open_nonwritable_fileobj
(
self
):
for
exctype
in
OSError
,
EOFError
,
RuntimeError
:
class
BadFile
(
io
.
BytesIO
):
first
=
True
def
write
(
self
,
data
):
if
self
.
first
:
self
.
first
=
False
raise
exctype
f
=
BadFile
()
with
self
.
assertRaises
(
exctype
):
tar
=
tarfile
.
open
(
tmpname
,
self
.
mode
,
fileobj
=
f
,
format
=
tarfile
.
PAX_FORMAT
,
pax_headers
=
{
'non'
:
'empty'
})
self
.
assertFalse
(
f
.
closed
)
class
GzipWriteTest
(
GzipTest
,
WriteTest
):
pass
...
...
Misc/NEWS
View file @
aee0e63e
...
...
@@ -25,6 +25,8 @@ Core and Builtins
Library
-------
- Issue #20243: TarFile no longer raise ReadError when opened in write mode.
- Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn'
t
write
complete
output
on
close
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment