From 94797e43e8dcd21fc6d92729c07537060ec76155 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Mon, 16 Apr 2018 12:19:58 +0000 Subject: [PATCH] py3: a few miscellaneous bytes/str fixes in sage.repl --- src/sage/repl/display/jsmol_iframe.py | 26 +++++++++++++------------- src/sage/repl/image.py | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/sage/repl/display/jsmol_iframe.py b/src/sage/repl/display/jsmol_iframe.py index b664bc6897b..5d9aacde610 100644 --- a/src/sage/repl/display/jsmol_iframe.py +++ b/src/sage/repl/display/jsmol_iframe.py @@ -19,10 +19,11 @@ discussion of loading JSMol. """ +import io import os import zipfile -from six import StringIO +from sage.cpython.string import bytes_to_str from sage.env import SAGE_LOCAL from sage.structure.sage_object import SageObject from sage.misc.cachefunc import cached_method @@ -121,7 +122,7 @@ def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'): if not isinstance(jmol, OutputSceneJmol): jmol = jmol._rich_repr_jmol() self._jmol = jmol - self._zip = zipfile.ZipFile(StringIO(self._jmol.scene_zip.get())) + self._zip = zipfile.ZipFile(io.BytesIO(self._jmol.scene_zip.get())) if path_to_jsmol is None: self._path = os.path.join('/', 'nbextensions', 'jsmol') else: @@ -152,21 +153,20 @@ def script(self): script = [] with self._zip.open('SCRIPT') as SCRIPT: for line in SCRIPT: - if line.startswith('pmesh'): - command, obj, meshfile = line.split(' ', 3) - assert command == 'pmesh' - if meshfile not in ['dots\n', 'mesh\n']: - assert meshfile.startswith('"') and meshfile.endswith('"\n') + if line.startswith(b'pmesh'): + command, obj, meshfile = line.split(b' ', 3) + assert command == b'pmesh' + if meshfile not in [b'dots\n', b'mesh\n']: + assert (meshfile.startswith(b'"') and + meshfile.endswith(b'"\n')) meshfile = meshfile[1:-2] # strip quotes script += [ - 'pmesh {0} inline "'.format(obj), - self._zip.open(meshfile).read(), + 'pmesh {0} inline "'.format(bytes_to_str(obj)), + bytes_to_str(self._zip.open(meshfile).read()), '"\n' ] - else: - script += [line] - else: - script += [line] + continue + script += [bytes_to_str(line)] return ''.join(script) def js_script(self): diff --git a/src/sage/repl/image.py b/src/sage/repl/image.py index 702e45128e7..d7d00b00c80 100644 --- a/src/sage/repl/image.py +++ b/src/sage/repl/image.py @@ -32,6 +32,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +import io import PIL.Image from sage.structure.sage_object import SageObject @@ -293,11 +294,10 @@ def _rich_repr_(self, display_manager, **kwds): ('JPEG', types.OutputImageJpg), ('GIF', types.OutputImageGif), ) - from six import StringIO from sage.repl.rich_output.buffer import OutputBuffer for format, output_container in preferred: if output_container in display_manager.supported_output(): - stream = StringIO() + stream = io.BytesIO() try: self.pil.save(stream, format=format) except IOError: