From: <pj...@us...> - 2008-07-31 19:50:52
|
Revision: 5030 http://jython.svn.sourceforge.net/jython/?rev=5030&view=rev Author: pjenvey Date: 2008-07-31 19:50:45 +0000 (Thu, 31 Jul 2008) Log Message: ----------- o fix test_softspace and reset softspace (and append a newline) in various places (equiv. of CPython's ceval.c::Py_FlushLine) o fix traceback source lines without trailing newlines (fixes #1087) Modified Paths: -------------- branches/asm/Lib/test/regrtest.py branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTraceback.java branches/asm/src/org/python/core/StdoutWrapper.java branches/asm/src/org/python/util/PythonInterpreter.java Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/Lib/test/regrtest.py 2008-07-31 19:50:45 UTC (rev 5030) @@ -1493,7 +1493,6 @@ test_pyclbr test_quopri test_random - test_softspace test_syntax test_trace test_ucn Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/Py.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -992,6 +992,7 @@ exceptHook.__call__(exc.type, exc.value, exc.traceback); } catch (PyException exc2) { exc2.normalize(); + flushLine(); stderr.println("Error in sys.excepthook:"); displayException(exc2.type, exc2.value, exc2.traceback, file); stderr.println(); @@ -1006,12 +1007,13 @@ ts.exception = null; } - public static void displayException(PyObject type, PyObject value, - PyObject tb, PyObject file) { + public static void displayException(PyObject type, PyObject value, PyObject tb, + PyObject file) { StdoutWrapper stderr = Py.stderr; if (file != null) { stderr = new FixedFileWrapper(file); } + flushLine(); if (tb instanceof PyTraceback) { stderr.print(((PyTraceback) tb).dumpStack()); @@ -1317,6 +1319,10 @@ stdout.println(); } + public static void flushLine() { + stdout.flushLine(); + } + /* * A collection of convenience functions for converting PyObjects to Java primitives */ Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PySystemState.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -342,6 +342,7 @@ Py.printException(exc); } } + Py.flushLine(); } public ClassLoader getClassLoader() { Modified: branches/asm/src/org/python/core/PyTraceback.java =================================================================== --- branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -90,6 +90,11 @@ i++; } line = line.substring(i); + if (!line.endsWith("\n")) { + line += "\n"; + } + } else { + line = null; } return line; } Modified: branches/asm/src/org/python/core/StdoutWrapper.java =================================================================== --- branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -46,7 +46,11 @@ if (obj instanceof PyFile) { ((PyFile) obj).flush(); } else { - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } } } @@ -68,7 +72,7 @@ write(StringUtil.fromBytes(data, off, len)); } - public void clearSoftspace() { + public void flushLine() { PyObject obj = myFile(); if (obj instanceof PyFile) { @@ -83,45 +87,63 @@ if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Newline); } - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } obj.__setattr__("softspace", Py.Zero); } } public void print(PyObject o, boolean space, boolean newline) { - PyString string = o.__str__(); PyObject obj = myFile(); if (obj instanceof PyFile) { - PyFile file = (PyFile) obj; + PyFile file = (PyFile)obj; + if (file.softspace) { + file.write(" "); + file.softspace = false; + } + PyString string = o.__str__(); String s = string.toString(); + int len = s.length(); + file.write(s); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + file.softspace = space; + } + } else { + file.softspace = space; + } if (newline) { - s = s + "\n"; + file.write("\n"); + file.softspace = false; } - if (file.softspace) { - s = " " + s; - } - file.write(s); file.flush(); - if (space && s.endsWith("\n")) { - space = false; - } - file.softspace = space; } else { PyObject ss = obj.__findattr__("softspace"); if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Space); + obj.__setattr__("softspace", Py.Zero); } + PyString string = o.__str__(); + String s = o.toString(); + int len = s.length(); obj.invoke("write", string); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } + } else { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } if (newline) { obj.invoke("write", Py.Newline); + obj.__setattr__("softspace", Py.Zero); } - // obj.invoke("flush"); - - if (space && string.toString().endsWith("\n")) { - space = false; - } - obj.__setattr__("softspace", space ? Py.One : Py.Zero); } } Modified: branches/asm/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -121,6 +121,7 @@ setState(); Py.exec(Py.compile_flags(s, "<string>", "exec",cflags), locals, locals); + Py.flushLine(); } /** @@ -131,6 +132,7 @@ public void exec(PyObject code) { setState(); Py.exec(code, locals, locals); + Py.flushLine(); } /** @@ -141,6 +143,7 @@ public void execfile(String s) { setState(); __builtin__.execfile_flags(s, locals, locals, cflags); + Py.flushLine(); } public void execfile(java.io.InputStream s) { @@ -150,6 +153,7 @@ public void execfile(java.io.InputStream s, String name) { setState(); Py.runCode((PyCode)Py.compile_flags(s, name, "exec",cflags), locals, locals); + Py.flushLine(); } // Getting and setting the locals dictionary This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |