29 from DebugConfig import ConfigQtNames, ConfigVarTypeStrings |
29 from DebugConfig import ConfigQtNames, ConfigVarTypeStrings |
30 from FlexCompleter import Completer |
30 from FlexCompleter import Completer |
31 from DebugUtilities import prepareJsonCommand |
31 from DebugUtilities import prepareJsonCommand |
32 from BreakpointWatch import Breakpoint, Watch |
32 from BreakpointWatch import Breakpoint, Watch |
33 |
33 |
34 if sys.version_info[0] == 2: |
34 from DebugUtilities import getargvalues, formatargvalues |
35 from inspect import getargvalues, formatargvalues |
|
36 else: |
|
37 unichr = chr |
|
38 from DebugUtilities import getargvalues, formatargvalues |
|
39 |
35 |
40 DebugClientInstance = None |
36 DebugClientInstance = None |
41 |
37 |
42 ############################################################################### |
38 ############################################################################### |
43 |
39 |
44 |
40 |
45 def DebugClientRawInput(prompt="", echo=True): |
41 def DebugClientRawInput(prompt=""): |
46 """ |
42 """ |
47 Replacement for the standard raw_input() builtin (Python 2) and |
43 Replacement for the standard input() builtin. |
48 the standard input() builtin (Python 3). |
|
49 |
44 |
50 This function works with the split debugger. |
45 This function works with the split debugger. |
51 |
46 |
52 @param prompt prompt to be shown |
47 @param prompt prompt to be shown |
53 @type str |
48 @type str |
54 @param echo flag indicating echoing of the input |
|
55 @type bool |
|
56 @return result of the raw_input()/input() call |
49 @return result of the raw_input()/input() call |
57 @rtype str |
50 @rtype str |
58 """ |
51 """ |
59 if DebugClientInstance is None or not DebugClientInstance.redirect: |
52 if DebugClientInstance is None or not DebugClientInstance.redirect: |
60 return DebugClientOrigRawInput(prompt) |
|
61 |
|
62 return DebugClientInstance.raw_input(prompt, echo) |
|
63 |
|
64 |
|
65 def DebugClientInput(prompt=""): |
|
66 """ |
|
67 Replacement for the standard input() builtin (Python 2). |
|
68 |
|
69 This function works with the split debugger. |
|
70 |
|
71 @param prompt prompt to be shown |
|
72 @type str |
|
73 @return result of the input() call |
|
74 @rtype str |
|
75 """ |
|
76 if DebugClientInstance is None or not DebugClientInstance.redirect: |
|
77 return DebugClientOrigInput(prompt) |
53 return DebugClientOrigInput(prompt) |
78 |
54 |
79 return DebugClientInstance.input(prompt) |
55 return DebugClientInstance.input(prompt) |
80 |
56 |
81 # Use our own input() and on Python 2 raw_input(). |
57 # Use our own input(). |
82 if sys.version_info[0] == 2: |
58 try: |
83 try: |
59 DebugClientOrigInput = __builtins__.__dict__['input'] |
84 DebugClientOrigRawInput = __builtins__.__dict__['raw_input'] |
60 __builtins__.__dict__['input'] = DebugClientRawInput |
85 __builtins__.__dict__['raw_input'] = DebugClientRawInput |
61 except (AttributeError, KeyError): |
86 except (AttributeError, KeyError): |
62 import __main__ |
87 import __main__ |
63 DebugClientOrigInput = __main__.__builtins__.__dict__['input'] |
88 DebugClientOrigRawInput = __main__.__builtins__.__dict__['raw_input'] |
64 __main__.__builtins__.__dict__['input'] = DebugClientRawInput |
89 __main__.__builtins__.__dict__['raw_input'] = DebugClientRawInput |
|
90 |
|
91 try: |
|
92 DebugClientOrigInput = __builtins__.__dict__['input'] |
|
93 __builtins__.__dict__['input'] = DebugClientInput |
|
94 except (AttributeError, KeyError): |
|
95 import __main__ |
|
96 DebugClientOrigInput = __main__.__builtins__.__dict__['input'] |
|
97 __main__.__builtins__.__dict__['input'] = DebugClientInput |
|
98 else: |
|
99 try: |
|
100 DebugClientOrigInput = __builtins__.__dict__['input'] |
|
101 __builtins__.__dict__['input'] = DebugClientRawInput |
|
102 except (AttributeError, KeyError): |
|
103 import __main__ |
|
104 DebugClientOrigInput = __main__.__builtins__.__dict__['input'] |
|
105 __main__.__builtins__.__dict__['input'] = DebugClientRawInput |
|
106 |
65 |
107 ############################################################################### |
66 ############################################################################### |
108 |
67 |
109 |
68 |
110 def DebugClientFork(): |
69 def DebugClientFork(): |
272 if m: |
231 if m: |
273 self.__coding = m.group(1) |
232 self.__coding = m.group(1) |
274 return |
233 return |
275 self.__coding = default |
234 self.__coding = default |
276 |
235 |
277 def raw_input(self, prompt, echo): |
236 def input(self, prompt): |
278 """ |
237 """ |
279 Public method to implement raw_input() / input() using the event loop. |
238 Public method to implement input() using the event loop. |
280 |
239 |
281 @param prompt the prompt to be shown (string) |
240 @param prompt the prompt to be shown (string) |
282 @param echo Flag indicating echoing of the input (boolean) |
241 @param echo Flag indicating echoing of the input (boolean) |
283 @return the entered string |
242 @return the entered string |
284 """ |
243 """ |
285 self.sendJsonCommand("RequestRaw", { |
244 self.sendJsonCommand("RequestRaw", { |
286 "prompt": prompt, |
245 "prompt": prompt, |
287 "echo": echo, |
246 "echo": True, |
288 }) |
247 }) |
289 self.eventLoop(True) |
248 self.eventLoop(True) |
290 return self.rawLine |
249 return self.rawLine |
291 |
250 |
292 def input(self, prompt): |
|
293 """ |
|
294 Public method to implement input() (Python 2) using the event loop. |
|
295 |
|
296 @param prompt the prompt to be shown (string) |
|
297 @return the entered string evaluated as a Python expresion |
|
298 """ |
|
299 return eval(self.raw_input(prompt, True)) # secok |
|
300 |
|
301 def sessionClose(self, terminate=True): |
251 def sessionClose(self, terminate=True): |
302 """ |
252 """ |
303 Public method to close the session with the debugger and optionally |
253 Public method to close the session with the debugger and optionally |
304 terminate. |
254 terminate. |
305 |
255 |
331 @param mode kind of code to be generated (string, exec or eval) |
281 @param mode kind of code to be generated (string, exec or eval) |
332 @return compiled code object (None in case of errors) |
282 @return compiled code object (None in case of errors) |
333 """ |
283 """ |
334 with codecs.open(filename, encoding=self.__coding) as fp: |
284 with codecs.open(filename, encoding=self.__coding) as fp: |
335 statement = fp.read() |
285 statement = fp.read() |
336 |
|
337 if sys.version_info[0] == 2: |
|
338 lines = statement.splitlines(True) |
|
339 for lineno, line in enumerate(lines[:2]): |
|
340 lines[lineno] = self.coding_re.sub('', line) |
|
341 |
|
342 statement = unicode('').join(lines) # __IGNORE_WARNING__ |
|
343 |
286 |
344 try: |
287 try: |
345 code = compile(statement + '\n', filename, mode) |
288 code = compile(statement + '\n', filename, mode) |
346 except SyntaxError: |
289 except SyntaxError: |
347 exctype, excval, exctb = sys.exc_info() |
290 exctype, excval, exctb = sys.exc_info() |