Exemple #1
0
 def __init__(self, *args, **kwargs):
     self.skip = kwargs.get('skip', None)
     Pdb.__init__(self, *args, **kwargs)
     self.prompt = Pdbi.PROMPT
Exemple #2
0
 def __init__(self, *args, **kwargs):
     Pdb.__init__(self, *args, **kwargs)
     self._ptcomp = None
     self.pt_init()
Exemple #3
0
    def __init__(self, addr="127.0.0.1", port=4444):
        """Initialize the socket and initialize pdb."""

        # Backup stdin and stdout before replacing them by the socket handle
        self.old_stdout = sys.stdout
        self.old_stdin = sys.stdin
        self.port = port

        # Open a 'reusable' socket to let the webapp reload on the same port
        self.skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
        self.skt.bind((addr, port))
        self.skt.listen(1)

        # Writes to stdout are forbidden in mod_wsgi environments
        try:
            sys.stderr.write("pdb is running on %s:%d\n"
                             % self.skt.getsockname())
        except IOError:
            pass

        (clientsocket, address) = self.skt.accept()
        handle = clientsocket.makefile('rw')

        Pdb.__init__(self, color_scheme='Linux', completekey='tab',
                     stdin=FileObjectWrapper(handle, self.old_stdin),
                     stdout=FileObjectWrapper(handle, self.old_stdin))
        handle.write("writing to handle")
        def import_module(possible_modules, needed_module):
            """Make it more resilient to different versions of IPython and try to
            find a module."""
            count = len(possible_modules)
            for module in possible_modules:
                sys.stderr.write(module)

                try:
                    return __import__(module, fromlist=[needed_module])
                except ImportError:
                    count -= 1
                    if count == 0:
                        raise

        possible_modules = ['IPython.terminal.ipapp',           # Newer IPython
                            'IPython.frontend.terminal.ipapp']  # Older IPython

        app = import_module(possible_modules, "TerminalIPythonApp")
        TerminalIPythonApp = app.TerminalIPythonApp

        possible_modules = ['IPython.terminal.embed',           # Newer IPython
                            'IPython.frontend.terminal.embed']  # Older IPython
        embed = import_module(possible_modules, "InteractiveShellEmbed")
        InteractiveShellEmbed = embed.InteractiveShellEmbed

        try:
            get_ipython
        except NameError:
            # Build a terminal app in order to force ipython to load the
            # configuration
            ipapp = TerminalIPythonApp()
            # Avoid output (banner, prints)
            ipapp.interact = False
            ipapp.initialize()
            def_colors = ipapp.shell.colors
        else:
            # If an instance of IPython is already running try to get an instance
            # of the application. If there is no TerminalIPythonApp instanciated
            # the instance method will create a new one without loading the config.
            # i.e: if we are in an embed instance we do not want to load the config.
            ipapp = TerminalIPythonApp.instance()
            shell = get_ipython()
            def_colors = shell.colors

            # Detect if embed shell or not and display a message
            if isinstance(shell, InteractiveShellEmbed):
                shell.write_err(
                    "\nYou are currently into an embedded ipython shell,\n"
                    "the configuration will not be loaded.\n\n"
                )

        self.rcLines += [line + '\n' for line in ipapp.exec_lines]
        sys.stdout = sys.stdin = handle
        OCCUPIED.claim(port, sys.stdout)
        sys.stderr.write(str(self.rcLines))
Exemple #4
0
 def __init__(self, *args, pt_session_options=None, **kwargs):
     Pdb.__init__(self, *args, **kwargs)
     self._ptcomp = None
     self.pt_init(pt_session_options)
Exemple #5
0
 def __init__(self, *args, pt_session_options=None, **kwargs):
     Pdb.__init__(self, *args, **kwargs)
     self._ptcomp = None
     self.pt_init(pt_session_options)
     self.thread_executor = ThreadPoolExecutor(1)