| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7f4f644 commit 7fdae0a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,17 +2,19 @@ | |||
| 2 | 2 | A PostScript backend, which can produce both PostScript .ps and .eps | |
| 3 | 3 | """ | |
| 4 | 4 | ||
| 5 | + # PY3KTODO: Get rid of "print >>fh" syntax | ||
| 6 | + | ||
| 5 | 7 | from __future__ import division | |
| 6 | 8 | import glob, math, os, shutil, sys, time | |
| 7 | 9 | def _fn_name(): return sys._getframe(1).f_code.co_name | |
| 10 | + import io | ||
| 8 | 11 | ||
| 9 | 12 | try: | |
| 10 | 13 | from hashlib import md5 | |
| 11 | 14 | except ImportError: | |
| 12 | 15 | from md5 import md5 #Deprecated in 2.5 | |
| 13 | 16 | ||
| 14 | 17 | from tempfile import mkstemp | |
| 15 | - from cStringIO import StringIO | ||
| 16 | 18 | from matplotlib import verbose, __version__, rcParams | |
| 17 | 19 | from matplotlib._pylab_helpers import Gcf | |
| 18 | 20 | from matplotlib.afm import AFM | |
@@ -322,7 +324,7 @@ def _get_font_afm(self, prop): | |||
| 322 | 324 | "Helvetica", fontext='afm', directory=self._afm_font_dir) | |
| 323 | 325 | font = self.afmfontd.get(fname) | |
| 324 | 326 | if font is None: | |
| 325 | - font = AFM(file(fname)) | ||
| 327 | + font = AFM(open(fname, 'rb')) | ||
| 326 | 328 | self.afmfontd[fname] = font | |
| 327 | 329 | self.afmfontd[key] = font | |
| 328 | 330 | return font | |
@@ -945,7 +947,8 @@ def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w', | |||
| 945 | 947 | raise ValueError("outfile must be a path or a file-like object") | |
| 946 | 948 | ||
| 947 | 949 | fd, tmpfile = mkstemp() | |
| 948 | - fh = os.fdopen(fd, 'w') | ||
| 950 | + raw_fh = os.fdopen(fd, 'wb') | ||
| 951 | + fh = io.TextIOWrapper(raw_fh, encoding="ascii") | ||
| 949 | 952 | ||
| 950 | 953 | # find the appropriate papertype | |
| 951 | 954 | width, height = self.figure.get_size_inches() | |
@@ -998,7 +1001,7 @@ def write(self, *kl, **kwargs): | |||
| 998 | 1001 | ||
| 999 | 1002 | self._pswriter = NullWriter() | |
| 1000 | 1003 | else: | |
| 1001 | - self._pswriter = StringIO() | ||
| 1004 | + self._pswriter = io.StringIO() | ||
| 1002 | 1005 | ||
| 1003 | 1006 | ||
| 1004 | 1007 | # mixed mode rendering | |
@@ -1064,7 +1067,8 @@ def write(self, *kl, **kwargs): | |||
| 1064 | 1067 | if is_opentype_cff_font(font_filename): | |
| 1065 | 1068 | raise RuntimeError("OpenType CFF fonts can not be saved using the internal Postscript backend at this time.\nConsider using the Cairo backend.") | |
| 1066 | 1069 | else: | |
| 1067 | - convert_ttf_to_ps(font_filename, fh, fonttype, glyph_ids) | ||
| 1070 | + fh.flush() | ||
| 1071 | + convert_ttf_to_ps(font_filename, raw_fh, fonttype, glyph_ids) | ||
| 1068 | 1072 | print >>fh, "end" | |
| 1069 | 1073 | print >>fh, "%%EndProlog" | |
| 1070 | 1074 | ||
@@ -1091,7 +1095,7 @@ def write(self, *kl, **kwargs): | |||
| 1091 | 1095 | xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox) | |
| 1092 | 1096 | ||
| 1093 | 1097 | if passed_in_file_object: | |
| 1094 | - fh = open(tmpfile) | ||
| 1098 | + fh = open(tmpfile, 'rb') | ||
| 1095 | 1099 | print >>outfile, fh.read() | |
| 1096 | 1100 | else: | |
| 1097 | 1101 | open(outfile, 'w') | |
@@ -1112,7 +1116,7 @@ def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor, | |||
| 1112 | 1116 | ||
| 1113 | 1117 | # write to a temp file, we'll move it to outfile when done | |
| 1114 | 1118 | fd, tmpfile = mkstemp() | |
| 1115 | - fh = os.fdopen(fd, 'w') | ||
| 1119 | + fh = io.fdopen(fd, 'w', encoding='ascii') | ||
| 1116 | 1120 | ||
| 1117 | 1121 | self.figure.dpi = 72 # ignore the dpi kwarg | |
| 1118 | 1122 | width, height = self.figure.get_size_inches() | |
@@ -1239,10 +1243,10 @@ def write(self, *kl, **kwargs): | |||
| 1239 | 1243 | rotated=psfrag_rotated) | |
| 1240 | 1244 | ||
| 1241 | 1245 | if isinstance(outfile, file): | |
| 1242 | - fh = file(tmpfile) | ||
| 1243 | - print >>outfile, fh.read() | ||
| 1246 | + fh = open(tmpfile, 'rb') | ||
| 1247 | + outfile.write(fh.read()) | ||
| 1244 | 1248 | else: | |
| 1245 | - open(outfile, 'w') | ||
| 1249 | + open(outfile, 'wb') | ||
| 1246 | 1250 | mode = os.stat(outfile).st_mode | |
| 1247 | 1251 | shutil.move(tmpfile, outfile) | |
| 1248 | 1252 | os.chmod(outfile, mode) | |
@@ -1261,7 +1265,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble, | |||
| 1261 | 1265 | shutil.move(tmpfile, epsfile) | |
| 1262 | 1266 | latexfile = tmpfile+'.tex' | |
| 1263 | 1267 | outfile = tmpfile+'.output' | |
| 1264 | - latexh = file(latexfile, 'w') | ||
| 1268 | + latexh = io.open(latexfile, 'w', encoding='ascii') | ||
| 1265 | 1269 | dvifile = tmpfile+'.dvi' | |
| 1266 | 1270 | psfile = tmpfile+'.ps' | |
| 1267 | 1271 | ||
@@ -1316,7 +1320,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble, | |||
| 1316 | 1320 | %(precmd, tmpdir, latexfile, outfile) | |
| 1317 | 1321 | verbose.report(command, 'debug') | |
| 1318 | 1322 | exit_status = os.system(command) | |
| 1319 | - fh = file(outfile) | ||
| 1323 | + fh = io.open(outfile, 'rb') | ||
| 1320 | 1324 | if exit_status: | |
| 1321 | 1325 | raise RuntimeError('LaTeX was not able to process your file:\ | |
| 1322 | 1326 | \nHere is the full report generated by LaTeX: \n\n%s'% fh.read()) | |
@@ -1328,7 +1332,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble, | |||
| 1328 | 1332 | os.path.split(psfile)[-1], os.path.split(dvifile)[-1], outfile) | |
| 1329 | 1333 | verbose.report(command, 'debug') | |
| 1330 | 1334 | exit_status = os.system(command) | |
| 1331 | - fh = file(outfile) | ||
| 1335 | + fh = io.open(outfile, 'rb') | ||
| 1332 | 1336 | if exit_status: raise RuntimeError('dvips was not able to \ | |
| 1333 | 1337 | process the following file:\n%s\nHere is the full report generated by dvips: \ | |
| 1334 | 1338 | \n\n'% dvifile + fh.read()) | |
@@ -1376,7 +1380,7 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False): | |||
| 1376 | 1380 | "%s" > "%s"'% (gs_exe, dpi, paper_option, psfile, tmpfile, outfile) | |
| 1377 | 1381 | verbose.report(command, 'debug') | |
| 1378 | 1382 | exit_status = os.system(command) | |
| 1379 | - fh = file(outfile) | ||
| 1383 | + fh = io.open(outfile, 'rb') | ||
| 1380 | 1384 | if exit_status: raise RuntimeError('ghostscript was not able to process \ | |
| 1381 | 1385 | your image.\nHere is the full report generated by ghostscript:\n\n' + fh.read()) | |
| 1382 | 1386 | else: verbose.report(fh.read(), 'debug') | |
@@ -1406,7 +1410,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False): | |||
| 1406 | 1410 | if sys.platform == 'win32': command = command.replace('=', '#') | |
| 1407 | 1411 | verbose.report(command, 'debug') | |
| 1408 | 1412 | exit_status = os.system(command) | |
| 1409 | - fh = file(outfile) | ||
| 1413 | + fh = io.open(outfile, 'rb') | ||
| 1410 | 1414 | if exit_status: raise RuntimeError('ps2pdf was not able to process your \ | |
| 1411 | 1415 | image.\n\Here is the report generated by ghostscript:\n\n' + fh.read()) | |
| 1412 | 1416 | else: verbose.report(fh.read(), 'debug') | |
@@ -1416,7 +1420,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False): | |||
| 1416 | 1420 | (pdffile, psfile, outfile) | |
| 1417 | 1421 | verbose.report(command, 'debug') | |
| 1418 | 1422 | exit_status = os.system(command) | |
| 1419 | - fh = file(outfile) | ||
| 1423 | + fh = io.open(outfile, 'rb') | ||
| 1420 | 1424 | if exit_status: raise RuntimeError('pdftops was not able to process your \ | |
| 1421 | 1425 | image.\nHere is the full report generated by pdftops: \n\n' + fh.read()) | |
| 1422 | 1426 | else: verbose.report(fh.read(), 'debug') | |
@@ -1499,9 +1503,9 @@ def pstoeps(tmpfile, bbox, rotated=False): | |||
| 1499 | 1503 | bbox_info, rotate = get_bbox_header(bbox, rotated=rotated) | |
| 1500 | 1504 | ||
| 1501 | 1505 | epsfile = tmpfile + '.eps' | |
| 1502 | - epsh = file(epsfile, 'w') | ||
| 1506 | + epsh = io.open(epsfile, 'w', encoding='ascii') | ||
| 1503 | 1507 | ||
| 1504 | - tmph = file(tmpfile) | ||
| 1508 | + tmph = io.open(tmpfile, 'r', encoding='ascii') | ||
| 1505 | 1509 | line = tmph.readline() | |
| 1506 | 1510 | # Modify the header: | |
| 1507 | 1511 | while line: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,11 @@ class PythonFileWriter : public TTStreamWriter | |||
| 48 | 48 | PyObject* result = NULL; | |
| 49 | 49 | if (_write_method) | |
| 50 | 50 | { | |
| 51 | + #if PY3K | ||
| 52 | + result = PyObject_CallFunction(_write_method, (char *)"y", a); | ||
| 53 | + #else | ||
| 51 | 54 | result = PyObject_CallFunction(_write_method, (char *)"s", a); | |
| 55 | + #endif | ||
| 52 | 56 | if (! result) | |
| 53 | 57 | { | |
| 54 | 58 | throw PythonExceptionOccurred(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments