Skip to content

Commit 42c77be

Browse files
committed
Make SVG work with a StringIO object on Python 2.x
1 parent e4893f5 commit 42c77be

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import division
22

3-
import os, base64, tempfile, urllib, gzip, io, sys
3+
import os, base64, tempfile, urllib, gzip, io, sys, codecs
44

55
import numpy as np
66

@@ -1064,7 +1064,11 @@ def print_svg(self, filename, *args, **kwargs):
10641064
if is_string_like(filename):
10651065
fh_to_close = svgwriter = io.open(filename, 'w', encoding='utf-8')
10661066
elif is_writable_file_like(filename):
1067-
svgwriter = io.TextIOWrapper(filename, 'utf-8')
1067+
if not isinstance(filename, io.TextIOBase):
1068+
if sys.version_info[0] >= 3:
1069+
svgwriter = io.TextIOWrapper(filename, 'utf-8')
1070+
else:
1071+
svgwriter = codecs.EncodedFile(filename, 'utf-8')
10681072
fh_to_close = None
10691073
else:
10701074
raise ValueError("filename must be a path or a file-like object")

0 commit comments

Comments
 (0)