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

Skip to content

Don't close GzipFile before it is used #3893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,10 @@ def _save (self, fo, format, **kwargs):
raise RuntimeError ('cairo has not been compiled with SVG '
'support enabled')
if format == 'svgz':
filename = fo
if is_string_like(fo):
fo = open(fo, 'wb')
close = True
fo = gzip.GzipFile(fo, 'wb')
else:
close = False
try:
fo = gzip.GzipFile(None, 'wb', fileobj=fo)
finally:
if close:
fo.close()
surface = cairo.SVGSurface (fo, width_in_points, height_in_points)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while you are tinkering around in here, could you fix this extraneous space?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, on second thought, I am seeing a bunch of them in this file... maybe it needs a separate PEP8 PR

else:
warnings.warn ("unknown format: %s" % format)
Expand Down Expand Up @@ -523,6 +516,8 @@ def _save (self, fo, format, **kwargs):

ctx.show_page()
surface.finish()
if format == 'svgz':
fo.close()


FigureCanvas = FigureCanvasCairo