-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
[2.7] bpo-33038: gzip.GzipFile assumes non-None name attribute #6095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
abb9ca0
bpo-33038: gzip.GzipFile assumes non-None name attribute
bbayles 112b3ee
Note issue in test
bbayles 7be4b8d
Merge branch '2.7' into gzip-fileobj-name
bbayles dee6d1b
Merge branch '2.7' into gzip-fileobj-name
bbayles 639a871
Use Python 3-style workaround
bbayles 865bfa3
Add additional test for io.open(fd)
bbayles 7b4507e
Update NEWS item
bbayles ec55e8b
Add basestring
bbayles e74b9f8
Add additional assert in test
bbayles 8a259be
Add to Misc/ACKS
bbayles 006e588
All on one line
bbayles 7fac6c1
Mention file descriptor case
bbayles f2793e9
Merge branch '2.7' into gzip-fileobj-name
serhiy-storchaka b0f3fb1
Merge branch '2.7' into gzip-fileobj-name
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
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 @@ def test_fileobj_from_fdopen(self): | |
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 @@ def test_read_with_extra(self): | |
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add an assertion for |
||
self.assertEqual(archive.name, '') | ||
|
||
def test_main(verbose=None): | ||
test_support.run_unittest(TestGzip) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gzip.GzipFile no longer produces an AttributeError exception when used with | ||
a file object with a non-string name attribute. Patch by Bo Bayles. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to backport
test_fileobj_from_fdopen
from 3.x.And add a similar test with
fileobj=io.open(fd, 'wb')
instead offileobj=os.fdopen(fd, 'wb')
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. The only difference between 2.7's
test_fileobj_from_fdopen
and 3.7's is the assert:2.7
3.7
Could you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right then.