From: <pj...@us...> - 2009-10-20 04:05:02
|
Revision: 6884 http://jython.svn.sourceforge.net/jython/?rev=6884&view=rev Author: pjenvey Date: 2009-10-20 04:04:53 +0000 (Tue, 20 Oct 2009) Log Message: ----------- move _exit/listdir to PosixModule, get rid of a duplicate getlogin impl Modified Paths: -------------- trunk/jython/Lib/posix.py trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/Lib/posix.py =================================================================== --- trunk/jython/Lib/posix.py 2009-10-20 03:43:46 UTC (rev 6883) +++ trunk/jython/Lib/posix.py 2009-10-20 04:04:53 UTC (rev 6884) @@ -12,20 +12,18 @@ from _nt import * import errno import jarray -import java.lang.System import stat as _stat import sys from java.io import File from org.python.core.io import FileDescriptors, FileIO, IOBase from org.python.core.Py import newString as asPyString -__all__ = _posix.__all__[:] -__all__.extend(['_exit', 'access', 'chdir', 'chmod', 'close', 'fdopen', - 'fsync', 'ftruncate', 'getcwd', 'getcwdu', 'getenv', 'getpid', - 'isatty', 'listdir', 'lseek', 'mkdir', 'open', 'popen', - 'putenv', 'read', 'remove', 'rename', 'rmdir', 'system', - 'umask', 'unlink', 'unsetenv', 'urandom', 'utime', - 'write']) +__all__ = [name for name in _posix.__all__ if not name.startswith('__doc__')] +__all__.extend(['access', 'chdir', 'chmod', 'close', 'fdopen', 'fsync', + 'ftruncate', 'getcwd', 'getcwdu', 'getenv', 'getpid', 'isatty', + 'lseek', 'mkdir', 'open', 'popen', 'putenv', 'read', 'remove', + 'rename', 'rmdir', 'system', 'umask', 'unlink', 'unsetenv', + 'urandom', 'utime', 'write']) _name = _posix.__name__[1:] @@ -38,14 +36,6 @@ # Lazily loaded path module _path = None -def _exit(n=0): - """_exit(status) - - Exit to the system with specified status, without normal exit - processing. - """ - java.lang.System.exit(n) - def getcwd(): """getcwd() -> path @@ -73,21 +63,6 @@ _path = os.path sys.setCurrentWorkingDir(_path.realpath(path)) -def listdir(path): - """listdir(path) -> list_of_strings - - Return a list containing the names of the entries in the directory. - - path: path of directory to list - - The list is in arbitrary order. It does not include the special - entries '.' and '..' even if they are present in the directory. - """ - l = File(sys.getPath(path)).list() - if l is None: - raise OSError(0, 'No such directory', path) - return [asPyString(entry) for entry in l] - def chmod(path, mode): """chmod(path, mode) @@ -399,13 +374,6 @@ def __iter__(self): return iter(self._stream) -def getlogin(): - """getlogin() -> string - - Return the actual login name. - """ - return java.lang.System.getProperty("user.name") - def putenv(key, value): """putenv(key, value) Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-20 03:43:46 UTC (rev 6883) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-20 04:04:53 UTC (rev 6884) @@ -17,13 +17,14 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; +import org.python.core.util.RelativeFile; /** * The underlying _posix or _nt module, named depending on the platform. * * This currently contains only some of the basics of the posix/nt modules (which are - * implemented in Python). In particular things like the PythonPOSIXHandler that are - * slower to instantiate and thus would affect startup time. + * implemented in Python), most importantly things like PythonPOSIXHandler that are slower + * to instantiate and thus would affect startup time. * * Eventually more if not all of the pure Python module should end up here. */ @@ -42,9 +43,6 @@ private static POSIX posix = POSIXFactory.getPOSIX(new PythonPOSIXHandler(), true); public static void classDictInit(PyObject dict) { - dict.__setitem__("__name__", new PyString("_" + os.getModuleName())); - dict.__setitem__("__doc__", __doc__); - // os.open flags, only expose what we support dict.__setitem__("O_RDONLY", Py.newInteger(0x0)); dict.__setitem__("O_WRONLY", Py.newInteger(0x1)); @@ -75,13 +73,46 @@ dict.__setitem__("getOSName", null); dict.__setitem__("__all__", dict.invoke("keys")); + + dict.__setitem__("__name__", new PyString("_" + os.getModuleName())); + dict.__setitem__("__doc__", __doc__); } + public static PyString __doc___exit = new PyString( + "_exit(status)\n\n" + + "Exit to the system with specified status, without normal exit processing."); + public static void _exit() { + _exit(0); + } + + public static void _exit(int status) { + System.exit(status); + } + + public static PyString __doc__listdir = new PyString( + "listdir(path) -> list_of_strings\n\n" + + "Return a list containing the names of the entries in the directory.\n\n" + + "path: path of directory to list\n\n" + + "The list is in arbitrary order. It does not include the special\n" + + "entries '.' and '..' even if they are present in the directory."); + public static PyList listdir(String path) { + PyList list = new PyList(); + String[] files = new RelativeFile(path).list(); + + if (files == null) { + throw Py.OSError("No such directory: " + path); + } + for (String file : files) { + list.append(new PyString(file)); + } + return list; + } + 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(Py.getSystemState().getPath(path))); + return PyStatResult.fromFileStat(posix.lstat(new RelativeFile(path).getPath())); } public static PyString __doc__stat = new PyString( @@ -90,11 +121,11 @@ "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(Py.getSystemState().getPath(path))); + return PyStatResult.fromFileStat(posix.stat(new RelativeFile(path).getPath())); } public static PyString __doc__strerror = new PyString( - "strerror(code) -> string\n\n" + + "strerror(code) -> string\n\n" + "Translate an error code to a message string."); public static PyObject strerror(int code) { Constant errno = Errno.valueOf(code); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |