From: <pj...@us...> - 2009-10-20 00:54:09
|
Revision: 6879 http://jython.svn.sourceforge.net/jython/?rev=6879&view=rev Author: pjenvey Date: 2009-10-20 00:54:00 +0000 (Tue, 20 Oct 2009) Log Message: ----------- o constantine lacks sensible Windows OpenFlags constants, roll our own o fix put/unset/getenv on Windows 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 00:20:58 UTC (rev 6878) +++ trunk/jython/Lib/posix.py 2009-10-20 00:54:00 UTC (rev 6879) @@ -320,7 +320,6 @@ try: fchannel = RandomAccessFile(sys.getPath(filename), 'rws').getChannel() except FileNotFoundException, fnfe: - #if path.isdir(filename): if _stat.S_ISDIR(stat(filename).st_mode): raise OSError(errno.EISDIR, strerror(errno.EISDIR)) raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) @@ -414,20 +413,26 @@ Change or add an environment variable. """ - environ[key] = value + # XXX: put/unset/getenv should probably be deprecated + import os + os.environ[key] = value def unsetenv(key): """unsetenv(key) Delete an environment variable. """ - if key in environ: - del environ[key] + import os + try: + del os.environ[key] + except KeyError: + pass def getenv(key, default=None): """Get an environment variable, return None if it doesn't exist. The optional second argument can specify an alternate default.""" - return environ.get(key, default) + import os + return os.environ.get(key, default) if _name == 'posix': def link(src, dst): Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-20 00:20:58 UTC (rev 6878) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-20 00:54:00 UTC (rev 6879) @@ -2,7 +2,6 @@ package org.python.modules.posix; import com.kenai.constantine.Constant; -import com.kenai.constantine.ConstantSet; import com.kenai.constantine.platform.Errno; import org.jruby.ext.posix.JavaPOSIX; @@ -39,18 +38,20 @@ /** Platform specific POSIX services. */ private static POSIX posix = POSIXFactory.getPOSIX(new PythonPOSIXHandler(), true); - private static final String[] openFlags = - {"O_RDONLY", "O_WRONLY", "O_RDWR", "O_APPEND", "O_SYNC", "O_CREAT", "O_TRUNC", "O_EXCL"}; - 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 - ConstantSet openFlagConstants = ConstantSet.getConstantSet("OpenFlags"); - for (String openFlag : openFlags) { - dict.__setitem__(openFlag, Py.newInteger(openFlagConstants.getValue(openFlag))); - } + dict.__setitem__("O_RDONLY", Py.newInteger(0x0)); + dict.__setitem__("O_WRONLY", Py.newInteger(0x1)); + dict.__setitem__("O_RDWR", Py.newInteger(0x2)); + dict.__setitem__("O_APPEND", Py.newInteger(0x8)); + dict.__setitem__("O_SYNC", Py.newInteger(0x80)); + dict.__setitem__("O_CREAT", Py.newInteger(0x200)); + dict.__setitem__("O_TRUNC", Py.newInteger(0x400)); + dict.__setitem__("O_EXCL", Py.newInteger(0x800)); + // os.access constants dict.__setitem__("F_OK", Py.Zero); dict.__setitem__("X_OK", Py.newInteger(1 << 0)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |