matplotlib/matplotlib — pull request #3893 by cgohlke (2014-12-04 21:31:50+00:00)
Title: Don't close GzipFile before it is used

Fixes issue #1883 for me on Windows.

Consider the code at :
```Python
if format == 'svgz':
filename = fo
if is_string_like(fo):
fo = open(fo, 'wb')
close = True
else:
close = False
try:
fo = gzip.GzipFile(None, 'wb', fileobj=fo)
finally:
if close:
fo.close()
```

In case the GzipFile is created from the open file created with `fo = open(fo, 'wb')`:
1) The GzipFile is always closed in the finally clause. Even though the GzipFile is closed, the open file passed to GzipFile as fileobj stays open. Later writes will be uncompressed (see ). Does this produce valid svgz files?
2) When the GzipFile is closed there is no reference to the open file left. Python can/will close the file at any time. Maybe that is the reason why on Windows the file is closed while on Linux it is still open.

The proposed changes should close all GzipFile and open file instances when/if necessary.