From: <zy...@us...> - 2009-04-16 03:11:58
|
Revision: 6229 http://jython.svn.sourceforge.net/jython/?rev=6229&view=rev Author: zyasoft Date: 2009-04-16 03:11:53 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Merged revisions 6208-6214,6218-6221,6224-6226 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6208 | amak | 2009-04-10 09:36:58 -0600 (Fri, 10 Apr 2009) | 2 lines Creating a poll object cache for MS Windows, because of a problem on that platform with creating too many Selectors. http://bugs.jython.org/issue1291 ........ r6209 | pjenvey | 2009-04-10 13:21:01 -0600 (Fri, 10 Apr 2009) | 5 lines cleanup class __module__ setup: o type/ClassType must default a __module__ (instead of Py.makeClass) for when types are constructed via type(name, bases, dict) o simplify the compiler's __module__ setup as it should just fail fast ........ r6210 | pjenvey | 2009-04-10 15:12:28 -0600 (Fri, 10 Apr 2009) | 3 lines ClassType shouldn't go through object's lookup machinery at all. not even __class__ or __call__ should show up in its lookup ........ r6211 | pjenvey | 2009-04-10 17:09:34 -0600 (Fri, 10 Apr 2009) | 1 line feeble attempt of debugging why these fail on hudson's all job ........ r6212 | pjenvey | 2009-04-10 18:24:56 -0600 (Fri, 10 Apr 2009) | 3 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_cmd_line.py@54387 ........ r6213 | pjenvey | 2009-04-10 18:25:21 -0600 (Fri, 10 Apr 2009) | 3 lines o reapply test_cmd_line workaround o fix error handling of bad -c/-m command lines ........ r6214 | pjenvey | 2009-04-10 19:11:10 -0600 (Fri, 10 Apr 2009) | 1 line fix test_sax when running under a path name with spaces ........ r6218 | amak | 2009-04-11 12:26:24 -0600 (Sat, 11 Apr 2009) | 1 line Adding a readme.txt so that the WEB-INF/lib directory doesn't end getting omitted up by the installer. ........ r6219 | pjenvey | 2009-04-11 14:49:13 -0600 (Sat, 11 Apr 2009) | 1 line cleanup ........ r6220 | pjenvey | 2009-04-11 15:27:36 -0600 (Sat, 11 Apr 2009) | 1 line encode unicode printed to file objects per the file's encoding ........ r6221 | pjenvey | 2009-04-11 18:21:44 -0600 (Sat, 11 Apr 2009) | 1 line restore the original encoding of SyntaxError text ........ r6224 | fwierzbicki | 2009-04-14 15:16:03 -0600 (Tue, 14 Apr 2009) | 6 lines Applied patch from http://bugs.jython.org/issue1271: Bean property accessors in derived class overide methods in base class. I altered his tests so that they are easily runnable by "ant javatest". Thanks to Geoffrey French for the fix. Also fixed a bad comment in IdentityTest.java. ........ r6225 | fwierzbicki | 2009-04-14 16:50:45 -0600 (Tue, 14 Apr 2009) | 3 lines Policy file that disallows writing to the filesystem to test GAE security patch. ........ r6226 | fwierzbicki | 2009-04-14 17:00:40 -0600 (Tue, 14 Apr 2009) | 2 lines Lame shell script to test jython with policy that disallows file writes. ........ Modified Paths: -------------- branches/newlist/Lib/os.py branches/newlist/Lib/select.py branches/newlist/Lib/test/test_class_jy.py branches/newlist/Lib/test/test_cmd_line.py branches/newlist/Lib/test/test_sax.py branches/newlist/NEWS branches/newlist/src/org/python/compiler/Module.java branches/newlist/src/org/python/core/ParserFacade.java branches/newlist/src/org/python/core/Py.java branches/newlist/src/org/python/core/PyClass.java branches/newlist/src/org/python/core/PyFrame.java branches/newlist/src/org/python/core/PyJavaType.java branches/newlist/src/org/python/core/PyType.java branches/newlist/src/org/python/core/StdoutWrapper.java branches/newlist/src/org/python/core/imp.java branches/newlist/src/org/python/util/jython.java branches/newlist/src/shell/jython branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java Added Paths: ----------- branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt branches/newlist/tests/policy/ branches/newlist/tests/policy/nowrite.policy branches/newlist/tests/policy/run.sh branches/newlist/tests/python/prop_test.py Removed Paths: ------------- branches/newlist/tests/policy/nowrite.policy branches/newlist/tests/policy/run.sh Property Changed: ---------------- branches/newlist/ Property changes on: branches/newlist ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6206 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6228 Copied: branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt (from rev 6226, trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt) =================================================================== --- branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt (rev 0) +++ branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1 @@ +The jython.jar file should be placed in this directory. Modified: branches/newlist/Lib/os.py =================================================================== --- branches/newlist/Lib/os.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/os.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -1080,7 +1080,6 @@ return _posix.isatty(fileno) if not isinstance(fileno, IOBase): - print fileno raise TypeError('a file descriptor is required') return fileno.isatty() Modified: branches/newlist/Lib/select.py =================================================================== --- branches/newlist/Lib/select.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/select.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -7,10 +7,11 @@ import java.nio.channels.Selector from java.nio.channels.SelectionKey import OP_ACCEPT, OP_CONNECT, OP_WRITE, OP_READ +import errno +import os +import Queue import socket -import errno - class error(Exception): pass ALL = None @@ -144,10 +145,18 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) - def close(self): + def _deregister_all(self): try: for k in self.selector.keys(): k.cancel() + # Keys are not actually removed from the selector until the next select operation. + self.selector.selectNow() + except java.lang.Exception, jlx: + raise _map_exception(jlx) + + def close(self): + try: + self._deregister_all() self.selector.close() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -165,10 +174,48 @@ return 0 return int(floatvalue * 1000) # Convert to milliseconds +# This cache for poll objects is required because of a bug in java on MS Windows +# http://bugs.jython.org/issue1291 + +class poll_object_cache: + + def __init__(self): + self.is_windows = os.get_os_type() == 'nt' + if self.is_windows: + self.poll_object_queue = Queue.Queue() + import atexit + atexit.register(self.finalize) + + def get_poll_object(self): + if not self.is_windows: + return poll() + try: + return self.poll_object_queue.get(False) + except Queue.Empty: + return poll() + + def release_poll_object(self, pobj): + if self.is_windows: + pobj._deregister_all() + self.poll_object_queue.put(pobj) + else: + pobj.close() + + def finalize(self): + if self.is_windows: + while True: + try: + p = self.poll_object_queue.get(False) + p.close() + except Queue.Empty: + return + +_poll_object_cache = poll_object_cache() + def native_select(read_fd_list, write_fd_list, outofband_fd_list, timeout=None): timeout = _calcselecttimeoutvalue(timeout) # First create a poll object to do the actual watching. - pobj = poll() + pobj = _poll_object_cache.get_poll_object() try: registered_for_read = {} # Check the read list @@ -192,10 +239,7 @@ write_ready_list.append(fd) return read_ready_list, write_ready_list, oob_ready_list finally: - # Need to close the poll object no matter what happened - # If it is left open, it may still have references to sockets - # That were registered before any exceptions occurred - pobj.close() + _poll_object_cache.release_poll_object(pobj) select = native_select Modified: branches/newlist/Lib/test/test_class_jy.py =================================================================== --- branches/newlist/Lib/test/test_class_jy.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_class_jy.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -17,17 +17,24 @@ self.assertEqual(str.__module__, '__builtin__') class Foo: pass - self.assertEqual(Foo.__module__, __name__) - self.assertEqual(str(Foo), '%s.Foo' % __name__) - self.assert_(repr(Foo).startswith('<class %s.Foo at' % __name__)) - foo = Foo() - self.assert_(str(foo).startswith('<%s.Foo instance at' % __name__)) + Fu = types.ClassType('Fu', (), {}) + for cls in Foo, Fu: + self.assert_('__module__' in cls.__dict__) + self.assertEqual(cls.__module__, __name__) + self.assertEqual(str(cls), '%s.%s' % (__name__, cls.__name__)) + self.assert_(repr(cls).startswith('<class %s.%s at' % + (__name__, cls.__name__))) + obj = cls() + self.assert_(str(obj).startswith('<%s.%s instance at' % + (__name__, cls.__name__))) class Bar(object): pass class Baz(Object): pass - for cls in Bar, Baz: + Bang = type('Bang', (), {}) + for cls in Bar, Baz, Bang: + self.assert_('__module__' in cls.__dict__) self.assertEqual(cls.__module__, __name__) self.assertEqual(str(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) self.assertEqual(repr(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) Modified: branches/newlist/Lib/test/test_cmd_line.py =================================================================== --- branches/newlist/Lib/test/test_cmd_line.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_cmd_line.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,4 +1,3 @@ -# from CPython 2.4, changing Python to Jython in test_version import test.test_support, unittest import sys @@ -7,14 +6,20 @@ class CmdLineTest(unittest.TestCase): def start_python(self, cmd_line): - outfp, infp = popen2.popen4('%s %s' % (sys.executable, cmd_line)) + outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line)) infp.close() data = outfp.read() outfp.close() + # try to cleanup the child so we don't appear to leak when running + # with regrtest -R. This should be a no-op on Windows. + popen2._cleanup() return data - def exit_code(self, cmd_line): - return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE) + def exit_code(self, *args): + cmd_line = [sys.executable] + cmd_line.extend(args) + return subprocess.call(cmd_line, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) def test_directories(self): self.assertNotEqual(self.exit_code('.'), 0) @@ -22,7 +27,7 @@ def verify_valid_flag(self, cmd_line): data = self.start_python(cmd_line) - self.assertTrue(data == '' or data.endswith('\n'), repr(data)) + self.assertTrue(data == '' or data.endswith('\n')) self.assertTrue('Traceback' not in data) def test_environment(self): @@ -45,11 +50,45 @@ self.assertTrue('usage' in self.start_python('-h')) def test_version(self): - version = 'Jython %d.%d' % sys.version_info[:2] + prefix = 'J' if test.test_support.is_jython else 'P' + version = prefix + 'ython %d.%d' % sys.version_info[:2] self.assertTrue(self.start_python('-V').startswith(version)) + def test_run_module(self): + # Test expected operation of the '-m' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-m'), 0) + # Check we get an error for a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'fnord43520xyz'), + 0) + # Check the runpy module also gives an error for + # a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'runpy', 'fnord43520xyz'), + 0) + # All good if module is located and run successfully + self.assertEqual( + self.exit_code('-m', 'timeit', '-n', '1'), + 0) + + def test_run_code(self): + # Test expected operation of the '-c' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-c'), 0) + # Check we get an error for an uncaught exception + self.assertNotEqual( + self.exit_code('-c', 'raise Exception'), + 0) + # All good if execution is successful + self.assertEqual( + self.exit_code('-c', 'pass'), + 0) + + def test_main(): test.test_support.run_unittest(CmdLineTest) + test.test_support.reap_children() if __name__ == "__main__": test_main() Modified: branches/newlist/Lib/test/test_sax.py =================================================================== --- branches/newlist/Lib/test/test_sax.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_sax.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -2,6 +2,7 @@ # regression test for SAX 2.0 # $Id: test_sax.py,v 1.13 2004/03/20 07:46:04 fdrake Exp $ +import urllib from xml.sax import handler, make_parser, ContentHandler, \ SAXException, SAXReaderNotAvailable, SAXParseException try: @@ -13,7 +14,7 @@ XMLFilterBase, Location from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from cStringIO import StringIO -from test.test_support import verbose, TestFailed, findfile +from test.test_support import is_jython, verbose, TestFailed, findfile # ===== Utilities @@ -472,14 +473,16 @@ parser.setContentHandler(xmlgen) testfile = findfile("test.xml") parser.parse(testfile) - #In Jython, the system id is a URL with forward slashes, and under Windows - #findfile returns a path with backslashes, so replace the backslashes with - #forward - import os - if os.name == 'java': + if is_jython: + # In Jython, the system id is a URL with forward slashes, and + # under Windows findfile returns a path with backslashes, so + # replace the backslashes with forward testfile = testfile.replace('\\', '/') - return xmlgen.location.getSystemId().endswith(testfile) and \ + # XXX: may not match getSystemId when the filename contains funky + # characters (like ':') + expected = urllib.quote(testfile) + return xmlgen.location.getSystemId().endswith(expected) and \ xmlgen.location.getPublicId() is None Modified: branches/newlist/NEWS =================================================================== --- branches/newlist/NEWS 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/NEWS 2009-04-16 03:11:53 UTC (rev 6229) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1271 ] Bean property accessors in derived class overide methods in base class - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException Modified: branches/newlist/src/org/python/compiler/Module.java =================================================================== --- branches/newlist/src/org/python/compiler/Module.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/compiler/Module.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -438,25 +438,14 @@ CodeCompiler compiler = new CodeCompiler(this, printResults); if (classBody) { - Label label_got_name = new Label(); - int module_tmp = c.getLocal("org/python/core/PyObject"); - + // Set the class's __module__ to __name__. fails when there's no __name__ c.aload(1); c.ldc("__module__"); - c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); - c.dup(); - c.ifnonnull(label_got_name); - c.pop(); c.aload(1); c.ldc("__name__"); - c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + c.invokevirtual("org/python/core/PyFrame", "getname", "(" + $str + ")" + $pyObj); - c.label(label_got_name); - c.astore(module_tmp); - c.aload(1); - c.ldc("__module__"); - c.aload(module_tmp); c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); } Modified: branches/newlist/src/org/python/core/ParserFacade.java =================================================================== --- branches/newlist/src/org/python/core/ParserFacade.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/ParserFacade.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -44,7 +44,7 @@ private ParserFacade() {} - private static String getLine(BufferedReader reader, int line) { + private static String getLine(ExpectedEncodingBufferedReader reader, int line) { if (reader == null) { return ""; } @@ -53,7 +53,14 @@ for (int i = 0; i < line; i++) { text = reader.readLine(); } - return text == null ? text : text + "\n"; + if (text == null) { + return text; + } + if (reader.encoding != null) { + // restore the original encoding + text = new PyUnicode(text).encode(reader.encoding); + } + return text + "\n"; } catch (IOException ioe) { } return text; @@ -80,7 +87,7 @@ line = node.getLine(); col = node.getCharPositionInLine(); } - String text=getLine(reader, line); + String text= getLine(reader, line); String msg = e.getMessage(); if (e.getType() == Py.IndentationError) { return new PyIndentationError(msg, line, col, text, filename); Modified: branches/newlist/src/org/python/core/Py.java =================================================================== --- branches/newlist/src/org/python/core/Py.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/Py.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -1566,14 +1566,6 @@ * @return a new Python Class PyObject */ public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { - PyFrame frame = getFrame(); - if (dict.__finditem__("__module__") == null) { - PyObject module = frame.getglobal("__name__"); - if (module != null) { - dict.__setitem__("__module__", module); - } - } - PyObject metaclass = dict.__finditem__("__metaclass__"); if (metaclass == null) { @@ -1584,7 +1576,7 @@ metaclass = base.getType(); } } else { - PyObject globals = frame.f_globals; + PyObject globals = getFrame().f_globals; if (globals != null) { metaclass = globals.__finditem__("__metaclass__"); } Modified: branches/newlist/src/org/python/core/PyClass.java =================================================================== --- branches/newlist/src/org/python/core/PyClass.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyClass.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,10 +1,7 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; -import org.python.expose.ExposedSet; import org.python.expose.ExposedType; /** @@ -16,16 +13,12 @@ public static final PyType TYPE = PyType.fromClass(PyClass.class); /** Holds the namespace for this class */ - @ExposedGet public PyObject __dict__; /** The base classes of this class */ - @ExposedGet public PyTuple __bases__; /** The name of this class */ - @ExposedGet - @ExposedSet public String __name__; // Store these methods for performance optimization. These are only used by PyInstance @@ -55,10 +48,8 @@ if (!(dict instanceof PyStringMap || dict instanceof PyDictionary)) { throw Py.TypeError("PyClass_New: dict must be a dictionary"); } - if (dict.__finditem__("__doc__") == null) { - dict.__setitem__("__doc__", Py.None); - } - findModule(dict); + PyType.ensureDoc(dict); + PyType.ensureModule(dict); if (!(bases instanceof PyTuple)) { throw Py.TypeError("PyClass_New: bases must be a tuple"); @@ -94,19 +85,6 @@ __contains__ = lookup("__contains__"); } - private static void findModule(PyObject dict) { - PyObject module = dict.__finditem__("__module__"); - if (module == null || module == Py.None) { - PyFrame f = Py.getFrame(); - if (f != null) { - PyObject nm = f.f_globals.__finditem__("__name__"); - if (nm != null) { - dict.__setitem__("__module__", nm); - } - } - } - } - PyObject lookup(String name) { PyObject result = __dict__.__finditem__(name); if (result == null && __bases__ != null) { @@ -127,14 +105,70 @@ @Override public PyObject __findattr_ex__(String name) { + if (name == "__dict__") { + return __dict__; + } + if (name == "__bases__") { + return __bases__; + } + if (name == "__name__") { + return Py.newString(__name__); + } + PyObject result = lookup(name); if (result == null) { - return super.__findattr_ex__(name); + return result; } return result.__get__(null, this); } @Override + public void __setattr__(String name, PyObject value) { + if (name == "__dict__") { + setDict(value); + return; + } else if (name == "__bases__") { + setBases(value); + return; + } else if (name == "__name__") { + setName(value); + return; + } else if (name == "__getattr__") { + __getattr__ = value; + return; + } else if (name == "__setattr__") { + __setattr__ = value; + return; + } else if (name == "__delattr__") { + __delattr__ = value; + return; + } else if (name == "__tojava__") { + __tojava__ = value; + return; + } else if (name == "__del__") { + __del__ = value; + return; + } else if (name == "__contains__") { + __contains__ = value; + return; + } + + if (value == null) { + try { + __dict__.__delitem__(name); + } catch (PyException pye) { + noAttributeError(name); + } + } + __dict__.__setitem__(name, value); + } + + @Override + public void __delattr__(String name) { + __setattr__(name, null); + } + + @Override public void __rawdir__(PyDictionary accum) { mergeClassDict(accum, this); } @@ -150,11 +184,6 @@ @Override public PyObject __call__(PyObject[] args, String[] keywords) { - return classobj___call__(args, keywords); - } - - @ExposedMethod - final PyObject classobj___call__(PyObject[] args, String[] keywords) { PyInstance inst; if (__del__ == null) { inst = new PyInstance(this); @@ -166,6 +195,11 @@ return inst; } + @Override + public boolean isCallable() { + return true; + } + /* PyClass's are compared based on __name__ */ @Override public int __cmp__(PyObject other) { @@ -219,17 +253,20 @@ return false; } - @ExposedSet(name = "__dict__") public void setDict(PyObject value) { - if (!(value instanceof PyStringMap || value instanceof PyDictionary)) { + if (value == null || !(value instanceof PyStringMap || value instanceof PyDictionary)) { throw Py.TypeError("__dict__ must be a dictionary object"); } __dict__ = value; } - @ExposedSet(name = "__bases__") - public void setBases(PyTuple value) { - for (PyObject base : value.getArray()) { + public void setBases(PyObject value) { + if (value == null || !(value instanceof PyTuple)) { + throw Py.TypeError("__bases__ must be a tuple object"); + } + + PyTuple bases = (PyTuple)value; + for (PyObject base : bases.getArray()) { if (!(base instanceof PyClass)) { throw Py.TypeError("__bases__ items must be classes"); } @@ -237,6 +274,17 @@ throw Py.TypeError("a __bases__ item causes an inheritance cycle"); } } - __bases__ = value; + __bases__ = bases; } + + public void setName(PyObject value) { + if (value == null || !Py.isInstance(value, PyString.TYPE)) { + throw Py.TypeError("__name__ must be a string object"); + } + String name = value.toString(); + if (name.contains("\u0000")) { + throw Py.TypeError("__name__ must not contain null bytes"); + } + __name__ = name; + } } Modified: branches/newlist/src/org/python/core/PyFrame.java =================================================================== --- branches/newlist/src/org/python/core/PyFrame.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyFrame.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -276,20 +276,6 @@ throw Py.NameError(String.format(NAME_ERROR_MSG, index)); } - public PyObject getname_or_null(String index) { - PyObject ret; - if (f_locals == null || f_locals == f_globals) { - ret = doGetglobal(index); - } else { - ret = f_locals.__finditem__(index); - if (ret != null) { - return ret; - } - ret = doGetglobal(index); - } - return ret; - } - public PyObject getglobal(String index) { PyObject ret = doGetglobal(index); if (ret != null) { Modified: branches/newlist/src/org/python/core/PyJavaType.java =================================================================== --- branches/newlist/src/org/python/core/PyJavaType.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyJavaType.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -407,7 +407,8 @@ // If one of our superclasses has something defined for this name, check if its a bean // property, and if so, try to fill in any gaps in our property from there - PyObject superForName = lookup(prop.__name__); + PyObject fromType[] = new PyObject[] { null }; + PyObject superForName = lookup_where(prop.__name__, fromType); if (superForName instanceof PyBeanProperty) { PyBeanProperty superProp = ((PyBeanProperty)superForName); // If it has a set method and we don't, take it regardless. If the types don't line @@ -426,6 +427,12 @@ // If the parent bean is hiding a static field, we need it as well. prop.field = superProp.field; } + } else if (superForName != null && fromType[0] != this && !(superForName instanceof PyBeanEvent)) { + // There is already an entry for this name + // It came from a type which is not @this; it came from a superclass + // It is not a bean event + // Do not override methods defined in superclass + continue; } // If the return types on the set and get methods for a property don't agree, the get // method takes precedence Modified: branches/newlist/src/org/python/core/PyType.java =================================================================== --- branches/newlist/src/org/python/core/PyType.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyType.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -374,10 +374,8 @@ dict.__setitem__("__new__", new PyStaticMethod(new_)); } - // NOTE: __module__ is already guaranteed by Py.makeClass - if (dict.__finditem__("__doc__") == null) { - dict.__setitem__("__doc__", Py.None); - } + ensureDoc(dict); + ensureModule(dict); // Calculate method resolution order mro_internal(); @@ -396,6 +394,37 @@ } } + /** + * Ensure dict contains a __doc__. + * + * @param dict a PyObject mapping + */ + public static void ensureDoc(PyObject dict) { + if (dict.__finditem__("__doc__") == null) { + dict.__setitem__("__doc__", Py.None); + } + } + + /** + * Ensure dict contains a __module__, retrieving it from the current frame if it + * doesn't exist. + * + * @param dict a PyObject mapping + */ + public static void ensureModule(PyObject dict) { + if (dict.__finditem__("__module__") != null) { + return; + } + PyFrame frame = Py.getFrame(); + if (frame == null) { + return; + } + PyObject name = frame.f_globals.__finditem__("__name__"); + if (name != null) { + dict.__setitem__("__module__", name); + } + } + private static PyObject invoke_new_(PyObject new_, PyType type, boolean init, PyObject[] args, String[] keywords) { PyObject newobj; Modified: branches/newlist/src/org/python/core/StdoutWrapper.java =================================================================== --- branches/newlist/src/org/python/core/StdoutWrapper.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/StdoutWrapper.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -105,8 +105,14 @@ file.write(" "); file.softspace = false; } - PyString string = o.__str__(); - String s = string.toString(); + + String s; + if (o instanceof PyUnicode && file.encoding != null) { + s = ((PyUnicode)o).encode(file.encoding, "strict"); + } else { + s = o.__str__().toString(); + } + int len = s.length(); file.write(s); if (o instanceof PyString) { Modified: branches/newlist/src/org/python/core/imp.java =================================================================== --- branches/newlist/src/org/python/core/imp.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/imp.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -20,7 +20,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 19; + public static final int APIVersion = 20; public static final int NO_MTIME = -1; Modified: branches/newlist/src/org/python/util/jython.java =================================================================== --- branches/newlist/src/org/python/util/jython.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/util/jython.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -259,6 +259,7 @@ interp.exec(opts.command); } catch (Throwable t) { Py.printException(t); + System.exit(1); } } @@ -273,7 +274,7 @@ } catch (Throwable t) { Py.printException(t); interp.cleanup(); - System.exit(0); + System.exit(-1); } } } @@ -407,8 +408,20 @@ Options.importSite = false; } else if (arg.equals("-c")) { - command = args[++index]; - if (!fixInteractive) interactive = false; + if (arg.length() > 2) { + command = arg.substring(2); + } + else if ((index + 1) < args.length) { + command = args[++index]; + } else { + System.err.println("Argument expected for the -c option"); + System.err.print(jython.usageHeader); + System.err.println("Try `jython -h' for more information."); + return false; + } + if (!fixInteractive) { + interactive = false; + } index++; break; } Modified: branches/newlist/src/shell/jython =================================================================== --- branches/newlist/src/shell/jython 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/shell/jython 2009-04-16 03:11:53 UTC (rev 6229) @@ -117,9 +117,13 @@ fi ;; # Match switches that take an argument - -c|-C|-jar|-Q|-W) - python_args=("${python_args[@]}" "$1" "$2") - shift + -c|-C|-m|-jar|-Q|-W) + if [ $# = 1 ]; then + python_args=("${python_args[@]}" "$1") + else + python_args=("${python_args[@]}" "$1" "$2") + shift + fi; ;; # Match -Dprop=val type args -D*) Modified: branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java =================================================================== --- branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -18,7 +18,6 @@ } public void testReadonly() { - //This used to cause an NPE see http://bugs.jython.org/issue1295 interp.execfile("tests/python/identity_test.py"); } } Modified: branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java =================================================================== --- branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -20,25 +20,8 @@ interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); } - //This test is for http://bugs.jython.org/issue1271 - public void testBaseProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("a = PropShadow.Derived()"); - interp.exec("assert a.foo() == 1, 'a'"); - interp.exec("assert a.bar() == 2, 'b'"); - */ + public void testShadowing() { + interp.execfile("tests/python/prop_test.py"); } - //This test is for http://bugs.jython.org/issue1271 - public void testDerivedProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("b = PropShadow.Derived()"); - interp.exec("assert b.getBaz() == 4, 'c'"); - interp.exec("assert b.getFoo() == 3, 'd'"); - interp.exec("assert b.foo() == 1, 'e'"); - interp.exec("assert b.foo() == 1, 'f'"); - */ - } } Deleted: branches/newlist/tests/policy/nowrite.policy =================================================================== --- trunk/jython/tests/policy/nowrite.policy 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/tests/policy/nowrite.policy 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,3 +0,0 @@ -grant { - permission java.util.PropertyPermission "*", "read"; -}; Copied: branches/newlist/tests/policy/nowrite.policy (from rev 6226, trunk/jython/tests/policy/nowrite.policy) =================================================================== --- branches/newlist/tests/policy/nowrite.policy (rev 0) +++ branches/newlist/tests/policy/nowrite.policy 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1,3 @@ +grant { + permission java.util.PropertyPermission "*", "read"; +}; Deleted: branches/newlist/tests/policy/run.sh =================================================================== --- trunk/jython/tests/policy/run.sh 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/tests/policy/run.sh 2009-04-16 03:11:53 UTC (rev 6229) @@ -1 +0,0 @@ -java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ Copied: branches/newlist/tests/policy/run.sh (from rev 6226, trunk/jython/tests/policy/run.sh) =================================================================== --- branches/newlist/tests/policy/run.sh (rev 0) +++ branches/newlist/tests/policy/run.sh 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1 @@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ Copied: branches/newlist/tests/python/prop_test.py (from rev 6226, trunk/jython/tests/python/prop_test.py) =================================================================== --- branches/newlist/tests/python/prop_test.py (rev 0) +++ branches/newlist/tests/python/prop_test.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1,16 @@ +from org.python.tests.identity import IdentityObject + +#This test is for http://bugs.jython.org/issue1271 +from org.python.tests.props import PropShadow + +a = PropShadow.Derived() +assert a.foo() == 1, 'a' +assert a.bar() == 2, 'b' + +from org.python.tests.props import PropShadow +b = PropShadow.Derived() +assert b.getBaz() == 4, 'c' +assert b.baz == 4, 'e' +assert b.getFoo() == 3, 'd' +assert b.foo() == 1, 'f' + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |