Beispiel #1
0
    def _load_ipyhon(self):
        """Try loading IPython shell. The result is set in self._ipython
        (can be None if IPython not available).
        """

        # Init
        self._ipython = None
        import __main__

        # Try importing IPython
        try:
            import IPython
        except ImportError:
            return

        # Version ok?
        if IPython.version_info < (1, ):
            return

        # Create an IPython shell
        from IPython.core.interactiveshell import InteractiveShell

        self._ipython = InteractiveShell(user_module=__main__)

        # Set some hooks / event callbacks
        # Run hook (pre_run_code_hook is depreacted in 2.0)
        pre_run_cell_hook = self.ipython_pre_run_cell_hook
        if IPython.version_info < (2, ):
            self._ipython.set_hook("pre_run_code_hook", pre_run_cell_hook)
        else:
            self._ipython.events.register("pre_run_cell", pre_run_cell_hook)
        # Other hooks
        self._ipython.set_hook("editor", self.ipython_editor_hook)
        self._ipython.set_custom_exc((bdb.BdbQuit, ), self.dbstop_handler)

        # Some patching
        self._ipython.ask_exit = self.ipython_ask_exit

        # Make output be shown on Windows
        if sys.platform.startswith("win"):
            # IPython wraps std streams just like we do below, but
            # pyreadline adds *another* wrapper, which is where it
            # goes wrong. Here we set it back to bypass pyreadline.

            if IPython.version_info < (
                    8,
            ):  # corrects a problem with IOStream from IPython 8.x.x
                from IPython.utils import io

                io.stdin = io.IOStream(sys.stdin)
                io.stdout = io.IOStream(sys.stdout)
                io.stderr = io.IOStream(sys.stderr)

            # Ipython uses msvcrt e.g. for pausing between pages
            # but this does not work in pyzo
            import msvcrt

            msvcrt.getwch = msvcrt.getch = input  # input is deffed above
Beispiel #2
0
    def init_io(self):
        if sys.platform not in {'win32', 'cli'}:
            return

        import colorama
        colorama.init()

        # For some reason we make these wrappers around stdout/stderr.
        # For now, we need to reset them so all output gets coloured.
        # https://github.com/ipython/ipython/issues/8669
        from IPython.utils import io
        io.stdout = io.IOStream(sys.stdout)
        io.stderr = io.IOStream(sys.stderr)
Beispiel #3
0
    def init_io(self):
        if sys.platform not in {'win32', 'cli'}:
            return

        import colorama
        colorama.init()

        # For some reason we make these wrappers around stdout/stderr.
        # For now, we need to reset them so all output gets coloured.
        # https://github.com/ipython/ipython/issues/8669
        # io.std* are deprecated, but don't show our own deprecation warnings
        # during initialization of the deprecated API.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            io.stdout = io.IOStream(sys.stdout)
            io.stderr = io.IOStream(sys.stderr)
Beispiel #4
0
        return zmq_shell.kernel_client
except ImportError:
    # Older IPythons
    from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp

    def kernel_client(zmq_shell):
        return zmq_shell.kernel_manager


embedded_shell = ZMQTerminalIPythonApp(config=cfg, user_ns={})
embedded_shell.initialize()

if os.name == "nt":
    # OMG what a fugly hack
    import IPython.utils.io as io
    io.stdout = io.IOStream(sys.__stdout__, fallback=io.devnull)
    io.stderr = io.IOStream(sys.__stderr__, fallback=io.devnull)
    embedded_shell.shell.show_banner()  # ... my eyes, oh my eyes..


ac_port = int(os.environ.get("SUBLIMEREPL_AC_PORT", "0"))
ac_ip = os.environ.get("SUBLIMEREPL_AC_IP", "127.0.0.1")
if ac_port:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((ac_ip, ac_port))


def read_netstring(s):
    size = 0
    while True:
        ch = s.recv(1)