Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
py3: a few miscellaneous bytes/str fixes in sage.repl
Browse files Browse the repository at this point in the history
  • Loading branch information
embray committed Apr 17, 2018
1 parent 56be384 commit 94797e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/sage/repl/display/jsmol_iframe.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/repl/image.py
Expand Up @@ -32,6 +32,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import io

import PIL.Image
from sage.structure.sage_object import SageObject
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 94797e4

Please sign in to comment.