Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c02a515

Browse files
committed
Merge pull request #3893 from cgohlke/patch-1
BUG : Don't close GzipFile before it is used
1 parent 5876c02 commit c02a515

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
@@ -482,17 +482,10 @@ def _save (self, fo, format, **kwargs):
482482
raise RuntimeError ('cairo has not been compiled with SVG '
483483
'support enabled')
484484
if format == 'svgz':
485-
filename = fo
486485
if is_string_like(fo):
487-
fo = open(fo, 'wb')
488-
close = True
486+
fo = gzip.GzipFile(fo, 'wb')
489487
else:
490-
close = False
491-
try:
492488
fo = gzip.GzipFile(None, 'wb', fileobj=fo)
493-
finally:
494-
if close:
495-
fo.close()
496489
surface = cairo.SVGSurface (fo, width_in_points, height_in_points)
497490
else:
498491
warnings.warn ("unknown format: %s" % format)
@@ -530,6 +523,8 @@ def _save (self, fo, format, **kwargs):
530523

531524
ctx.show_page()
532525
surface.finish()
526+
if format == 'svgz':
527+
fo.close()
533528

534529

535530
FigureCanvas = FigureCanvasCairo

0 commit comments

Comments
 (0)