Trees | Indices | Help |
|
---|
|
1 import readline 2 import code 3 import sys 4 import traceback 5948 code.InteractiveConsole.__init__(self,dict) 9 self.prompt = prompt 10 self.loop_exit = False 11 self.dict = dict1214 try: 15 sys.ps1 16 except AttributeError: 17 sys.ps1 = ">>> " 18 try: 19 sys.ps2 20 except AttributeError: 21 sys.ps2 = "... " 22 23 while not self.loop_exit: 24 try: 25 self.read_py_command() 26 except (SystemExit, EOFError): 27 # EOF while in Python just breaks out to top level. 28 self.write('\n') 29 self.loop_exit = True 30 break 31 except KeyboardInterrupt: 32 self.write("\nKeyboardInterrupt\n") 33 self.resetbuffer() 34 more = 0 35 except: 36 traceback.print_exc()3739 # Canonicalize the format of the input string 40 temp_str = in_str 41 temp_str.strip(' \t') 42 words = temp_str.split() 43 temp_str = ('').join(words) 44 45 # Check the input string to see if it was the quit 46 # command. If so, intercept it, so that it doesn't 47 # close stdin on us! 48 if (temp_str.lower() == "quit()" or temp_str.lower() == "exit()"): 49 self.loop_exit = True 50 in_str = "raise SystemExit " 51 return in_str5254 stream = sys.stdout 55 stream.write (prompt) 56 stream.flush () 57 try: 58 line = sys.stdin.readline() 59 except KeyboardInterrupt: 60 line = " \n" 61 except (SystemExit, EOFError): 62 line = "quit()\n" 63 if not line: 64 raise EOFError 65 if line[-1] == '\n': 66 line = line[:-1] 67 return line6870 # Read off a complete Python command. 71 more = 0 72 while 1: 73 if more: 74 prompt = sys.ps2 75 else: 76 prompt = sys.ps1 77 line = self.my_raw_input(prompt) 78 # Can be None if sys.stdin was redefined 79 encoding = getattr(sys.stdin, "encoding", None) 80 if encoding and not isinstance(line, unicode): 81 line = line.decode(encoding) 82 line = self.process_input (line) 83 more = self.push(line) 84 if not more: 85 break8688 line = self.process_input (input) 89 more = self.push(line) 90 if more: 91 self.write ("Input not a complete line.") 92 self.resetbuffer() 93 more = 096 # Pass in the dictionary, for continuity from one session to the next. 97 repl = SimpleREPL('>>> ', dict) 98 repl.interact()99 103
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Jul 19 13:22:38 2013 | http://epydoc.sourceforge.net |