[Jython-checkins] jython: Enable piping input into Jython without getting extraneous prompt output
jim.baker
jython-checkins at python.org
Wed Apr 15 21:02:30 CEST 2015
https://hg.python.org/jython/rev/cc3e787c0a7c
changeset: 7671:cc3e787c0a7c
user: Jason Madden <jason.madden at nextthought.com>
date: Wed Apr 15 15:01:34 2015 -0400
summary:
Enable piping input into Jython without getting extraneous prompt output
Previously Jython would display prompt (sys.ps1, sys.ps2) on stdout
Fixes http://bugs.jython.org/issue2325
files:
ACKNOWLEDGMENTS | 1 +
src/org/python/core/Py.java | 4 ++++
src/org/python/util/InteractiveConsole.java | 4 +++-
src/org/python/util/jython.java | 9 +++++++--
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS
--- a/ACKNOWLEDGMENTS
+++ b/ACKNOWLEDGMENTS
@@ -152,6 +152,7 @@
Paolo Dina
Eliya Sadan
Stefan Richthofer
+ Jason Madden
Local Variables:
mode: indented-text
diff --git a/src/org/python/core/Py.java b/src/org/python/core/Py.java
--- a/src/org/python/core/Py.java
+++ b/src/org/python/core/Py.java
@@ -1533,10 +1533,14 @@
* @return true if (we think) we are in an interactive environment
*/
public static boolean isInteractive() {
+ // python.launcher.tty is authoratative; see http://bugs.jython.org/issue2325
String isTTY = System.getProperty("python.launcher.tty");
if (isTTY != null && isTTY.equals("true")) {
return true;
}
+ if (isTTY != null && isTTY.equals("false")) {
+ return false;
+ }
// Decide if System.in is interactive
try {
POSIX posix = POSIXFactory.getPOSIX();
diff --git a/src/org/python/util/InteractiveConsole.java b/src/org/python/util/InteractiveConsole.java
--- a/src/org/python/util/InteractiveConsole.java
+++ b/src/org/python/util/InteractiveConsole.java
@@ -146,7 +146,9 @@
if (!exc.match(Py.EOFError)) {
throw exc;
}
- write("\n");
+ if (banner != null) {
+ write("\n");
+ }
break;
} catch (Throwable t) {
// catch jline.console.UserInterruptException, rethrow as a KeyboardInterrupt
diff --git a/src/org/python/util/jython.java b/src/org/python/util/jython.java
--- a/src/org/python/util/jython.java
+++ b/src/org/python/util/jython.java
@@ -408,11 +408,16 @@
if (opts.fixInteractive || (opts.filename == null && opts.command == null)) {
// Go interactive with the console: the parser needs to know the encoding.
String encoding = Py.getConsole().getEncoding();
-
// Run the interpreter interactively
try {
interp.cflags.encoding = encoding;
- interp.interact(null, null);
+ if (!opts.interactive) {
+ // Don't print prompts. http://bugs.jython.org/issue2325
+ interp._interact(null, null);
+ }
+ else {
+ interp.interact(null, null);
+ }
} catch (Throwable t) {
Py.printException(t);
}
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list