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
afe5f633
Commit
afe5f633
authored
May 09, 2018
by
Bo Bayles
Committed by
Serhiy Storchaka
May 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)
parent
d7e783b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/gzip.py
Lib/gzip.py
+2
-3
Lib/test/test_gzip.py
Lib/test/test_gzip.py
+15
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst
...S.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst
+2
-0
No files found.
Lib/gzip.py
View file @
afe5f633
...
...
@@ -95,9 +95,8 @@ class GzipFile(io.BufferedIOBase):
if
filename
is
None
:
# Issue #13781: os.fdopen() creates a fileobj with a bogus name
# attribute. Avoid saving this in the gzip header's filename field.
if
hasattr
(
fileobj
,
'name'
)
and
fileobj
.
name
!=
'<fdopen>'
:
filename
=
fileobj
.
name
else
:
filename
=
getattr
(
fileobj
,
'name'
,
''
)
if
not
isinstance
(
filename
,
basestring
)
or
filename
==
'<fdopen>'
:
filename
=
''
if
mode
is
None
:
if
hasattr
(
fileobj
,
'mode'
):
mode
=
fileobj
.
mode
...
...
Lib/test/test_gzip.py
View file @
afe5f633
...
...
@@ -6,6 +6,7 @@ from test import test_support
import
os
import
io
import
struct
import
tempfile
gzip
=
test_support
.
import_module
(
'gzip'
)
data1
=
""" int length=DEFAULTALLOC, err = Z_OK;
...
...
@@ -331,6 +332,12 @@ class TestGzip(unittest.TestCase):
with
gzip
.
GzipFile
(
fileobj
=
f
,
mode
=
"w"
)
as
g
:
self
.
assertEqual
(
g
.
name
,
""
)
def
test_fileobj_from_io_open
(
self
):
fd
=
os
.
open
(
self
.
filename
,
os
.
O_WRONLY
|
os
.
O_CREAT
)
with
io
.
open
(
fd
,
"wb"
)
as
f
:
with
gzip
.
GzipFile
(
fileobj
=
f
,
mode
=
"w"
)
as
g
:
self
.
assertEqual
(
g
.
name
,
""
)
def
test_fileobj_mode
(
self
):
gzip
.
GzipFile
(
self
.
filename
,
"wb"
).
close
()
with
open
(
self
.
filename
,
"r+b"
)
as
f
:
...
...
@@ -359,6 +366,14 @@ class TestGzip(unittest.TestCase):
with
gzip
.
GzipFile
(
fileobj
=
io
.
BytesIO
(
gzdata
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
b'Test'
)
def
test_fileobj_without_name
(
self
):
# Issue #33038: GzipFile should not assume that file objects that have
# a .name attribute use a non-None value.
with
tempfile
.
SpooledTemporaryFile
()
as
f
:
with
gzip
.
GzipFile
(
fileobj
=
f
,
mode
=
'wb'
)
as
archive
:
archive
.
write
(
b'data'
)
self
.
assertEqual
(
archive
.
name
,
''
)
def
test_main
(
verbose
=
None
):
test_support
.
run_unittest
(
TestGzip
)
...
...
Misc/ACKS
View file @
afe5f633
...
...
@@ -94,6 +94,7 @@ Michael R Bax
Anthony Baxter
Mike Bayer
Samuel L. Bayer
Bo Bayles
Donald Beaudry
David Beazley
Carlo Beccarini
...
...
Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst
0 → 100644
View file @
afe5f633
gzip.GzipFile no longer produces an AttributeError exception when used with
a file object with a non-string name attribute. Patch by Bo Bayles.
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