output = self.smlnjwrapper.run_command(code, timeout=None) except KeyboardInterrupt: self.smlnjwrapper.child.sendintr() interrupted = True self.smlnjwrapper._expect_prompt() output = self.smlnjwrapper.child.before except EOF: output = self.smlnjwrapper.child.before + 'Restarting SML/NJ' self._start_smlnjang() if not silent: # Send standard output stream_content = {'name': 'stdout', 'text': output} self.send_response(self.iopub_socket, 'stream', stream_content) if interrupted: return {'status': 'abort', 'execution_count': self.execution_count} return { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {} } # ===== MAIN ===== if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=SMLNJKernel)
return self.do_execute_direct('help %s' % obj) def handle_plot_settings(self): """Handle the current plot settings""" settings = self.plot_settings settings.setdefault('size', '560,420') width, height = 560, 420 if isinstance(settings['size'], tuple): width, height = settings['size'] elif settings['size']: try: width, height = settings['size'].split(',') width, height = int(width), int(height) except Exception as e: self.Error(e) size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s])\n;" self.do_execute_direct(size % (width / 150., height / 150.)) def repr(self, obj): return obj def restart_kernel(self): """Restart the kernel""" self._matlab.stop() if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MatlabKernel)
from IPython.kernel.zmq.kernelbase import Kernel class NodeKernel(Kernel): implementation = "node-kernel" implementation_version = "test" language = "javascript" language_version = "test" banner = "test" def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): if not silent: stream_content = {'name': 'stdout', 'data':'hi!'} self.send_response(self.iopub_socket, 'stream', stream_content) return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=NodeKernel)
'data': { 'text/html': u'{}'.format(u'$$' + moutput.group(1) + u'$$') }, 'metadata': {} } self.send_response(self.iopub_socket, 'display_data', content) else: stream_content = { 'execution_count': self.execution_count, 'name': 'stdout', 'text': output } self.send_response(self.iopub_socket, 'stream', stream_content) if interrupted: return {'status': 'abort', 'execution_count': self.execution_count} return { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {} } # ===== MAIN ===== if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=EgisonKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import VirtuosoKernel IPKernelApp.launch_instance(kernel_class=VirtuosoKernel)
): self.continuation = False self.ignore_output() code = self.remove_continuations(code.strip()) mata_magic = re.match(r'\s*%%mata\s+', code) if mata_magic: code = 'mata\n' + code[mata_magic.end():] + '\nend\n' try: self.stata_do(' ' + code + '\n') self.respond() except KeyboardInterrupt: self.stata.UtilSetStataBreak() self.respond() return {'status': 'abort', 'execution_count': self.execution_count} msg = { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {} } return msg def do_shutdown(self, restart): self.stata_do(' exit, clear\n') if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=StataKernel)
class BrainfuckKernel(Kernel): implementation = 'brainfuck' implementation_version = '1.0' language = 'brainfuck' language_version = '0.1' language_info = {'mimetype': 'text/plain', 'name': 'brainfuck'} banner = "Brainfuck Kernel - it f***s with your brain" def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): if not silent: brainy = Brainy() brainy.eval(code) code_result = brainy.get_output() stream_content = {'name': 'stdout', 'text': code_result} self.send_response(self.iopub_socket, 'stream', stream_content) return {'status': 'ok', # The base class increments the execution count 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}, } if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BrainfuckKernel) else: from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BrainfuckKernel)
settings.setdefault('size', '560,420') width, height = 560, 420 if isinstance(settings['size'], tuple): width, height = settings['size'] elif settings['size']: try: width, height = settings['size'].split(',') width, height = int(width), int(height) except Exception as e: self.Error(e) size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s])\n;" self.do_execute_direct(size % (width / 150., height / 150.)) def repr(self, obj): return obj def restart_kernel(self): """Restart the kernel""" self._matlab.stop() def do_shutdown(self, restart): with open('test.txt', 'w') as fid: fid.write('hey hey\n') self._matlab.stop() if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MatlabKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import CalystoScheme IPKernelApp.launch_instance(kernel_class=CalystoScheme)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import NielsKernel IPKernelApp.launch_instance(kernel_class=NielsKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import SkulptPythonKernel IPKernelApp.launch_instance(kernel_class=SkulptPythonKernel)
def do_execute_direct(self, code): if not code.strip(): return self.log.debug('execute: %s' % code) shell_magic = self.line_magics['shell'] resp = shell_magic.eval(code.strip()) self.log.debug('execute done') return resp.strip() def get_completions(self, info): shell_magic = self.line_magics['shell'] return shell_magic.get_completions(info) def get_kernel_help_on(self, info, level=0, none_on_fail=False): code = info['code'].strip() if not code or len(code.split()) > 1: if none_on_fail: return None else: return "" shell_magic = self.line_magics['shell'] return shell_magic.get_help_on(info, level, none_on_fail) def repr(self, data): return data if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MetaKernelBash)
def get_variable(self, name): """ Get a variable from the kernel language. """ python_magic = self.line_magics['python'] return python_magic.env.get(name, None) def do_execute_direct(self, code): python_magic = self.line_magics['python'] return python_magic.eval(code.strip()) def do_function_direct(self, function_name, arg): """ Call a function in the kernel language with args (as a single item). """ python_magic = self.line_magics['python'] return python_magic.eval("%s(%s)" % (function_name, arg)) def get_completions(self, info): python_magic = self.line_magics['python'] return python_magic.get_completions(info) def get_kernel_help_on(self, info, level=0, none_on_fail=False): python_magic = self.line_magics['python'] return python_magic.get_help_on(info, level, none_on_fail) if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MetaKernelPython)
repl.expect('java>') banner = repl.before.decode('utf-8') def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): self.repl.sendline(re.sub(r'\s+', ' ', code, flags=re.MULTILINE)) self.repl.expect('java>') response = self.repl.before.decode('utf-8') if not silent: stream_content = { 'name': 'stdout', 'text': response.split('\n', 1)[1] } self.send_response(self.iopub_socket, 'stream', stream_content) return { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}, } if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=JavaKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from sage.repl.ipython_kernel.kernel import SageKernel IPKernelApp.launch_instance(kernel_class=SageKernel)
output = self.iowrapper.run_command(code, timeout=None) except KeyboardInterrupt: self.iowrapper.child.sendintr() interrupted = True self.iowrapper._expect_prompt() output = self.iowrapper.child.before except EOF: output = self.iowrapper.child.before + 'Restarting Io' self._start_io() if not silent: # Send standard output stream_content = {'name': 'stdout', 'text': output} self.send_response(self.iopub_socket, 'stream', stream_content) if interrupted: return {'status': 'abort', 'execution_count': self.execution_count} return { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {} } # ===== MAIN ===== if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=IoKernel)
implementation_version = '1.0' language = 'text' language_version = '0.1' banner = "MetaKernel Echo - as useful as a parrot" language_info = { 'mimetype': 'text/plain', 'name': 'text', # ------ If different from 'language': # 'codemirror_mode': { # "version": 2, # "name": "ipython" # } # 'pygments_lexer': 'language', # 'version' : "x.y.z", 'file_extension': '.txt', 'help_links': MetaKernel.help_links, } def get_usage(self): return "This is the echo kernel." def do_execute_direct(self, code): return code.rstrip() def repr(self, data): return repr(data) if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MetaKernelEcho)
line = '.' timeout = 3. while len(line) > 0 or timeout > 0.: try: line = self._gforth_que.get_nowait() # or q.get(timeout=.1) except Empty: line = '' if timeout > 0.: time.sleep(0.01) timeout -= 0.01 else: # got line output += line + '\n' timeout = 0. # Return results. if not silent: stream_content = {'name': 'stdout', 'data': output} self.send_response(self.iopub_socket, 'stream', stream_content) # Barf or return ok. if False: return {'status': 'error', 'execution_count': self.execution_count, 'ename': '', 'evalue': str(exitcode), 'traceback': []} else: return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=ForthKernel)
width, height = 560, 420 if isinstance(settings['size'], tuple): width, height = settings['size'] elif settings['size']: try: width, height = settings['size'].split(',') width, height = int(width), int(height) except Exception as e: self.Error('Error setting plot settings: %s' % e) size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s]);" cmds.append(size % (width / 150., height / 150.)) self.do_execute_direct('\n'.join(cmds)) def _make_figs(self, plot_dir): cmd = """ figHandles = get(0, 'children'); for fig=1:length(figHandles); h = figHandles(fig); filename = fullfile('%s', ['OctaveFig', sprintf('%%03d', fig)]); saveas(h, [filename, '.%s']); close(h); end; """ % (plot_dir, self._plot_fmt) super(OctaveKernel, self).do_execute_direct(cmd.replace('\n', '')) if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=OctaveKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import MySQLKernel IPKernelApp.launch_instance(kernel_class=MySQLKernel)
from .kernel import * if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=RedisKernel)
if not os.path.exists(self.hist_file): with open(self.hist_file, 'wb') as f: f.write('') with open(self.hist_file, 'rb') as f: history = f.readlines() history = history[:self.max_hist_cache] self.hist_cache = history self.log.debug('**HISTORY:') self.log.debug(history) history = [(None, None, h) for h in history] return {'history': history} def do_shutdown(self, restart): self.log.debug("**Shutting down") self.idlwrapper.child.kill(signal.SIGKILL) if self.hist_file: with open(self.hist_file,'wb') as f: data = '\n'.join(self.hist_cache[-self.max_hist_cache:]) f.write(data.encode('utf-8')) return {'status':'ok', 'restart':restart} if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=IDLKernel)
from __future__ import absolute_import from .kernel import * if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=RedisKernel)
super().__init__(*args, **kwargs) def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): mochi_builtins.eval_code_block(code) if not silent: stream_content = {'name': 'stdout', 'text': self.output.read()} self.send_response(self.iopub_socket, 'stream', stream_content) else: pass #self.output.read() if self.error.peek(): stream_content = {'name': 'stderr', 'text': self.error.read()} self.send_response(self.iopub_socket, 'stream', stream_content) else: pass #self.error.read() return {'status': 'ok', # The base class increments the execution count 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}, } if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=MochiKernel)
print e print qCommands.encode('ascii') result = '' return formatQ(result) def formatQ(result): formatter = getattr(result,'to_html', None) if formatter: return formatter() return str(result) def connect(details): try: return q.connect(details['hostname'].encode('ascii'), details['port'], details['username'].encode('ascii'), details['password'].encode('ascii')) except Exception as e: print e return None def getDetails(connectionStr): connectionDetail = connectionStr.split('=')[-1] print connectionDetail connectionObj = json.loads(connectionDetail) for detail in ('hostname', 'port', 'username', 'password'): if detail not in connectionObj: return None return connectionObj if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=KdbKernel)
else: # got line output += line + '\n' timeout = 0. # Return results. if not silent: stream_content = {'name': 'stdout', 'data': output} self.send_response(self.iopub_socket, 'stream', stream_content) # Barf or return ok. if False: return { 'status': 'error', 'execution_count': self.execution_count, 'ename': '', 'evalue': str(exitcode), 'traceback': [] } else: return { 'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {} } if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=ForthKernel)
text = info['code'][:info['end']] env = env or {} interpreter = Interpreter(text, [env]) position = (info['line_num'], info['column']) path = UserContext(text, position).get_path_until_cursor() path, dot, like = completion_parts(path) before = text[:len(text) - len(like)] completions = interpreter.completions() completions = [before + c.name_with_symbols for c in completions] return [c[info['start']:] for c in completions] def do_complete(self, code, cursor_pos): info = self.parser.parse_code(code, 0, cursor_pos) matches = info['path_matches'] if jedi: matches += self.get_jedi_completions(info) return {'matches': matches, 'cursor_start': info['start'], 'cursor_end': info['end'], 'metadata': dict(), 'status': 'ok'} if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=TestKernel)
def banner(self): if self._banner is None: self._banner = check_output(['bash', '--version']).decode('utf-8') return self._banner def makeWrapper(self): """Start a bash shell and return a :class:`REPLWrapper` object. Note that this is equivalent :function:`metakernel.pyexpect.bash`, but is used here as an example of how to be cross-platform. """ if os.name == 'nt': prompt_regex = u('__repl_ready__') prompt_emit_cmd = u('echo __repl_ready__') prompt_change_cmd = None else: prompt_change_cmd = u("PS1='{0}' PS2='{1}' PROMPT_COMMAND=''") prompt_emit_cmd = None prompt_regex = re.compile('[$#]') extra_init_cmd = "export PAGER=cat" return REPLWrapper('bash', prompt_regex, prompt_change_cmd, prompt_emit_cmd=prompt_emit_cmd, extra_init_cmd=extra_init_cmd) if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BashKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import PrologKernel IPKernelApp.launch_instance(kernel_class=PrologKernel)
return self._banner def makeWrapper(self): """Start a bash shell and return a :class:`REPLWrapper` object. Note that this is equivalent :function:`metakernel.pyexpect.bash`, but is used here as an example of how to be cross-platform. """ if os.name == 'nt': prompt_regex = u('__repl_ready__') prompt_emit_cmd = u('echo __repl_ready__') prompt_change_cmd = None else: prompt_change_cmd = u("PS1='{0}' PS2='{1}' PROMPT_COMMAND=''") prompt_emit_cmd = None prompt_regex = re.compile('[$#]') extra_init_cmd = "export PAGER=cat" return REPLWrapper('bash', prompt_regex, prompt_change_cmd, prompt_emit_cmd=prompt_emit_cmd, extra_init_cmd=extra_init_cmd) if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BashKernel)
'stream', { 'name': 'stdout', 'data': 'Richer print'}) # We prepare the response with our rich data # (the plot). content = {'source': 'kernel', 'data': {'text/html': out.data}, 'metadata': {}, 'text': [repr(out)]} # We send the display_data message with the # contents. self.send_response(self.iopub_socket, 'display_data', content) else: stream_content = {'name': 'stdout', 'data': output} self.send_response(self.iopub_socket, 'stream', stream_content) # We return the exection results. return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=PrintKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import PowerShellKernel IPKernelApp.launch_instance(kernel_class=PowerShellKernel)
code, silent, store_history=True, user_expressions=None, allow_stdin=False): global pointer global cells if code == "flush": pointer = 0 cells = [0] code, pointer, cells = brainfuck.process_string(code, pointer, cells) if not silent: stream_content = {'name': 'stdout', 'text': code} self.send_response(self.iopub_socket, 'stream', stream_content) return { 'status': 'ok', # The base class increments the execution count 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}, } if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BrainfuckKernel) else: from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=BrainfuckKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .stata_kernel import StataKernel IPKernelApp.launch_instance(kernel_class=StataKernel)
from IPython.kernel.zmq.kernelapp import IPKernelApp from .kernel import PostgresKernel IPKernelApp.launch_instance(kernel_class=PostgresKernel)
return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} interrupted = False try: output = self.erlangwrapper.run_command(code, timeout=None) except KeyboardInterrupt: self.erlangwrapper.child.sendintr() interrupted = True self.erlangwrapper._expect_prompt() output = self.erlangwrapper.child.before except EOF: output = self.erlangwrapper.child.before + 'Restarting Erlang' self._start_erlang() if not silent: # Send standard output stream_content = {'name': 'stdout', 'text': output} self.send_response(self.iopub_socket, 'stream', stream_content) if interrupted: return {'status': 'abort', 'execution_count': self.execution_count} return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} # ===== MAIN ===== if __name__ == '__main__': from IPython.kernel.zmq.kernelapp import IPKernelApp IPKernelApp.launch_instance(kernel_class=ErlangKernel)