1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
from pydev_console_utils import Null
import sys
original_stdout = sys.stdout
original_stderr = sys.stderr
#=======================================================================================================================
# PyDevFrontEnd
#=======================================================================================================================
class PyDevFrontEnd(PrefilterFrontEnd):
def __init__(self, *args, **kwargs):
PrefilterFrontEnd.__init__(self, *args, **kwargs)
#Disable the output trap: we want all that happens to go to the output directly
self.shell.output_trap = Null()
self._curr_exec_lines = []
self._continuation_prompt = ''
def capture_output(self):
pass
def release_output(self):
pass
def continuation_prompt(self):
return self._continuation_prompt
def write(self, txt, refresh=True):
original_stdout.write(txt)
def new_prompt(self, prompt):
self.input_buffer = ''
#The java side takes care of this part.
#self.write(prompt)
def show_traceback(self):
import traceback;traceback.print_exc()
def write_out(self, txt, *args, **kwargs):
original_stdout.write(txt)
def write_err(self, txt, *args, **kwargs):
original_stderr.write(txt)
def getNamespace(self):
return self.shell.user_ns
def is_complete(self, string):
#Based on IPython 0.10.1
if string in ('', '\n'):
# Prefiltering, eg through ipython0, may return an empty
# string although some operations have been accomplished. We
# thus want to consider an empty string as a complete
# statement.
return True
else:
try:
# Add line returns here, to make sure that the statement is
# complete (except if '\' was used).
# This should probably be done in a different place (like
# maybe 'prefilter_input' method? For now, this works.
clean_string = string.rstrip('\n')
if not clean_string.endswith('\\'): clean_string += '\n\n'
is_complete = codeop.compile_command(clean_string,
"<string>", "exec")
except Exception:
# XXX: Hack: return True so that the
# code gets executed and the error captured.
is_complete = True
return is_complete
def addExec(self, line):
if self._curr_exec_lines:
if not line:
self._curr_exec_lines.append(line)
#Would be the line below, but we've set the continuation_prompt to ''.
#buf = self.continuation_prompt() + ('\n' + self.continuation_prompt()).join(self._curr_exec_lines)
buf = '\n'.join(self._curr_exec_lines)
self.input_buffer = buf + '\n'
if self._on_enter():
del self._curr_exec_lines[:]
return False #execute complete (no more)
return True #needs more
else:
self._curr_exec_lines.append(line)
return True #needs more
else:
self.input_buffer = line
if not self._on_enter():
#Did not execute
self._curr_exec_lines.append(line)
return True #needs more
return False #execute complete (no more)
def update(self, globals, locals):
locals['_oh'] = self.shell.user_ns['_oh']
locals['_ip'] = self.shell.user_ns['_ip']
self.shell.user_global_ns = globals
self.shell.user_ns = locals
def is_automagic(self):
if self.ipython0.rc.automagic:
return True
else:
return False
def get_greeting_msg(self):
return 'PyDev console: using IPython 0.10\n'
|