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. |