Skip to content

Commit ef7f818

Browse files
Fix PS backend for Python 2.x
1 parent 7fdae0a commit ef7f818

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import glob, math, os, shutil, sys, time
99
def _fn_name(): return sys._getframe(1).f_code.co_name
1010
import io
11+
if sys.version_info[0] < 3:
12+
import cStringIO
1113

1214
try:
1315
from hashlib import md5
@@ -947,8 +949,11 @@ def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
947949
raise ValueError("outfile must be a path or a file-like object")
948950

949951
fd, tmpfile = mkstemp()
950-
raw_fh = os.fdopen(fd, 'wb')
951-
fh = io.TextIOWrapper(raw_fh, encoding="ascii")
952+
raw_fh = io.open(fd, 'wb')
953+
if sys.version_info[0] >= 3:
954+
fh = io.TextIOWrapper(raw_fh, encoding="ascii")
955+
else:
956+
fh = raw_fh
952957

953958
# find the appropriate papertype
954959
width, height = self.figure.get_size_inches()
@@ -1001,7 +1006,10 @@ def write(self, *kl, **kwargs):
10011006

10021007
self._pswriter = NullWriter()
10031008
else:
1004-
self._pswriter = io.StringIO()
1009+
if sys.version_info[0] >= 3:
1010+
self._pswriter = io.StringIO()
1011+
else:
1012+
self._pswriter = cStringIO.StringIO()
10051013

10061014

10071015
# mixed mode rendering

0 commit comments

Comments
 (0)