Пример #1
0
 def execute(self, python_string, raw_string=None):
     if self.debug:
         print 'Executing Python code:', repr(python_string)
     self.capture_output()
     LineFrontEndBase.execute(self, python_string,
                                 raw_string=raw_string)
     self.release_output()
Пример #2
0
 def execute(self, python_string, raw_string=None):
     if self.debug:
         print 'Executing Python code:', repr(python_string)
     self.capture_output()
     LineFrontEndBase.execute(self, python_string,
                                 raw_string=raw_string)
     self.release_output()
Пример #3
0
    def __init__(self, ipython0=None, *args, **kwargs):
        """ Parameters
            ----------

            ipython0: an optional ipython0 instance to use for command
            prefiltering and completion.
        """
        LineFrontEndBase.__init__(self, *args, **kwargs)
        self.shell.output_trap = RedirectorOutputTrap(
                            out_callback=self.write,
                            err_callback=self.write,
                                            )
        self.shell.traceback_trap = SyncTracebackTrap(
                        formatters=self.shell.traceback_trap.formatters,
                            )

        # Start the ipython0 instance:
        self.save_output_hooks()
        if ipython0 is None:
            # Instanciate an IPython0 InteractiveShell to be able to use the
            # prefiltering.
            # Suppress all key input, to avoid waiting
            def my_rawinput(x=None):
                return '\n'
            old_rawinput = __builtin__.raw_input
            __builtin__.raw_input = my_rawinput
            ipython0 = InteractiveShell(
                parent=None, user_ns=self.shell.user_ns,
                user_global_ns=self.shell.user_global_ns
            )
            __builtin__.raw_input = old_rawinput
        self.ipython0 = ipython0
        # Set the pager:
        self.ipython0.set_hook('show_in_pager', 
                    lambda s, string: self.write("\n" + string))
        self.ipython0.write = self.write
        self._ip = _ip = self.ipython0
        # Make sure the raw system call doesn't get called, as we don't
        # have a stdin accessible.
        self._ip.system = self.system_call
        # XXX: Muck around with magics so that they work better
        # in our environment
        if not sys.platform.startswith('win'):
            self.ipython0.magic_ls = mk_system_call(self.system_call, 
                                                                'ls -CF')
        # And now clean up the mess created by ipython0
        self.release_output()


        if not 'banner' in kwargs and self.banner is None:
            self.banner = self.ipython0.banner

        # FIXME: __init__ and start should be two different steps
        self.start()
Пример #4
0
    def __init__(self, ipython0=None, *args, **kwargs):
        """ Parameters
            ----------

            ipython0: an optional ipython0 instance to use for command
            prefiltering and completion.
        """
        LineFrontEndBase.__init__(self, *args, **kwargs)
        self.shell.output_trap = RedirectorOutputTrap(
            out_callback=self.write,
            err_callback=self.write,
        )
        self.shell.traceback_trap = SyncTracebackTrap(
            formatters=self.shell.traceback_trap.formatters, )

        # Start the ipython0 instance:
        self.save_output_hooks()
        if ipython0 is None:
            # Instanciate an IPython0 InteractiveShell to be able to use the
            # prefiltering.
            # Suppress all key input, to avoid waiting
            def my_rawinput(x=None):
                return '\n'

            old_rawinput = __builtin__.raw_input
            __builtin__.raw_input = my_rawinput
            ipython0 = InteractiveShell(
                parent=None,
                user_ns=self.shell.user_ns,
                user_global_ns=self.shell.user_global_ns)
            __builtin__.raw_input = old_rawinput
        self.ipython0 = ipython0
        # Set the pager:
        self.ipython0.set_hook('show_in_pager',
                               lambda s, string: self.write("\n" + string))
        self.ipython0.write = self.write
        self._ip = _ip = self.ipython0
        # Make sure the raw system call doesn't get called, as we don't
        # have a stdin accessible.
        self._ip.system = self.system_call
        # XXX: Muck around with magics so that they work better
        # in our environment
        if not sys.platform.startswith('win'):
            self.ipython0.magic_ls = mk_system_call(self.system_call, 'ls -CF')
        # And now clean up the mess created by ipython0
        self.release_output()

        if not 'banner' in kwargs and self.banner is None:
            self.banner = self.ipython0.banner

        # FIXME: __init__ and start should be two different steps
        self.start()
Пример #5
0
    def prefilter_input(self, input_string):
        """ Using IPython0 to prefilter the commands to turn them
        in executable statements that are valid Python strings.
        """
        input_string = LineFrontEndBase.prefilter_input(self, input_string)
        filtered_lines = []
        # The IPython0 prefilters sometime produce output. We need to
        # capture it.
        self.capture_output()
        self.last_result = dict(number=self.prompt_number)

        try:
            try:
                for line in input_string.split('\n'):
                    pf = self.ipython0.prefilter_manager.prefilter_lines
                    filtered_lines.append(pf(line, False).rstrip())
            except:
                # XXX: probably not the right thing to do.
                self.ipython0.showsyntaxerror()
                self.after_execute()
        finally:
            self.release_output()

        # Clean up the trailing whitespace, to avoid indentation errors
        filtered_string = '\n'.join(filtered_lines)
        return filtered_string
Пример #6
0
    def prefilter_input(self, input_string):
        """ Using IPython0 to prefilter the commands to turn them
        in executable statements that are valid Python strings.
        """
        input_string = LineFrontEndBase.prefilter_input(self, input_string)
        filtered_lines = []
        # The IPython0 prefilters sometime produce output. We need to
        # capture it.
        self.capture_output()
        self.last_result = dict(number=self.prompt_number)

        try:
            try:
                for line in input_string.split("\n"):
                    pf = self.ipython0.prefilter_manager.prefilter_lines
                    filtered_lines.append(pf(line, False).rstrip())
            except:
                # XXX: probably not the right thing to do.
                self.ipython0.showsyntaxerror()
                self.after_execute()
        finally:
            self.release_output()

        # Clean up the trailing whitespace, to avoid indentation errors
        filtered_string = "\n".join(filtered_lines)
        return filtered_string
Пример #7
0
    def __init__(self, ipython0=None, *args, **kwargs):
        """ Parameters:
            -----------

            ipython0: an optional ipython0 instance to use for command
            prefiltering and completion.
        """
        LineFrontEndBase.__init__(self, *args, **kwargs)
        self.shell.output_trap = RedirectorOutputTrap(
                            out_callback=self.write,
                            err_callback=self.write,
                                            )
        self.shell.traceback_trap = SyncTracebackTrap(
                        formatters=self.shell.traceback_trap.formatters,
                            )

        # Start the ipython0 instance:
        self.save_output_hooks()
        if ipython0 is None:
            # Instanciate an IPython0 interpreter to be able to use the
            # prefiltering.
            # XXX: argv=[] is a bit bold.
            ipython0 = make_IPython(argv=[], 
                                    user_ns=self.shell.user_ns,
                                    user_global_ns=self.shell.user_global_ns)
        self.ipython0 = ipython0
        # Set the pager:
        self.ipython0.set_hook('show_in_pager', 
                    lambda s, string: self.write("\n" + string))
        self.ipython0.write = self.write
        self._ip = _ip = IPApi(self.ipython0)
        # Make sure the raw system call doesn't get called, as we don't
        # have a stdin accessible.
        self._ip.system = self.system_call
        # XXX: Muck around with magics so that they work better
        # in our environment
        self.ipython0.magic_ls = mk_system_call(self.system_call, 
                                                            'ls -CF')
        # And now clean up the mess created by ipython0
        self.release_output()


        if not 'banner' in kwargs and self.banner is None:
            self.banner = self.ipython0.BANNER + """
This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code."""

        self.start()
Пример #8
0
    def __init__(self, ipython0=None, argv=None, *args, **kwargs):
        """ Parameters
            ----------

            ipython0: an optional ipython0 instance to use for command
            prefiltering and completion.

            argv : list, optional
              Used as the instance's argv value.  If not given, [] is used.
        """
        if argv is None:
            argv = []
        # This is a hack to avoid the IPython exception hook to trigger
        # on exceptions (https://bugs.launchpad.net/bugs/337105)
        # XXX: This is horrible: module-leve monkey patching -> side
        # effects.
        from IPython import iplib
        iplib.InteractiveShell.isthreaded = True

        LineFrontEndBase.__init__(self, *args, **kwargs)
        self.shell.output_trap = RedirectorOutputTrap(
                            out_callback=self.write,
                            err_callback=self.write,
                                            )
        self.shell.traceback_trap = SyncTracebackTrap(
                        formatters=self.shell.traceback_trap.formatters,
                            )

        # Start the ipython0 instance:
        self.save_output_hooks()
        if ipython0 is None:
            # Instanciate an IPython0 interpreter to be able to use the
            # prefiltering.
            # Suppress all key input, to avoid waiting
            def my_rawinput(x=None):
                return '\n'
            old_rawinput = __builtin__.raw_input
            __builtin__.raw_input = my_rawinput
            # XXX: argv=[] is a bit bold.
            ipython0 = make_IPython(argv=argv, 
                                    user_ns=self.shell.user_ns,
                                    user_global_ns=self.shell.user_global_ns)
            __builtin__.raw_input = old_rawinput
        self.ipython0 = ipython0
        # Set the pager:
        self.ipython0.set_hook('show_in_pager', 
                    lambda s, string: self.write("\n" + string))
        self.ipython0.write = self.write
        self._ip = _ip = IPApi(self.ipython0)
        # Make sure the raw system call doesn't get called, as we don't
        # have a stdin accessible.
        self._ip.system = self.system_call
        # XXX: Muck around with magics so that they work better
        # in our environment
        if not sys.platform.startswith('win'):
            self.ipython0.magic_ls = mk_system_call(self.system_call, 
                                                                'ls -CF')
        # And now clean up the mess created by ipython0
        self.release_output()


        if not 'banner' in kwargs and self.banner is None:
            self.banner = self.ipython0.BANNER

        # FIXME: __init__ and start should be two different steps
        self.start()