From: <pj...@us...> - 2008-11-14 07:36:05
|
Revision: 5578 http://jython.svn.sourceforge.net/jython/?rev=5578&view=rev Author: pjenvey Date: 2008-11-14 07:35:53 +0000 (Fri, 14 Nov 2008) Log Message: ----------- bring in constantine (0.3dev r80) for better errnos Modified Paths: -------------- trunk/jython/Lib/os.py trunk/jython/Lib/subprocess.py trunk/jython/Lib/test/test_chdir.py trunk/jython/Lib/test/test_fileno.py trunk/jython/build.xml trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/IOBase.java trunk/jython/src/org/python/core/io/ServerSocketIO.java trunk/jython/src/org/python/modules/_py_compile.java trunk/jython/src/org/python/modules/errno.java Added Paths: ----------- trunk/jython/extlibs/constantine.jar Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/Lib/os.py 2008-11-14 07:35:53 UTC (rev 5578) @@ -46,6 +46,7 @@ import stat as _stat import sys from java.io import File +from org.python.constantine.platform import Errno from org.python.core.io import FileDescriptors, FileIO, IOBase from org.python.core.Py import newString as asPyString @@ -101,7 +102,7 @@ err = getattr(errno, error.name(), None) if err is None: raise OSError('%s: %s' % (error, msg)) - raise OSError(err, errno.strerror(err), msg) + raise OSError(err, strerror(err), msg) def unimplementedError(self, method_name): raise NotImplementedError(method_name) def warn(self, warning_id, msg, rest): @@ -246,9 +247,9 @@ """ realpath = _path.realpath(path) if not _path.exists(realpath): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) if not _path.isdir(realpath): - raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOTDIR), path) + raise OSError(errno.ENOTDIR, strerror(errno.ENOTDIR), path) sys.setCurrentWorkingDir(realpath) def listdir(path): @@ -275,7 +276,7 @@ # catch not found errors explicitly here, for now abs_path = sys.getPath(path) if not File(abs_path).exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) _posix.chmod(abs_path, mode) def mkdir(path, mode='ignored'): @@ -292,7 +293,7 @@ err = errno.EEXIST else: err = 0 - msg = errno.strerror(err) if err else "couldn't make directory" + msg = strerror(err) if err else "couldn't make directory" raise OSError(err, msg, path) def makedirs(path, mode='ignored'): @@ -371,9 +372,9 @@ Remove a directory.""" f = File(sys.getPath(path)) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) elif not f.isDirectory(): - raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOTDIR), path) + raise OSError(errno.ENOTDIR, strerror(errno.ENOTDIR), path) elif not f.delete(): raise OSError(0, "couldn't delete directory", path) @@ -409,10 +410,17 @@ """ if not isinstance(code, (int, long)): raise TypeError('an integer is required') - try: - return errno.strerror(code) - except KeyError: + constant = Errno.valueOf(code) + if constant is Errno.__UNKNOWN_CONSTANT__: return 'Unknown error: %d' % code + if constant.name() == constant.description(): + # XXX: have constantine handle this fallback + # Fake constant or just lacks a description, fallback to Linux's + from org.python.constantine.platform.linux import Errno as LinuxErrno + constant = getattr(LinuxErrno, constant.name(), None) + if not constant: + return 'Unknown error: %d' % code + return asPyString(constant.toString()) def access(path, mode): """access(path, mode) -> True if granted, False otherwise @@ -459,7 +467,7 @@ raise f = File(abs_path) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) size = f.length() mtime = f.lastModified() / 1000.0 mode = 0 @@ -509,7 +517,7 @@ # Not a link, only now can we determine if it exists (because # File.exists() returns False for dead links) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) return stat(path) def utime(path, times): @@ -550,12 +558,12 @@ if (len(mode) and mode[0] or '') not in 'rwa': raise ValueError("invalid file mode '%s'" % mode) if rawio.closed(): - raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) + raise OSError(errno.EBADF, strerror(errno.EBADF)) try: fp = FileDescriptors.wrap(rawio, mode, bufsize) except IOError: - raise OSError(errno.EINVAL, errno.strerror(errno.EINVAL)) + raise OSError(errno.EINVAL, strerror(errno.EINVAL)) return fp def ftruncate(fd, length): @@ -567,7 +575,7 @@ try: rawio.truncate(length) except Exception, e: - raise IOError(errno.EBADF, errno.strerror(errno.EBADF)) + raise IOError(errno.EBADF, strerror(errno.EBADF)) def lseek(fd, pos, how): """lseek(fd, pos, how) -> newpos @@ -593,10 +601,10 @@ appending = flag & O_APPEND if updating and writing: - raise OSError(errno.EINVAL, errno.strerror(errno.EINVAL), filename) + raise OSError(errno.EINVAL, strerror(errno.EINVAL), filename) if not creating and not path.exists(filename): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), filename) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) if not writing: if updating: @@ -611,7 +619,7 @@ if exclusive and creating: try: if not File(sys.getPath(filename)).createNewFile(): - raise OSError(errno.EEXIST, errno.strerror(errno.EEXIST), + raise OSError(errno.EEXIST, strerror(errno.EEXIST), filename) except java.io.IOException, ioe: raise OSError(ioe) @@ -627,8 +635,8 @@ fchannel = RandomAccessFile(sys.getPath(filename), 'rws').getChannel() except FileNotFoundException, fnfe: if path.isdir(filename): - raise OSError(errno.EISDIR, errno.strerror(errno.EISDIR)) - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), filename) + raise OSError(errno.EISDIR, strerror(errno.EISDIR)) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) return FileIO(fchannel, mode) return FileIO(filename, mode) @@ -659,7 +667,7 @@ try: return func(*args, **kwargs) except: - raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) + raise OSError(errno.EBADF, strerror(errno.EBADF)) if _name == 'posix' and _native_posix: def link(src, dst): Modified: trunk/jython/Lib/subprocess.py =================================================================== --- trunk/jython/Lib/subprocess.py 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/Lib/subprocess.py 2008-11-14 07:35:53 UTC (rev 5578) @@ -1169,9 +1169,9 @@ if cwd is None: cwd = os.getcwd() elif not os.path.exists(cwd): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), cwd) + raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), cwd) elif not os.path.isdir(cwd): - raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOENT), cwd) + raise OSError(errno.ENOTDIR, os.strerror(errno.ENOENT), cwd) builder.directory(java.io.File(cwd)) # Let Java manage redirection of stderr to stdout (it's more Modified: trunk/jython/Lib/test/test_chdir.py =================================================================== --- trunk/jython/Lib/test/test_chdir.py 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/Lib/test/test_chdir.py 2008-11-14 07:35:53 UTC (rev 5578) @@ -177,10 +177,11 @@ def test_invalid_chdir(self): raises(OSError, - '[Errno 2] No such file or directory: %r' % self.filename1, + '[Errno 2] %s: %r' % (os.strerror(2), self.filename1), os.chdir, self.filename1) open(self.filename1, 'w').close() - raises(OSError, '[Errno 20] Not a directory: %r' % self.filename1, + raises(OSError, + '[Errno 20] %s: %r' % (os.strerror(20), self.filename1), os.chdir, self.filename1) Modified: trunk/jython/Lib/test/test_fileno.py =================================================================== --- trunk/jython/Lib/test/test_fileno.py 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/Lib/test/test_fileno.py 2008-11-14 07:35:53 UTC (rev 5578) @@ -31,8 +31,7 @@ self.assertEqual(os.path.getsize(self.filename), 0) self.fp.close() - raises(IOError, '[Errno 9] Bad file descriptor', - os.ftruncate, self.fd, 0) + raises(IOError, 9, os.ftruncate, self.fd, 0) def test_lseek(self): self.assertEqual(os.lseek(self.fd, 0, 1), 0) @@ -40,8 +39,7 @@ os.lseek(self.fd, 7, 0) self.assertEqual(os.read(self.fd, 7), 'filenos') self.fp.close() - raises(OSError, '[Errno 9] Bad file descriptor', - os.lseek, self.fd, 0, 1) + raises(OSError, 9, os.lseek, self.fd, 0, 1) def test_read(self): self.fp.write('jython filenos') @@ -50,16 +48,14 @@ self.assertEqual(os.read(self.fd, 7), 'jython ') self.assertEqual(os.read(self.fd, 99), 'filenos') self.fp.close() - raises(OSError, '[Errno 9] Bad file descriptor', - os.read, self.fd, 1) + raises(OSError, 9, os.read, self.fd, 1) def test_write(self): os.write(self.fd, 'jython filenos') self.fp.seek(0) self.assertEqual(self.fp.read(), 'jython filenos') self.fp.close() - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'The Larch') + raises(OSError, 9, os.write, self.fd, 'The Larch') class TestOsOpenTestCase(unittest.TestCase): @@ -96,8 +92,7 @@ # falls back to read only without O_WRONLY/O_RDWR self.fd = os.open(self.filename, os.O_APPEND) - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'new') + raises(OSError, 9, os.write, self.fd, 'new') # Acts as append on windows (seeks to the end) os.lseek(self.fd, 0, 0) self.assertEquals(os.read(self.fd, len('jython filenos')), 'jython filenos') @@ -105,8 +100,7 @@ # falls back to read only without O_WRONLY/O_RDWR self.fd = os.open(self.filename, os.O_CREAT) - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'new') + raises(OSError, 9, os.write, self.fd, 'new') self.assertEquals(os.read(self.fd, len('jython filenos')), 'jython filenos') os.close(self.fd) @@ -133,8 +127,7 @@ self.fd = os.open(self.filename, os.O_TRUNC | os.O_WRONLY) self.assertEquals(os.path.getsize(self.filename), 0) os.write(self.fd, 'write only truncated') - raises(OSError, '[Errno 9] Bad file descriptor', - os.read, self.fd, 99) + raises(OSError, 9, os.read, self.fd, 99) os.close(self.fd) fd = open(self.filename) @@ -146,8 +139,7 @@ # falls back to read only without O_WRONLY/O_RDWR, but truncates self.fd = os.open(self.filename, os.O_TRUNC) self.assertEquals(os.path.getsize(self.filename), 0) - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'new') + raises(OSError, 9, os.write, self.fd, 'new') self.assertEquals(os.read(self.fd, 99), '') os.close(self.fd) @@ -159,8 +151,7 @@ # append with no write falls back to read, but still truncates self.fd = os.open(self.filename, os.O_TRUNC | os.O_APPEND) self.assertEquals(os.path.getsize(self.filename), 0) - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'new') + raises(OSError, 9, os.write, self.fd, 'new') os.close(self.fd) fp = open(self.filename, 'w') @@ -172,26 +163,23 @@ def test_open_exclusive(self): self.assert_(not os.path.exists(self.filename)) # fails without O_CREAT - raises(OSError, '[Errno 2] No such file or directory: %r' % \ - self.filename, - os.open, self.filename, os.O_EXCL) + raises(OSError, (2, self.filename), os.open, self.filename, os.O_EXCL) self.assert_(not os.path.exists(self.filename)) # creates, read only self.fd = os.open(self.filename, os.O_EXCL | os.O_CREAT) self.assert_(os.path.exists(self.filename)) - raises(OSError, '[Errno 9] Bad file descriptor', - os.write, self.fd, 'jython') + raises(OSError, 9, os.write, self.fd, 'jython') self.assertEquals(os.read(self.fd, 99), '') os.close(self.fd) # not exclusive unless creating os.close(os.open(self.filename, os.O_EXCL)) - raises(OSError, '[Errno 17] File exists: %r' % self.filename, + raises(OSError, (17, self.filename), os.open, self.filename, os.O_CREAT | os.O_EXCL) - raises(OSError, '[Errno 17] File exists: %r' % self.filename, + raises(OSError, (17, self.filename), os.open, self.filename, os.O_CREAT | os.O_WRONLY | os.O_EXCL) - raises(OSError, '[Errno 17] File exists: %r' % self.filename, + raises(OSError, (17, self.filename), os.open, self.filename, os.O_CREAT | os.O_RDWR | os.O_EXCL) os.remove(self.filename) @@ -208,8 +196,7 @@ self.fd = os.open(self.filename, os.O_SYNC | os.O_WRONLY | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') - raises(OSError, '[Errno 9] Bad file descriptor', - os.read, self.fd, 99) + raises(OSError, 9, os.read, self.fd, 99) os.close(self.fd) os.remove(self.filename) @@ -232,12 +219,11 @@ def test_bad_open(self): for mode in (os.O_WRONLY, os.O_WRONLY, os.O_RDWR): - raises(OSError, '[Errno 2] No such file or directory: %r' % \ - self.filename, os.open, self.filename, mode) + raises(OSError, (2, self.filename), os.open, self.filename, mode) open(self.filename, 'w').close() - raises(OSError, '[Errno 22] Invalid argument: %r' % self.filename, + raises(OSError, (22, self.filename), os.open, self.filename, os.O_WRONLY | os.O_RDWR) @@ -321,12 +307,26 @@ def raises(exc, expected, callable, *args): + """Ensure the specified call raises exc. + + expected is compared against the exception message if not None. It + can be a str, an errno or a 2 item tuple of errno/filename. The + latter two being for comparison against EnvironmentErrors. + """ + if expected: + if isinstance(expected, str): + msg = expected + else: + errno = expected[0] if isinstance(expected, tuple) else expected + msg = '[Errno %d] %s' % (errno, os.strerror(errno)) + if isinstance(expected, tuple): + msg += ': %r' % expected[1] try: callable(*args) - except exc, msg: - if expected is not None and str(msg) != expected: + except exc, val: + if expected and str(val) != msg: raise test_support.TestFailed( - "Message %r, expected %r" % (str(msg), expected)) + "Message %r, expected %r" % (str(value), msg)) else: raise test_support.TestFailed("Expected %s" % exc) Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/build.xml 2008-11-14 07:35:53 UTC (rev 5578) @@ -525,6 +525,8 @@ <zipfileset src="extlibs/jna-posix.jar"/> <!-- <rule pattern="com.sun.jna.**" result="org.python.jna.@1"/> --> <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> + <zipfileset src="extlibs/constantine.jar"/> + <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> </jarjar> <unjar src="${output.dir}/jarjar.jar" dest="${jarjar.dir}"> <patternset> Added: trunk/jython/extlibs/constantine.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/constantine.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/core/Py.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -22,11 +23,11 @@ import java.util.Set; import org.python.antlr.ast.modType; +import org.python.constantine.platform.Errno; import org.python.compiler.Module; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; import org.python.core.util.StringUtil; -import org.python.modules.errno; public final class Py { @@ -144,14 +145,15 @@ } public static PyObject IOError; - public static PyException IOError(java.io.IOException ioe) { + public static PyException IOError(IOException ioe) { String message = ioe.getMessage(); if (message == null) { message = ioe.getClass().getName(); } - if (ioe instanceof java.io.FileNotFoundException) { - message = "File not found - " + message; - return IOError(errno.ENOENT, message); + if (ioe instanceof FileNotFoundException) { + PyTuple args = new PyTuple(Py.newInteger(Errno.ENOENT.value()), + Py.newString("File not found - " + message)); + return new PyException(Py.IOError, args); } return new PyException(Py.IOError, message); } @@ -160,10 +162,18 @@ return new PyException(Py.IOError, message); } - public static PyException IOError(int errno, String message) { - PyTuple args = new PyTuple(new PyInteger(errno), new PyString(message)); + public static PyException IOError(Errno errno) { + PyObject args = new PyTuple(Py.newInteger(errno.value()), + Py.newString(errno.description())); return new PyException(Py.IOError, args); } + + public static PyException IOError(Errno errno, String filename) { + PyObject args = new PyTuple(Py.newInteger(errno.value()), + Py.newString(errno.description()), Py.newString(filename)); + return new PyException(Py.IOError, args); + } + public static PyObject KeyError; public static PyException KeyError(String message) { Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/core/io/FileIO.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -12,11 +12,11 @@ import java.nio.channels.Channels; import java.nio.channels.FileChannel; +import org.python.constantine.platform.Errno; import org.python.core.imp; import org.python.core.Py; import org.python.core.PyObject; import org.python.core.util.RelativeFile; -import org.python.modules.errno; /** * Raw I/O implementation for OS files. @@ -67,13 +67,13 @@ fileChannel = file.getChannel(); } catch (FileNotFoundException fnfe) { if (fullPath.isDirectory()) { - throw Py.IOError(errno.EISDIR, "Is a directory"); + throw Py.IOError(Errno.EISDIR, name); } if ((writing && !fullPath.canWrite()) || fnfe.getMessage().endsWith("(Permission denied)")) { - throw Py.IOError(errno.EACCES, "Permission denied: '" + name + "'"); + throw Py.IOError(Errno.EACCES, name); } - throw Py.IOError(errno.ENOENT, "No such file or directory: '" + name + "'"); + throw Py.IOError(Errno.ENOENT, name); } initPosition(); @@ -289,7 +289,7 @@ pos += fileChannel.size(); break; default: - throw Py.IOError(errno.EINVAL, "invalid whence value"); + throw Py.IOError(Errno.EINVAL); } fileChannel.position(pos); return pos; Modified: trunk/jython/src/org/python/core/io/IOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/IOBase.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/core/io/IOBase.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -1,9 +1,9 @@ /* Copyright (c) 2007 Jython Developers */ package org.python.core.io; +import org.python.constantine.platform.Errno; import org.python.core.Py; import org.python.core.PyException; -import org.python.modules.errno; /** * Base class for all I/O classes. @@ -148,7 +148,7 @@ */ public void checkReadable() { if (!readable()) { - throw Py.IOError(errno.EBADF, "Bad file descriptor"); + throw Py.IOError(Errno.EBADF); } } @@ -167,7 +167,7 @@ */ public void checkWritable() { if (!writable()) { - throw Py.IOError(errno.EBADF, "Bad file descriptor"); + throw Py.IOError(Errno.EBADF); } } Modified: trunk/jython/src/org/python/core/io/ServerSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/ServerSocketIO.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/core/io/ServerSocketIO.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -6,8 +6,8 @@ import java.nio.channels.Channel; import java.nio.channels.ServerSocketChannel; +import org.python.constantine.platform.Errno; import org.python.core.Py; -import org.python.modules.errno; /** * Raw I/O implementation for server sockets. @@ -34,14 +34,14 @@ public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); - throw Py.IOError(errno.ENOTCONN, "Socket is not connected"); + throw Py.IOError(Errno.ENOTCONN); } /** {@inheritDoc} */ public int write(ByteBuffer buf) { checkClosed(); checkWritable(); - throw Py.IOError(errno.EBADF, "Bad file descriptor"); + throw Py.IOError(Errno.EBADF); } /** {@inheritDoc} */ Modified: trunk/jython/src/org/python/modules/_py_compile.java =================================================================== --- trunk/jython/src/org/python/modules/_py_compile.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/modules/_py_compile.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -3,6 +3,7 @@ import java.io.File; +import org.python.constantine.platform.Errno; import org.python.core.Py; import org.python.core.PyList; import org.python.core.PyString; @@ -20,7 +21,7 @@ File file = new File(filename); if (!file.exists()) { - throw Py.IOError(errno.ENOENT, "No such file or directory: '" + filename + "'"); + throw Py.IOError(Errno.ENOENT, filename); } String name = file.getName(); int dot = name.lastIndexOf('.'); Modified: trunk/jython/src/org/python/modules/errno.java =================================================================== --- trunk/jython/src/org/python/modules/errno.java 2008-11-14 00:28:42 UTC (rev 5577) +++ trunk/jython/src/org/python/modules/errno.java 2008-11-14 07:35:53 UTC (rev 5578) @@ -1,288 +1,63 @@ +/* Copyright (c) Jython Developers */ package org.python.modules; -import org.python.core.*; +import org.python.constantine.Constant; +import org.python.constantine.ConstantSet; +import org.python.core.ClassDictInit; +import org.python.core.Py; +import org.python.core.PyDictionary; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.imp; /** - * This file contains autogenerated error codes from:<br/> - * <b>Python 2.2.1 (#5, Oct 7 2002, 09:20:38) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-97)]</b> + * The Python errno module. * - * @author brian zimmer - * @version 2.2.1 - * @copyright 2002 brian zimmer + * Errno constants can be accessed from Java code via + * {@link org.python.constantine.platform.Errno}, e.g. Errno.ENOENT. */ -public final class errno implements ClassDictInit { +public class errno implements ClassDictInit { - private errno() {} + public static final PyString __doc__ = Py.newString( + "This module makes available standard errno system symbols.\n\n" + + "The value of each symbol is the corresponding integer value,\n" + + "e.g., on most systems, errno.ENOENT equals the integer 2.\n\n" + + "The dictionary errno.errorcode maps numeric codes to symbol names,\n" + + "e.g., errno.errorcode[2] could be the string 'ENOENT'.\n\n" + + "Symbols that are not relevant to the underlying system are not defined.\n\n" + + "To map error codes to error messages, use the function os.strerror(),\n" + + "e.g. os.strerror(2) could return 'No such file or directory'."); - public static final int EPERM = 1; - public static final int ENOENT = 2; - public static final int ESRCH = 3; - public static final int EINTR = 4; - public static final int EIO = 5; - public static final int ENXIO = 6; - public static final int E2BIG = 7; - public static final int ENOEXEC = 8; - public static final int EBADF = 9; - public static final int ECHILD = 10; - public static final int EAGAIN = 11; - public static final int EWOULDBLOCK = 11; - public static final int ENOMEM = 12; - public static final int EACCES = 13; - public static final int EFAULT = 14; - public static final int ENOTBLK = 15; - public static final int EBUSY = 16; - public static final int EEXIST = 17; - public static final int EXDEV = 18; - public static final int ENODEV = 19; - public static final int ENOTDIR = 20; - public static final int EISDIR = 21; - public static final int EINVAL = 22; - public static final int ENFILE = 23; - public static final int EMFILE = 24; - public static final int ENOTTY = 25; - public static final int ETXTBSY = 26; - public static final int EFBIG = 27; - public static final int ENOSPC = 28; - public static final int ESPIPE = 29; - public static final int EROFS = 30; - public static final int EMLINK = 31; - public static final int EPIPE = 32; - public static final int EDOM = 33; - public static final int ERANGE = 34; - public static final int EDEADLK = 35; - public static final int EDEADLOCK = 35; - public static final int ENAMETOOLONG = 36; - public static final int ENOLCK = 37; - public static final int ENOSYS = 38; - public static final int ENOTEMPTY = 39; - public static final int ELOOP = 40; - public static final int ENOMSG = 42; - public static final int EIDRM = 43; - public static final int ECHRNG = 44; - public static final int EL2NSYNC = 45; - public static final int EL3HLT = 46; - public static final int EL3RST = 47; - public static final int ELNRNG = 48; - public static final int EUNATCH = 49; - public static final int ENOCSI = 50; - public static final int EL2HLT = 51; - public static final int EBADE = 52; - public static final int EBADR = 53; - public static final int EXFULL = 54; - public static final int ENOANO = 55; - public static final int EBADRQC = 56; - public static final int EBADSLT = 57; - public static final int EBFONT = 59; - public static final int ENOSTR = 60; - public static final int ENODATA = 61; - public static final int ETIME = 62; - public static final int ENOSR = 63; - public static final int ENONET = 64; - public static final int ENOPKG = 65; - public static final int EREMOTE = 66; - public static final int ENOLINK = 67; - public static final int EADV = 68; - public static final int ESRMNT = 69; - public static final int ECOMM = 70; - public static final int EPROTO = 71; - public static final int EMULTIHOP = 72; - public static final int EDOTDOT = 73; - public static final int EBADMSG = 74; - public static final int EOVERFLOW = 75; - public static final int ENOTUNIQ = 76; - public static final int EBADFD = 77; - public static final int EREMCHG = 78; - public static final int ELIBACC = 79; - public static final int ELIBBAD = 80; - public static final int ELIBSCN = 81; - public static final int ELIBMAX = 82; - public static final int ELIBEXEC = 83; - public static final int EILSEQ = 84; - public static final int ERESTART = 85; - public static final int ESTRPIPE = 86; - public static final int EUSERS = 87; - public static final int ENOTSOCK = 88; - public static final int EDESTADDRREQ = 89; - public static final int EMSGSIZE = 90; - public static final int EPROTOTYPE = 91; - public static final int ENOPROTOOPT = 92; - public static final int EPROTONOSUPPORT = 93; - public static final int ESOCKTNOSUPPORT = 94; - public static final int EOPNOTSUPP = 95; - public static final int EPFNOSUPPORT = 96; - public static final int EAFNOSUPPORT = 97; - public static final int EADDRINUSE = 98; - public static final int EADDRNOTAVAIL = 99; - public static final int ENETDOWN = 100; - public static final int ENETUNREACH = 101; - public static final int ENETRESET = 102; - public static final int ECONNABORTED = 103; - public static final int ECONNRESET = 104; - public static final int ENOBUFS = 105; - public static final int EISCONN = 106; - public static final int ENOTCONN = 107; - public static final int ESHUTDOWN = 108; - public static final int ETOOMANYREFS = 109; - public static final int ETIMEDOUT = 110; - public static final int ECONNREFUSED = 111; - public static final int EHOSTDOWN = 112; - public static final int EHOSTUNREACH = 113; - public static final int EALREADY = 114; - public static final int EINPROGRESS = 115; - public static final int ESTALE = 116; - public static final int EUCLEAN = 117; - public static final int ENOTNAM = 118; - public static final int ENAVAIL = 119; - public static final int EISNAM = 120; - public static final int EREMOTEIO = 121; - public static final int EDQUOT = 122; - - // AMAK: Starting a new series of jython specific error numbers - public static final int ESOCKISBLOCKING = 20000; - public static final int EGETADDRINFOFAILED = 20001; - + /** Reverse mapping of codes to names. */ public static final PyObject errorcode = new PyDictionary(); - private static final PyObject strerror = new PyDictionary(); - public static void classDictInit(PyObject dict) throws PyIgnoreMethodTag { - addcode(dict, EPERM, "EPERM", "Operation not permitted"); - addcode(dict, ENOENT, "ENOENT", "No such file or directory"); - addcode(dict, ESRCH, "ESRCH", "No such process"); - addcode(dict, EINTR, "EINTR", "Interrupted system call"); - addcode(dict, EIO, "EIO", "Input/output error"); - addcode(dict, ENXIO, "ENXIO", "Device not configured"); - addcode(dict, E2BIG, "E2BIG", "Argument list too long"); - addcode(dict, ENOEXEC, "ENOEXEC", "Exec format error"); - addcode(dict, EBADF, "EBADF", "Bad file descriptor"); - addcode(dict, ECHILD, "ECHILD", "No child processes"); - addcode(dict, EAGAIN, "EAGAIN", "Resource temporarily unavailable"); - addcode(dict, EWOULDBLOCK, "EWOULDBLOCK", "Resource temporarily unavailable"); - addcode(dict, ENOMEM, "ENOMEM", "Cannot allocate memory"); - addcode(dict, EACCES, "EACCES", "Permission denied"); - addcode(dict, EFAULT, "EFAULT", "Bad address"); - addcode(dict, ENOTBLK, "ENOTBLK", "Block device required"); - addcode(dict, EBUSY, "EBUSY", "Device or resource busy"); - addcode(dict, EEXIST, "EEXIST", "File exists"); - addcode(dict, EXDEV, "EXDEV", "Invalid cross-device link"); - addcode(dict, ENODEV, "ENODEV", "No such device"); - addcode(dict, ENOTDIR, "ENOTDIR", "Not a directory"); - addcode(dict, EISDIR, "EISDIR", "Is a directory"); - addcode(dict, EINVAL, "EINVAL", "Invalid argument"); - addcode(dict, ENFILE, "ENFILE", "Too many open files in system"); - addcode(dict, EMFILE, "EMFILE", "Too many open files"); - addcode(dict, ENOTTY, "ENOTTY", "Inappropriate ioctl for device"); - addcode(dict, ETXTBSY, "ETXTBSY", "Text file busy"); - addcode(dict, EFBIG, "EFBIG", "File too large"); - addcode(dict, ENOSPC, "ENOSPC", "No space left on device"); - addcode(dict, ESPIPE, "ESPIPE", "Illegal seek"); - addcode(dict, EROFS, "EROFS", "Read-only file system"); - addcode(dict, EMLINK, "EMLINK", "Too many links"); - addcode(dict, EPIPE, "EPIPE", "Broken pipe"); - addcode(dict, EDOM, "EDOM", "Numerical argument out of domain"); - addcode(dict, ERANGE, "ERANGE", "Numerical result out of range"); - addcode(dict, EDEADLK, "EDEADLK", "Resource deadlock avoided"); - addcode(dict, EDEADLOCK, "EDEADLOCK", "Resource deadlock avoided"); - addcode(dict, ENAMETOOLONG, "ENAMETOOLONG", "File name too long"); - addcode(dict, ENOLCK, "ENOLCK", "No locks available"); - addcode(dict, ENOSYS, "ENOSYS", "Function not implemented"); - addcode(dict, ENOTEMPTY, "ENOTEMPTY", "Directory not empty"); - addcode(dict, ELOOP, "ELOOP", "Too many levels of symbolic links"); - addcode(dict, ENOMSG, "ENOMSG", "No message of desired type"); - addcode(dict, EIDRM, "EIDRM", "Identifier removed"); - addcode(dict, ECHRNG, "ECHRNG", "Channel number out of range"); - addcode(dict, EL2NSYNC, "EL2NSYNC", "Level 2 not synchronized"); - addcode(dict, EL3HLT, "EL3HLT", "Level 3 halted"); - addcode(dict, EL3RST, "EL3RST", "Level 3 reset"); - addcode(dict, ELNRNG, "ELNRNG", "Link number out of range"); - addcode(dict, EUNATCH, "EUNATCH", "Protocol driver not attached"); - addcode(dict, ENOCSI, "ENOCSI", "No CSI structure available"); - addcode(dict, EL2HLT, "EL2HLT", "Level 2 halted"); - addcode(dict, EBADE, "EBADE", "Invalid exchange"); - addcode(dict, EBADR, "EBADR", "Invalid request descriptor"); - addcode(dict, EXFULL, "EXFULL", "Exchange full"); - addcode(dict, ENOANO, "ENOANO", "No anode"); - addcode(dict, EBADRQC, "EBADRQC", "Invalid request code"); - addcode(dict, EBADSLT, "EBADSLT", "Invalid slot"); - addcode(dict, EBFONT, "EBFONT", "Bad font file format"); - addcode(dict, ENOSTR, "ENOSTR", "Device not a stream"); - addcode(dict, ENODATA, "ENODATA", "No data available"); - addcode(dict, ETIME, "ETIME", "Timer expired"); - addcode(dict, ENOSR, "ENOSR", "Out of streams resources"); - addcode(dict, ENONET, "ENONET", "Machine is not on the network"); - addcode(dict, ENOPKG, "ENOPKG", "Package not installed"); - addcode(dict, EREMOTE, "EREMOTE", "Object is remote"); - addcode(dict, ENOLINK, "ENOLINK", "Link has been severed"); - addcode(dict, EADV, "EADV", "Advertise error"); - addcode(dict, ESRMNT, "ESRMNT", "Srmount error"); - addcode(dict, ECOMM, "ECOMM", "Communication error on send"); - addcode(dict, EPROTO, "EPROTO", "Protocol error"); - addcode(dict, EMULTIHOP, "EMULTIHOP", "Multihop attempted"); - addcode(dict, EDOTDOT, "EDOTDOT", "RFS specific error"); - addcode(dict, EBADMSG, "EBADMSG", "Bad message"); - addcode(dict, EOVERFLOW, "EOVERFLOW", "Value too large for defined data type"); - addcode(dict, ENOTUNIQ, "ENOTUNIQ", "Name not unique on network"); - addcode(dict, EBADFD, "EBADFD", "File descriptor in bad state"); - addcode(dict, EREMCHG, "EREMCHG", "Remote address changed"); - addcode(dict, ELIBACC, "ELIBACC", "Can not access a needed shared library"); - addcode(dict, ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library"); - addcode(dict, ELIBSCN, "ELIBSCN", ".lib section in a.out corrupted"); - addcode(dict, ELIBMAX, "ELIBMAX", "Attempting to link in too many shared libraries"); - addcode(dict, ELIBEXEC, "ELIBEXEC", "Cannot exec a shared library directly"); - addcode(dict, EILSEQ, "EILSEQ", "Invalid or incomplete multibyte or wide character"); - addcode(dict, ERESTART, "ERESTART", "Interrupted system call should be restarted"); - addcode(dict, ESTRPIPE, "ESTRPIPE", "Streams pipe error"); - addcode(dict, EUSERS, "EUSERS", "Too many users"); - addcode(dict, ENOTSOCK, "ENOTSOCK", "Socket operation on non-socket"); - addcode(dict, EDESTADDRREQ, "EDESTADDRREQ", "Destination address required"); - addcode(dict, EMSGSIZE, "EMSGSIZE", "Message too long"); - addcode(dict, EPROTOTYPE, "EPROTOTYPE", "Protocol wrong type for socket"); - addcode(dict, ENOPROTOOPT, "ENOPROTOOPT", "Protocol not available"); - addcode(dict, EPROTONOSUPPORT, "EPROTONOSUPPORT", "Protocol not supported"); - addcode(dict, ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT", "Socket type not supported"); - addcode(dict, EOPNOTSUPP, "EOPNOTSUPP", "Operation not supported"); - addcode(dict, EPFNOSUPPORT, "EPFNOSUPPORT", "Protocol family not supported"); - addcode(dict, EAFNOSUPPORT, "EAFNOSUPPORT", "Address family not supported by protocol"); - addcode(dict, EADDRINUSE, "EADDRINUSE", "Address already in use"); - addcode(dict, EADDRNOTAVAIL, "EADDRNOTAVAIL", "Cannot assign requested address"); - addcode(dict, ENETDOWN, "ENETDOWN", "Network is down"); - addcode(dict, ENETUNREACH, "ENETUNREACH", "Network is unreachable"); - addcode(dict, ENETRESET, "ENETRESET", "Network dropped connection on reset"); - addcode(dict, ECONNABORTED, "ECONNABORTED", "Software caused connection abort"); - addcode(dict, ECONNRESET, "ECONNRESET", "Connection reset by peer"); - addcode(dict, ENOBUFS, "ENOBUFS", "No buffer space available"); - addcode(dict, EISCONN, "EISCONN", "Transport endpoint is already connected"); - addcode(dict, ENOTCONN, "ENOTCONN", "Transport endpoint is not connected"); - addcode(dict, ESHUTDOWN, "ESHUTDOWN", "Cannot send after transport endpoint shutdown"); - addcode(dict, ETOOMANYREFS, "ETOOMANYREFS", "Too many references: cannot splice"); - addcode(dict, ETIMEDOUT, "ETIMEDOUT", "Connection timed out"); - addcode(dict, ECONNREFUSED, "ECONNREFUSED", "Connection refused"); - addcode(dict, EHOSTDOWN, "EHOSTDOWN", "Host is down"); - addcode(dict, EHOSTUNREACH, "EHOSTUNREACH", "No route to host"); - addcode(dict, EALREADY, "EALREADY", "Operation already in progress"); - addcode(dict, EINPROGRESS, "EINPROGRESS", "Operation now in progress"); - addcode(dict, ESTALE, "ESTALE", "Stale NFS file handle"); - addcode(dict, EUCLEAN, "EUCLEAN", "Structure needs cleaning"); - addcode(dict, ENOTNAM, "ENOTNAM", "Not a XENIX named type file"); - addcode(dict, ENAVAIL, "ENAVAIL", "No XENIX semaphores available"); - addcode(dict, EISNAM, "EISNAM", "Is a named type file"); - addcode(dict, EREMOTEIO, "EREMOTEIO", "Remote I/O error"); - addcode(dict, EDQUOT, "EDQUOT", "Disk quota exceeded"); + public static void classDictInit(PyObject dict) { + for (Constant constant : ConstantSet.getConstantSet("Errno")) { + addCode(dict, constant.name(), constant.value(), constant.toString()); + } + // XXX: necessary? + addCode(dict, "ESOCKISBLOCKING", 20000, "Socket is in blocking mode"); + addCode(dict, "EGETADDRINFOFAILED", 20001, "getaddrinfo failed"); - // AMAK: starting a new series of jython specific errors - addcode(dict, ESOCKISBLOCKING, "ESOCKISBLOCKING", "Socket is in blocking mode"); - addcode(dict, EGETADDRINFOFAILED, "EGETADDRINFOFAILED", "getaddrinfo failed"); + // Hide from Python + dict.__setitem__("classDictInit", null); } - public static PyObject strerror(PyObject error) { - return strerror.__getitem__(error); + private static void addCode(PyObject dict, String name, int code, String message) { + PyObject nameObj = Py.newString(name); + PyObject codeObj = Py.newInteger(code); + dict.__setitem__(nameObj, codeObj); + errorcode.__setitem__(codeObj, nameObj); } - private static void addcode(PyObject dict, int errno, - String err, String msg) { - PyObject errno_o = Py.newInteger(errno); - PyObject err_o = Py.newString(err); - strerror.__setitem__(errno_o, Py.newString(msg)); - errorcode.__setitem__(errno_o, err_o); - dict.__setitem__(err_o, errno_o); + /** + * @deprecated Use org.python.core.constantine.Errno.valueOf(code).toString() (or + * os.strerror from Python) instead. + */ + @Deprecated + public static PyObject strerror(PyObject code) { + Py.warning(Py.DeprecationWarning, + "The errno.strerror function is deprecated, use os.strerror."); + return imp.load("os").__getattr__("strerror").__call__(code); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |