Skip to content

Commit

Permalink
Merge pull request Calysto#88 from minrk/text-output
Browse files Browse the repository at this point in the history
wrap output in TextOutput in ProcessMetaKernel
  • Loading branch information
dsblank committed Jan 16, 2016
2 parents 2892498 + 89d6d36 commit 1e8d803
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions metakernel/process_metakernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import
from . import MetaKernel
from .pexpect import EOF
from .replwrap import REPLWrapper, u, PY3
from .replwrap import REPLWrapper, u
from subprocess import check_output
import os
import re
Expand All @@ -11,6 +11,18 @@
version_pat = re.compile(r'version (\d+(\.\d+)+)')


class TextOutput(object):
"""Wrapper for text output whose repr is the text itself.
This avoids `repr(output)` adding quotation marks around already-rendered text.
"""
def __init__(self, output):
self.output = output

def __repr__(self):
return self.output


class ProcessMetaKernel(MetaKernel):
implementation = 'process_kernel'
implementation_version = __version__
Expand Down Expand Up @@ -38,7 +50,6 @@ def banner(self):
def __init__(self, **kwargs):
MetaKernel.__init__(self, **kwargs)
self.wrapper = None
self.repr = str if PY3 else lambda x: x.encode('utf-8')
self._start()

def _start(self):
Expand Down Expand Up @@ -91,7 +102,7 @@ def do_execute_direct(self, code, stream_handler=None):
'execution_count': self.execution_count,
'payload': [], 'user_expressions': {}}

return output
return TextOutput(output)

def check_exitcode(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions metakernel/tests/test_process_metakernel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from IPython.display import HTML

from metakernel.tests.utils import get_kernel, get_log_text
from metakernel.process_metakernel import BashKernel

Expand All @@ -17,3 +19,6 @@ def test_process_metakernel():
kernel.do_execute('lalkjds')
text = get_log_text(kernel)
assert ': command not found' in text, text

html = HTML("some html")
kernel.Display(html)

0 comments on commit 1e8d803

Please sign in to comment.