This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author da
Recipients da
Date 2018-03-10.00:46:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520642770.84.0.467229070634.issue33038@psf.upfronthosting.co.za>
In-reply-to
Content
The Python documentation states that if the GzipFile can't determine a filename from `fileobj` it'll use an empty string and won't be included in the header. Unfortunately, this doesn't work for SpooledTemporaryFile which has a `name` attribute but doesn't set it initially. The result is a crash.

To reproduce

```
import gzip
import tempfile

with tempfile.SpooledTemporaryFile() as fd:
    with gzip.GzipFile(mode='wb', fileobj=fd) as gz:
        gz.write(b'asdf')
```

Result:
```
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/gzip.py", line 136, in __init__
    self._write_gzip_header()
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/gzip.py", line 170, in _write_gzip_header
    fname = os.path.basename(self.name)
  File "/Users/diegoargueta/.pyenv/versions/gds27/lib/python2.7/posixpath.py", line 114, in basename
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'
```

This doesn't happen on Python 3.6, where the null filename is handled properly. I've attached a patch file that fixed the issue for me.
History
Date User Action Args
2018-03-10 00:46:11dasetrecipients: + da
2018-03-10 00:46:10dasetmessageid: <1520642770.84.0.467229070634.issue33038@psf.upfronthosting.co.za>
2018-03-10 00:46:10dalinkissue33038 messages
2018-03-10 00:46:10dacreate