def cmdline_exec(w, size, key):
    cmd = self.cmdline_edit.get_edit_text()
    if (not cmd):
        return
    self.add_cmdline_content(('>>> ' + cmd), 'command line input')
    if ((not self.cmdline_history) or (cmd != self.cmdline_history[(- 1)])):
        self.cmdline_history.append(cmd)
    self.cmdline_history_position = (- 1)
    prev_sys_stdin = sys.stdin
    prev_sys_stdout = sys.stdout
    prev_sys_stderr = sys.stderr
    from io import StringIO
    sys.stdin = None
    sys.stderr = sys.stdout = StringIO()
    try:
        eval(compile(cmd, '<pudb command line>', 'single'), cmdline_get_namespace())
    except Exception:
        (tp, val, tb) = sys.exc_info()
        import traceback
        tblist = traceback.extract_tb(tb)
        del tblist[:1]
        tb_lines = traceback.format_list(tblist)
        if tb_lines:
            tb_lines.insert(0, 'Traceback (most recent call last):\n')
        tb_lines[len(tb_lines):] = traceback.format_exception_only(tp, val)
        self.add_cmdline_content(''.join(tb_lines), 'command line error')
    else:
        self.cmdline_edit.set_edit_text('')
    finally:
        if sys.stdout.getvalue():
            self.add_cmdline_content(sys.stdout.getvalue(), 'command line output')
        sys.stdin = prev_sys_stdin
        sys.stdout = prev_sys_stdout
        sys.stderr = prev_sys_stderr
def cmdline_exec(w, size, key):
    cmd = self.cmdline_edit.get_edit_text()
    if (not cmd):
        return
    self.add_cmdline_content(('>>> ' + cmd), 'command line input')
    if ((not self.cmdline_history) or (cmd != self.cmdline_history[(- 1)])):
        self.cmdline_history.append(cmd)
    self.cmdline_history_position = (- 1)
    prev_sys_stdin = sys.stdin
    prev_sys_stdout = sys.stdout
    prev_sys_stderr = sys.stderr
    from io import StringIO
    sys.stdin = None
    sys.stderr = sys.stdout = StringIO()
    try:
        eval(compile(cmd, '<pudb command line>', 'single'), cmdline_get_namespace())
    except Exception:
        (tp, val, tb) = sys.exc_info()
        import traceback
        tblist = traceback.extract_tb(tb)
        del tblist[:1]
        tb_lines = traceback.format_list(tblist)
        if tb_lines:
            tb_lines.insert(0, 'Traceback (most recent call last):\n')
        tb_lines[len(tb_lines):] = traceback.format_exception_only(tp, val)
        self.add_cmdline_content(.join(tb_lines), 'command line error')
    else:
        self.cmdline_edit.set_edit_text()
    finally:
        if sys.stdout.getvalue():
            self.add_cmdline_content(sys.stdout.getvalue(), 'command line output')
        sys.stdin = prev_sys_stdin
        sys.stdout = prev_sys_stdout
        sys.stderr = prev_sys_stderr