echo_kernel.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from ipykernel.kernelapp import IPKernelApp
  4. from ipykernel.kernelbase import Kernel
  5. class EchoKernel(Kernel):
  6. implementation = 'Echo'
  7. implementation_version = '1.0'
  8. language = 'echo'
  9. language_version = '0.1'
  10. language_info = {
  11. 'name': 'echo',
  12. 'mimetype': 'text/plain',
  13. 'file_extension': '.txt',
  14. }
  15. banner = "Echo kernel - as useful as a parrot"
  16. def do_execute(self, code, silent, store_history=True,
  17. user_expressions=None, allow_stdin=False):
  18. if not silent:
  19. stream_content = {'name': 'stdout', 'text': code}
  20. self.send_response(self.iopub_socket, 'stream', stream_content)
  21. return {'status': 'ok',
  22. # The base class increments the execution count
  23. 'execution_count': self.execution_count,
  24. 'payload': [],
  25. 'user_expressions': {}}
  26. class EchoKernelApp(IPKernelApp):
  27. kernel_class = EchoKernel
  28. if __name__ == '__main__':
  29. logging.disable(logging.ERROR)
  30. EchoKernelApp.launch_instance()