Skip to content
This repository
Browse code

updated _input_repl_cmd to use codeop.compile_command from PSL

  • Loading branch information...
commit 0e68e83555bacac1b3f1b76dfe5ddbb4f9983a0c 1 parent f15cfb3
authored March 27, 2009

Showing 1 changed file with 17 additions and 11 deletions. Show diff stats Hide diff stats

  1. 28  ipydbg.py
28  ipydbg.py
@@ -314,25 +314,31 @@ def _print_source_line(self, sp, lines):
314 314
     
315 315
     @inputcmd(_inputcmds, ConsoleKey.R)
316 316
     def _input_repl_cmd(self, keyinfo):
  317
+      # I'd really like to replace some of this code with code.interact, but 
  318
+      # code.interact doesn't work currently because Ctl-Z doesn't throw an 
  319
+      # EOFError in raw_input like CPy does
  320
+      from codeop import compile_command
317 321
       print 
318 322
       repl_locals = {'self': self}
319 323
       with CC.ConsoleColorMgr(ConsoleColor.DarkBlue, ConsoleColor.White):
320 324
         print "REPL Console"
321 325
         cmd = ""
322 326
         while True:
323  
-          Console.Write(">>>")
  327
+          Console.Write(">>>" if not cmd else "...")
  328
+          
324 329
           line = Console.ReadLine()
325  
-          if str.IsNullOrEmpty(line):
326  
-            if str.IsNullOrEmpty(cmd):
327  
-              break
328  
-            else:
329  
-              code = compile(cmd, "<input>", "single")
330  
-              print "Executing:"+ cmd
331  
-              exec code in globals(), repl_locals 
  330
+          if not line and not cmd:
  331
+            break
  332
+          
  333
+          try:
  334
+            cmd = cmd + line + "\n"
  335
+            code = compile_command(cmd)
  336
+            if code != None:
  337
+              exec code in globals(), repl_locals
332 338
               cmd = ""
333  
-          else:
334  
-            cmd = cmd + line 
335  
-            if cmd != line: cmd = cmd + "\n"
  339
+          except Exception, ex:
  340
+            with CC.Red: print ex
  341
+            cmd = ""
336 342
             
337 343
     @inputcmd(_inputcmds, ConsoleKey.Spacebar)
338 344
     def _input_continue_cmd(self, keyinfo):

0 notes on commit 0e68e83

Please sign in to comment.
Something went wrong with that request. Please try again.