Skip to content

Commit edd4f86

Browse files
committed
Merge pull request matplotlib#3893 from cgohlke/patch-1
BUG : Don't close GzipFile before it is used
2 parents 2d14bfc + e8cbace commit edd4f86

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,10 @@ def _save (self, fo, format, **kwargs):
475475
raise RuntimeError ('cairo has not been compiled with SVG '
476476
'support enabled')
477477
if format == 'svgz':
478-
filename = fo
479478
if is_string_like(fo):
480-
fo = open(fo, 'wb')
481-
close = True
479+
fo = gzip.GzipFile(fo, 'wb')
482480
else:
483-
close = False
484-
try:
485481
fo = gzip.GzipFile(None, 'wb', fileobj=fo)
486-
finally:
487-
if close:
488-
fo.close()
489482
surface = cairo.SVGSurface (fo, width_in_points, height_in_points)
490483
else:
491484
warnings.warn ("unknown format: %s" % format)
@@ -523,6 +516,8 @@ def _save (self, fo, format, **kwargs):
523516

524517
ctx.show_page()
525518
surface.finish()
519+
if format == 'svgz':
520+
fo.close()
526521

527522

528523
FigureCanvas = FigureCanvasCairo

0 commit comments

Comments
 (0)