Re: [Python-Dev] [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)
From: Serhiy Storchaka To: python-check...@python.org Sent: Wednesday, 9 May 2018, 10:14 Subject: [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095) https://github.com/python/cpython/commit/afe5f633e49e0e873d42088ae56819609c803ba0commit: afe5f633e49e0e873d42088ae56819609c803ba0branch: 2.7author: Bo Baylescommitter: Serhiy Storchaka date: 2018-05-09T13:14:40+03:00summary:bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)files:A Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstM Lib/gzip.pyM Lib/test/test_gzip.pyM Misc/ACKSdiff --git a/Lib/gzip.py b/Lib/gzip.pyindex 07c6db493b0b..76ace394f482 100644--- a/Lib/gzip.py+++ b/Lib/gzip.py@@ -95,9 +95,8 @@ def __init__(self, filename=None, mode=None, 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 != '':- filename = fileobj.name- else:+ filename = getattr(fileobj, 'name', '')+ if not isinstance(filename, basestring) or filename == '': filename = '' if mode is None: if hasattr(fileobj, 'mode'): mode = fileobj.modediff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.pyindex 902d93fe043f..cdb1af5c3d13 100644--- a/Lib/test/test_gzip.py+++ b/Lib/test/test_gzip.py@@ -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')+ self.assertEqual(archive.name, '')+ def test_main(verbose=None): test_support.run_unittest(TestGzip) diff --git a/Misc/ACKS b/Misc/ACKSindex 580b0c5bf76d..458f31e6a6b7 100644--- a/Misc/ACKS+++ b/Misc/ACKS@@ -94,6 +94,7 @@ Michael R Bax Anthony Baxter Mike Bayer Samuel L. Bayer+Bo Bayles Donald Beaudry David Beazley Carlo Beccarinidiff --git a/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstnew file mode 100644index ..22d394b85ab7--- /dev/null+++ b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst@@ -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.___Python-checkins mailing listpython-check...@python.orghttps://mail.python.org/mailman/listinfo/python-checkins___Python-Dev mailing listPython-Dev@python.orghttps://mail.python.org/mailman/listinfo/python-devUnsubscribe: https://mail.python.org/mailman/options/python-dev/nataliemorrisonxm980xm%40yahoo.com___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)
From: Serhiy Storchaka To: python-check...@python.org Sent: Wednesday, 9 May 2018, 10:14 Subject: [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095) https://github.com/python/cpython/commit/afe5f633e49e0e873d42088ae56819609c803ba0commit: afe5f633e49e0e873d42088ae56819609c803ba0branch: 2.7author: Bo Baylescommitter: Serhiy Storchaka date: 2018-05-09T13:14:40+03:00summary:bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)files:A Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstM Lib/gzip.pyM Lib/test/test_gzip.pyM Misc/ACKSdiff --git a/Lib/gzip.py b/Lib/gzip.pyindex 07c6db493b0b..76ace394f482 100644--- a/Lib/gzip.py+++ b/Lib/gzip.py@@ -95,9 +95,8 @@ def __init__(self, filename=None, mode=None, 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 != '':- filename = fileobj.name- else:+ filename = getattr(fileobj, 'name', '')+ if not isinstance(filename, basestring) or filename == '': filename = '' if mode is None: if hasattr(fileobj, 'mode'): mode = fileobj.modediff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.pyindex 902d93fe043f..cdb1af5c3d13 100644--- a/Lib/test/test_gzip.py+++ b/Lib/test/test_gzip.py@@ -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')+ self.assertEqual(archive.name, '')+ def test_main(verbose=None): test_support.run_unittest(TestGzip) diff --git a/Misc/ACKS b/Misc/ACKSindex 580b0c5bf76d..458f31e6a6b7 100644--- a/Misc/ACKS+++ b/Misc/ACKS@@ -94,6 +94,7 @@ Michael R Bax Anthony Baxter Mike Bayer Samuel L. Bayer+Bo Bayles Donald Beaudry David Beazley Carlo Beccarinidiff --git a/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstnew file mode 100644index ..22d394b85ab7--- /dev/null+++ b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst@@ -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.___Python-checkins mailing listpython-check...@python.orghttps://mail.python.org/mailman/listinfo/python-checkins___Python-Dev mailing listPython-Dev@python.orghttps://mail.python.org/mailman/listinfo/python-devUnsubscribe: https://mail.python.org/mailman/options/python-dev/nataliemorrisonxm980xm%40yahoo.com___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)
From: Serhiy Storchaka To: python-check...@python.org Sent: Wednesday, 9 May 2018, 10:14 Subject: [Python-checkins] bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095) https://github.com/python/cpython/commit/afe5f633e49e0e873d42088ae56819609c803ba0commit: afe5f633e49e0e873d42088ae56819609c803ba0branch: 2.7author: Bo Baylescommitter: Serhiy Storchaka date: 2018-05-09T13:14:40+03:00summary:bpo-33038: Fix gzip.GzipFile for file objects with a non-string name attribute. (GH-6095)files:A Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstM Lib/gzip.pyM Lib/test/test_gzip.pyM Misc/ACKSdiff --git a/Lib/gzip.py b/Lib/gzip.pyindex 07c6db493b0b..76ace394f482 100644--- a/Lib/gzip.py+++ b/Lib/gzip.py@@ -95,9 +95,8 @@ def __init__(self, filename=None, mode=None, 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 != '':- filename = fileobj.name- else:+ filename = getattr(fileobj, 'name', '')+ if not isinstance(filename, basestring) or filename == '': filename = '' if mode is None: if hasattr(fileobj, 'mode'): mode = fileobj.modediff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.pyindex 902d93fe043f..cdb1af5c3d13 100644--- a/Lib/test/test_gzip.py+++ b/Lib/test/test_gzip.py@@ -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')+ self.assertEqual(archive.name, '')+ def test_main(verbose=None): test_support.run_unittest(TestGzip) diff --git a/Misc/ACKS b/Misc/ACKSindex 580b0c5bf76d..458f31e6a6b7 100644--- a/Misc/ACKS+++ b/Misc/ACKS@@ -94,6 +94,7 @@ Michael R Bax Anthony Baxter Mike Bayer Samuel L. Bayer+Bo Bayles Donald Beaudry David Beazley Carlo Beccarinidiff --git a/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rstnew file mode 100644index ..22d394b85ab7--- /dev/null+++ b/Misc/NEWS.d/next/Library/2018-03-10-20-14-36.bpo-33038.yA6CP5.rst@@ -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.___Python-checkins mailing listpython-check...@python.orghttps://mail.python.org/mailman/listinfo/python-checkins___Python-Dev mailing listPython-Dev@python.orghttps://mail.python.org/mailman/listinfo/python-devUnsubscribe: https://mail.python.org/mailman/options/python-dev/nataliemorrisonxm980xm%40yahoo.com___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com