1 package org.python.util; 3 import org.python.core.*; 4 5 7 public class InteractiveConsole extends InteractiveInterpreter { 8 public String filename; 9 10 public InteractiveConsole() { 11 this(null, "<console>"); 12 } 13 public InteractiveConsole(PyObject locals) { 14 this(locals, "<console>"); 15 } 16 public InteractiveConsole(PyObject locals, String filename) { 17 super(locals); 18 this.filename = filename; 19 } 20 21 30 public void interact() { 31 interact(getDefaultBanner()); 32 } 33 34 public static String getDefaultBanner() { 35 String compiler = System.getProperty("java.compiler"); 36 37 return "Jython " + PySystemState.version + " on " + 38 PySystemState.platform + " (JIT: " + 39 ((compiler == null) ? "null" : compiler) + ")"; 40 } 41 42 public void interact(String banner) { 43 if (banner != null) { 44 write(banner); 45 write("\n"); 46 } 47 exec("2"); 49 boolean more = false; 51 while (true) { 52 PyObject prompt = more ? systemState.ps2 : systemState.ps1; 53 String line; 54 try { 55 line = raw_input(prompt); 56 } catch (PyException exc) { 57 if (!Py.matchException(exc, Py.EOFError)) 58 throw exc; 59 write("\n"); 60 break; 61 } 62 more = push(line); 63 } 64 } 65 66 78 79 public boolean push(String line) { 80 if (buffer.length() > 0) 81 buffer.append("\n"); 82 buffer.append(line); 83 boolean more = runsource(buffer.toString(), filename); 84 if (!more) 85 resetbuffer(); 86 return more; 87 } 88 89 98 public String raw_input(PyObject prompt) { 99 return __builtin__.raw_input(prompt); 100 } 101 } 102 | Popular Tags |