From: <pj...@us...> - 2009-10-31 01:46:36
|
Revision: 6935 http://jython.svn.sourceforge.net/jython/?rev=6935&view=rev Author: pjenvey Date: 2009-10-31 01:46:11 +0000 (Sat, 31 Oct 2009) Log Message: ----------- speedup the stat call as it can easily be performance critical, fix some __doc__ strings Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-30 23:53:24 UTC (rev 6934) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-31 01:46:11 UTC (rev 6935) @@ -18,6 +18,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; +import org.python.core.PyBuiltinFunction; import org.python.core.PyDictionary; import org.python.core.PyException; import org.python.core.PyFile; @@ -25,6 +26,7 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; +import org.python.core.ThreadState; import org.python.core.imp; import org.python.core.io.FileDescriptors; import org.python.core.io.FileIO; @@ -85,6 +87,7 @@ dict.__setitem__("O_TRUNC", Py.newInteger(O_TRUNC)); dict.__setitem__("O_EXCL", Py.newInteger(O_EXCL)); + // os.access flags dict.__setitem__("F_OK", Py.newInteger(F_OK)); dict.__setitem__("X_OK", Py.newInteger(X_OK)); dict.__setitem__("W_OK", Py.newInteger(W_OK)); @@ -99,6 +102,10 @@ dict.__setitem__("error", Py.OSError); dict.__setitem__("stat_result", PyStatResult.TYPE); + // Faster call paths + dict.__setitem__("lstat", new LstatFunction()); + dict.__setitem__("stat", new StatFunction()); + // Hide from Python Hider.hideFunctions(PosixModule.class, dict, os, nativePosix); dict.__setitem__("classDictInit", null); @@ -252,21 +259,21 @@ } } - public static PyString __doc___getcwd = new PyString( + public static PyString __doc__getcwd = new PyString( "getcwd() -> path\n\n" + "Return a string representing the current working directory."); public static PyObject getcwd() { return Py.newString(Py.getSystemState().getCurrentWorkingDir()); } - public static PyString __doc___getcwdu = new PyString( + public static PyString __doc__getcwdu = new PyString( "getcwd() -> path\n\n" + "Return a unicode string representing the current working directory."); public static PyObject getcwdu() { return Py.newUnicode(Py.getSystemState().getCurrentWorkingDir()); } - public static PyString __doc___getpid = new PyString( + public static PyString __doc__getpid = new PyString( "getpid() -> pid\n\n" + "Return the current process id"); @Hide(posixImpl = PosixImpl.JAVA) @@ -324,13 +331,6 @@ } } - public static PyString __doc__lstat = new PyString( - "lstat(path) -> stat result\n\n" + - "Like stat(path), but do not follow symbolic links."); - public static PyObject lstat(String path) { - return PyStatResult.fromFileStat(posix.lstat(absolutePath(path))); - } - public static PyString __doc__mkdir = new PyString( "mkdir(path [, mode=0777])\n\n" + "Create a directory."); @@ -424,15 +424,6 @@ unlink(path); } - public static PyString __doc__stat = new PyString( - "stat(path) -> stat result\n\n" + - "Perform a stat system call on the given path.\n\n" + - "Note that some platforms may return only a small subset of the\n" + - "standard fields"); - public static PyObject stat(String path) { - return PyStatResult.fromFileStat(posix.stat(absolutePath(path))); - } - public static PyString __doc__strerror = new PyString( "strerror(code) -> string\n\n" + "Translate an error code to a message string."); @@ -559,4 +550,42 @@ public static String getOSName() { return os.getModuleName(); } + + static class LstatFunction extends PyBuiltinFunction { + LstatFunction() { + super("lstat", + "lstat(path) -> stat result\n\n" + + "Like stat(path), but do not follow symbolic links."); + } + + @Override + public PyObject __call__(ThreadState state, PyObject pathObj) { + if (!(pathObj instanceof PyString)) { + throw Py.TypeError(String.format("coercing to Unicode: need string or buffer, %s " + + "found", pathObj.getType().fastGetName())); + } + String absolutePath = absolutePath(pathObj.toString()); + return PyStatResult.fromFileStat(posix.lstat(absolutePath)); + } + } + + static class StatFunction extends PyBuiltinFunction { + StatFunction() { + super("stat", + "stat(path) -> stat result\n\n" + + "Perform a stat system call on the given path.\n\n" + + "Note that some platforms may return only a small subset of the\n" + + "standard fields"); + } + + @Override + public PyObject __call__(ThreadState state, PyObject pathObj) { + if (!(pathObj instanceof PyString)) { + throw Py.TypeError(String.format("coercing to Unicode: need string or buffer, %s " + + "found", pathObj.getType().fastGetName())); + } + String absolutePath = absolutePath(pathObj.toString()); + return PyStatResult.fromFileStat(posix.stat(absolutePath)); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-03-21 17:52:42
|
Revision: 6987 http://jython.svn.sourceforge.net/jython/?rev=6987&view=rev Author: pjenvey Date: 2010-03-21 17:52:36 +0000 (Sun, 21 Mar 2010) Log Message: ----------- fix os.system not returning the command's exit code fixes #1577 and the test_chdir os.sytem tests patch from Alex Gr?\195?\182nholm Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2010-03-15 01:37:30 UTC (rev 6986) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2010-03-21 17:52:36 UTC (rev 6987) @@ -710,10 +710,10 @@ public static PyString __doc__system = new PyString( "system(command) -> exit_status\n\n" + "Execute the command (a string) in a subshell."); - public static void system(PyObject command) { - // import subprocess; subprocess.call(command, shell=True) - imp.load("subprocess").invoke("call", command, new PyObject[] {Py.True}, - new String[] {"shell"}); + public static PyObject system(PyObject command) { + // import subprocess; return subprocess.call(command, shell=True) + return imp.load("subprocess").invoke("call", command, new PyObject[] {Py.True}, + new String[] {"shell"}); } public static PyString __doc__umask = new PyString( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |