From ad341b48278b2664b5aef978b84416d8fb861f7b Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 7 Jan 2015 20:39:55 -0600 Subject: [PATCH 1/3] Fixes for file saving in webagg --- lib/matplotlib/backends/backend_webagg.py | 8 +++++++- lib/matplotlib/backends/backend_webagg_core.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py index 9583906ab2fe..16ef87b407a6 100644 --- a/lib/matplotlib/backends/backend_webagg.py +++ b/lib/matplotlib/backends/backend_webagg.py @@ -197,7 +197,13 @@ def get(self, fignum, fmt): self.set_header('Content-Type', mimetypes.get(fmt, 'binary')) - buff = io.BytesIO() + # override fileno to raise AttributeError so PIL doesn't error + class BytesIO(io.BytesIO): + @property + def fileno(self): + raise AttributeError + + buff = BytesIO() manager.canvas.print_figure(buff, format=fmt) self.write(buff.getvalue()) diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 8f971600d040..7a4bec1a325a 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -403,7 +403,8 @@ def get_javascript(cls, stream=None): for filetype, ext in sorted(FigureCanvasWebAggCore. get_supported_filetypes_grouped(). items()): - extensions.append(ext[0]) + if not ext[0] == 'pgf': # pgf does not support BytesIO + extensions.append(ext[0]) output.write("mpl.extensions = {0};\n\n".format( json.dumps(extensions))) From 2f20e82f764f511d80a8aca051a1ef5224fb9e04 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 7 Jan 2015 20:42:25 -0600 Subject: [PATCH 2/3] Update docstring --- lib/matplotlib/backends/backend_webagg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py index 16ef87b407a6..6f1003926035 100644 --- a/lib/matplotlib/backends/backend_webagg.py +++ b/lib/matplotlib/backends/backend_webagg.py @@ -197,7 +197,7 @@ def get(self, fignum, fmt): self.set_header('Content-Type', mimetypes.get(fmt, 'binary')) - # override fileno to raise AttributeError so PIL doesn't error + # override fileno to raise AttributeError to prevent PIL error class BytesIO(io.BytesIO): @property def fileno(self): From cdf50a5df50bce419158f7397424eb481c064316 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 7 Jan 2015 20:57:30 -0600 Subject: [PATCH 3/3] Use six.BytesIO rather than a monkey patch. --- lib/matplotlib/backends/backend_webagg.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py index 6f1003926035..fe0310787376 100644 --- a/lib/matplotlib/backends/backend_webagg.py +++ b/lib/matplotlib/backends/backend_webagg.py @@ -17,7 +17,6 @@ import datetime import errno -import io import json import os import random @@ -197,13 +196,7 @@ def get(self, fignum, fmt): self.set_header('Content-Type', mimetypes.get(fmt, 'binary')) - # override fileno to raise AttributeError to prevent PIL error - class BytesIO(io.BytesIO): - @property - def fileno(self): - raise AttributeError - - buff = BytesIO() + buff = six.BytesIO() manager.canvas.print_figure(buff, format=fmt) self.write(buff.getvalue())