From: <fwi...@us...> - 2008-12-16 19:24:45
|
Revision: 5770 http://jython.svn.sourceforge.net/jython/?rev=5770&view=rev Author: fwierzbicki Date: 2008-12-16 19:24:41 +0000 (Tue, 16 Dec 2008) Log Message: ----------- Fix for http://bugs.jython.org/issue1205, thanks to pb for the report and Philip Jenvey for the AST analysis. List Comprehensions where only including one "list_if" in a series of "list_if". Generator Expressions had the same issue. Added a test to test_genexprs_jy.py and created test_listcomp_jy.py to test for the issue. Modified Paths: -------------- trunk/jython/Lib/test/test_genexps_jy.py trunk/jython/grammar/Python.g Added Paths: ----------- trunk/jython/Lib/test/test_listcomp_jy.py Modified: trunk/jython/Lib/test/test_genexps_jy.py =================================================================== --- trunk/jython/Lib/test/test_genexps_jy.py 2008-12-16 16:58:32 UTC (rev 5769) +++ trunk/jython/Lib/test/test_genexps_jy.py 2008-12-16 19:24:41 UTC (rev 5770) @@ -15,6 +15,13 @@ # this far we've already passed self.assert_(sorted(locals_test) == ['test_support', 'unittest']) + #http://bugs.jython.org/issue1205 applied to genexps. + def test_long_genexp(self): + r = 2 + g = ((x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) + if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 + if x1**3+x2**3 == y1**3+y2**3 ) + self.assertEquals(g.next(), (1, (0, 1), (0, 1))) def test_main(): test_support.run_unittest(GeneratorExpressionsTestCase) Added: trunk/jython/Lib/test/test_listcomp_jy.py =================================================================== --- trunk/jython/Lib/test/test_listcomp_jy.py (rev 0) +++ trunk/jython/Lib/test/test_listcomp_jy.py 2008-12-16 19:24:41 UTC (rev 5770) @@ -0,0 +1,19 @@ +import unittest +from test import test_support + +class ListCompTestCase(unittest.TestCase): + + #http://bugs.jython.org/issue1205 + def test_long_listcomp(self): + r = 2 + lc = [(x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) + if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 + if x1**3+x2**3 == y1**3+y2**3 ] + self.assertEquals(len(lc), 1) + self.assertEquals(lc, [(1, (0, 1), (0, 1))]) + +def test_main(): + test_support.run_unittest(ListCompTestCase) + +if __name__ == '__main__': + test_main() Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-12-16 16:58:32 UTC (rev 5769) +++ trunk/jython/grammar/Python.g 2008-12-16 19:24:41 UTC (rev 5770) @@ -1516,60 +1516,55 @@ ; //list_iter: list_for | list_if -list_iter [List gens] returns [expr etype] +list_iter [List gens, List ifs] : list_for[gens] - | list_if[gens] { - $etype = $list_if.etype; - } + | list_if[gens, ifs] ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for [List gens] - : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? +@init { + List ifs = new ArrayList(); +} + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens, ifs])? { - List<expr> e = new ArrayList<expr>(); - if ($list_iter.etype != null) { - e.add($list_iter.etype); - } - gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($testlist.tree), e)); + Collections.reverse(ifs); + gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($testlist.tree), ifs)); } ; //list_if: 'if' test [list_iter] -list_if[List gens] returns [expr etype] - : IF test[expr_contextType.Load] (list_iter[gens])? +list_if[List gens, List ifs] + : IF test[expr_contextType.Load] (list_iter[gens, ifs])? { - $etype = actions.castExpr($test.tree); + ifs.add(actions.castExpr($test.tree)); } ; //gen_iter: gen_for | gen_if -gen_iter [List gens] returns [expr etype] +gen_iter [List gens, List ifs] : gen_for[gens] - | gen_if[gens] - { - $etype = $gen_if.etype; - } + | gen_if[gens, ifs] ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] gen_for [List gens] - : FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? +@init { + List ifs = new ArrayList(); +} + : FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens, ifs]? { - List<expr> e = new ArrayList<expr>(); - if ($gen_iter.etype != null) { - e.add($gen_iter.etype); - } - gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($or_test.tree), e)); + Collections.reverse(ifs); + gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($or_test.tree), ifs)); } ; //gen_if: 'if' old_test [gen_iter] -gen_if[List gens] returns [expr etype] - : IF test[expr_contextType.Load] gen_iter[gens]? - { - $etype = actions.castExpr($test.tree); - } +gen_if[List gens, List ifs] + : IF test[expr_contextType.Load] gen_iter[gens, ifs]? + { + ifs.add(actions.castExpr($test.tree)); + } ; //yield_expr: 'yield' [testlist] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-17 07:09:29
|
Revision: 5773 http://jython.svn.sourceforge.net/jython/?rev=5773&view=rev Author: pjenvey Date: 2008-12-17 07:09:26 +0000 (Wed, 17 Dec 2008) Log Message: ----------- forgot to proxy EnumerationIter Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/PyJavaType.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-17 07:07:56 UTC (rev 5772) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-17 07:09:26 UTC (rev 5773) @@ -6,7 +6,7 @@ from test import test_support from java.awt import (Dimension, Component, Rectangle, Button, Color, HeadlessException) -from java.util import ArrayList, Vector, HashMap, Hashtable +from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter from java.lang import Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte @@ -450,7 +450,11 @@ del m["a"] self.assertEquals(0, len(m)) + def test_enumerable_delegation(self): + tokenizer = StringTokenizer('foo bar') + self.assertEquals(list(iter(tokenizer)), ['foo', 'bar']) + def test_main(): test_support.run_unittest(AbstractOnSyspathTest, InstantiationTest, Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-12-17 07:07:56 UTC (rev 5772) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-12-17 07:09:26 UTC (rev 5773) @@ -409,7 +409,7 @@ return false; } - private class EnumerationIter extends PyIterator { + private static class EnumerationIter extends PyIterator { private Enumeration<Object> proxy; @@ -495,6 +495,13 @@ }; collectionProxies.put(Iterator.class, new PyBuiltinMethod[] {iteratorProxy}); + PyBuiltinMethodNarrow enumerationProxy = new PyBuiltinMethodNarrow("__iter__", 0, 0) { + public PyObject __call__() { + return new EnumerationIter(((Enumeration)self.getJavaProxy())); + } + }; + collectionProxies.put(Enumeration.class, new PyBuiltinMethod[] {enumerationProxy}); + // Map doesn't extend Collection, so it needs its own version of len, iter and contains PyBuiltinMethodNarrow mapLenProxy = new MapMethod("__len__", 0, 0) { @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-17 19:42:44
|
Revision: 5774 http://jython.svn.sourceforge.net/jython/?rev=5774&view=rev Author: fwierzbicki Date: 2008-12-17 19:42:40 +0000 (Wed, 17 Dec 2008) Log Message: ----------- Fix for http://bugs.jython.org/issue1063. On stack overflows we now properly throw a Python RuntimeError instead of a Java StackOverflowError. This also allows us to use an the CPython test_exceptions.py unmodified. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java Removed Paths: ------------- trunk/jython/Lib/test/test_exceptions.py Deleted: trunk/jython/Lib/test/test_exceptions.py =================================================================== --- trunk/jython/Lib/test/test_exceptions.py 2008-12-17 07:09:26 UTC (rev 5773) +++ trunk/jython/Lib/test/test_exceptions.py 2008-12-17 19:42:40 UTC (rev 5774) @@ -1,349 +0,0 @@ -# Python test set -- part 5, built-in exceptions - -import os -import sys -import unittest -import warnings -import pickle, cPickle - -from test.test_support import TESTFN, unlink, run_unittest - -# XXX This is not really enough, each *operation* should be tested! - -class ExceptionTests(unittest.TestCase): - - def testReload(self): - # Reloading the built-in exceptions module failed prior to Py2.2, while it - # should act the same as reloading built-in sys. - try: - import exceptions - reload(exceptions) - except ImportError, e: - self.fail("reloading exceptions: %s" % e) - - def raise_catch(self, exc, excname): - try: - raise exc, "spam" - except exc, err: - buf1 = str(err) - try: - raise exc("spam") - except exc, err: - buf2 = str(err) - self.assertEquals(buf1, buf2) - self.assertEquals(exc.__name__, excname) - - def testRaising(self): - self.raise_catch(AttributeError, "AttributeError") - self.assertRaises(AttributeError, getattr, sys, "undefined_attribute") - - self.raise_catch(EOFError, "EOFError") - fp = open(TESTFN, 'w') - fp.close() - fp = open(TESTFN, 'r') - savestdin = sys.stdin - try: - try: - sys.stdin = fp - x = raw_input() - except EOFError: - pass - finally: - sys.stdin = savestdin - fp.close() - unlink(TESTFN) - - self.raise_catch(IOError, "IOError") - self.assertRaises(IOError, open, 'this file does not exist', 'r') - - self.raise_catch(ImportError, "ImportError") - self.assertRaises(ImportError, __import__, "undefined_module") - - self.raise_catch(IndexError, "IndexError") - x = [] - self.assertRaises(IndexError, x.__getitem__, 10) - - self.raise_catch(KeyError, "KeyError") - x = {} - self.assertRaises(KeyError, x.__getitem__, 'key') - - self.raise_catch(KeyboardInterrupt, "KeyboardInterrupt") - - self.raise_catch(MemoryError, "MemoryError") - - self.raise_catch(NameError, "NameError") - try: x = undefined_variable - except NameError: pass - - self.raise_catch(OverflowError, "OverflowError") - x = 1 - for dummy in range(128): - x += x # this simply shouldn't blow up - - self.raise_catch(RuntimeError, "RuntimeError") - - self.raise_catch(SyntaxError, "SyntaxError") - try: exec '/\n' - except SyntaxError: pass - - self.raise_catch(IndentationError, "IndentationError") - - self.raise_catch(TabError, "TabError") - # can only be tested under -tt, and is the only test for -tt - #try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '<string>', 'exec') - #except TabError: pass - #else: self.fail("TabError not raised") - - self.raise_catch(SystemError, "SystemError") - - self.raise_catch(SystemExit, "SystemExit") - self.assertRaises(SystemExit, sys.exit, 0) - - self.raise_catch(TypeError, "TypeError") - try: [] + () - except TypeError: pass - - self.raise_catch(ValueError, "ValueError") - self.assertRaises(ValueError, chr, 10000) - - self.raise_catch(ZeroDivisionError, "ZeroDivisionError") - try: x = 1/0 - except ZeroDivisionError: pass - - self.raise_catch(Exception, "Exception") - try: x = 1/0 - except Exception, e: pass - - def testSyntaxErrorMessage(self): - # make sure the right exception message is raised for each of - # these code fragments - - def ckmsg(src, msg): - try: - compile(src, '<fragment>', 'exec') - except SyntaxError, e: - if e.msg != msg: - self.fail("expected %s, got %s" % (msg, e.msg)) - else: - self.fail("failed to get expected SyntaxError") - - s = '''while 1: - try: - pass - finally: - continue''' - - if not sys.platform.startswith('java'): - ckmsg(s, "'continue' not supported inside 'finally' clause") - - s = '''if 1: - try: - continue - except: - pass''' - - ckmsg(s, "'continue' not properly in loop") - ckmsg("continue\n", "'continue' not properly in loop") - - def testSettingException(self): - # test that setting an exception at the C level works even if the - # exception object can't be constructed. - - class BadException: - def __init__(self_): - raise RuntimeError, "can't instantiate BadException" - - def test_capi1(): - import _testcapi - try: - _testcapi.raise_exception(BadException, 1) - except TypeError, err: - exc, err, tb = sys.exc_info() - co = tb.tb_frame.f_code - self.assertEquals(co.co_name, "test_capi1") - self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py')) - else: - self.fail("Expected exception") - - def test_capi2(): - import _testcapi - try: - _testcapi.raise_exception(BadException, 0) - except RuntimeError, err: - exc, err, tb = sys.exc_info() - co = tb.tb_frame.f_code - self.assertEquals(co.co_name, "__init__") - self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py')) - co2 = tb.tb_frame.f_back.f_code - self.assertEquals(co2.co_name, "test_capi2") - else: - self.fail("Expected exception") - - if not sys.platform.startswith('java'): - test_capi1() - test_capi2() - - def test_WindowsError(self): - try: - WindowsError - except NameError: - pass - else: - self.failUnlessEqual(str(WindowsError(1001)), - "1001") - self.failUnlessEqual(str(WindowsError(1001, "message")), - "[Error 1001] message") - self.failUnlessEqual(WindowsError(1001, "message").errno, 22) - self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001) - - def testAttributes(self): - # test that exception attributes are happy - - exceptionList = [ - (BaseException, (), {'message' : '', 'args' : ()}), - (BaseException, (1, ), {'message' : 1, 'args' : (1,)}), - (BaseException, ('foo',), - {'message' : 'foo', 'args' : ('foo',)}), - (BaseException, ('foo', 1), - {'message' : '', 'args' : ('foo', 1)}), - (SystemExit, ('foo',), - {'message' : 'foo', 'args' : ('foo',), 'code' : 'foo'}), - (IOError, ('foo',), - {'message' : 'foo', 'args' : ('foo',), 'filename' : None, - 'errno' : None, 'strerror' : None}), - (IOError, ('foo', 'bar'), - {'message' : '', 'args' : ('foo', 'bar'), 'filename' : None, - 'errno' : 'foo', 'strerror' : 'bar'}), - (IOError, ('foo', 'bar', 'baz'), - {'message' : '', 'args' : ('foo', 'bar'), 'filename' : 'baz', - 'errno' : 'foo', 'strerror' : 'bar'}), - (IOError, ('foo', 'bar', 'baz', 'quux'), - {'message' : '', 'args' : ('foo', 'bar', 'baz', 'quux')}), - (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : ('errnoStr', 'strErrorStr'), - 'strerror' : 'strErrorStr', 'errno' : 'errnoStr', - 'filename' : 'filenameStr'}), - (EnvironmentError, (1, 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : (1, 'strErrorStr'), 'errno' : 1, - 'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}), - (SyntaxError, ('msgStr',), - {'message' : 'msgStr', 'args' : ('msgStr',), 'text' : None, - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : None, 'lineno' : None, 'offset' : None}), - (SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', - 'textStr')), - {'message' : '', 'offset' : 'offsetStr', 'text' : 'textStr', - 'args' : ('msgStr', ('filenameStr', 'linenoStr', - 'offsetStr', 'textStr')), - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : 'filenameStr', 'lineno' : 'linenoStr'}), - (SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', - 'textStr', 'print_file_and_lineStr'), - {'message' : '', 'text' : None, - 'args' : ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', - 'textStr', 'print_file_and_lineStr'), - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : None, 'lineno' : None, 'offset' : None}), - (UnicodeError, (), {'message' : '', 'args' : (),}), - (UnicodeEncodeError, ('ascii', u'a', 0, 1, 'ordinal not in range'), - {'message' : '', 'args' : ('ascii', u'a', 0, 1, - 'ordinal not in range'), - 'encoding' : 'ascii', 'object' : u'a', - 'start' : 0, 'reason' : 'ordinal not in range'}), - (UnicodeDecodeError, ('ascii', '\xff', 0, 1, 'ordinal not in range'), - {'message' : '', 'args' : ('ascii', '\xff', 0, 1, - 'ordinal not in range'), - 'encoding' : 'ascii', 'object' : '\xff', - 'start' : 0, 'reason' : 'ordinal not in range'}), - (UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"), - {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'), - 'object' : u'\u3042', 'reason' : 'ouch', - 'start' : 0, 'end' : 1}), - ] - try: - exceptionList.append( - (WindowsError, (1, 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : (1, 'strErrorStr'), - 'strerror' : 'strErrorStr', 'winerror' : 1, - 'errno' : 22, 'filename' : 'filenameStr'}) - ) - except NameError: - pass - - for exc, args, expected in exceptionList: - try: - raise exc(*args) - except BaseException, e: - if type(e) is not exc: - raise - # Verify module name - self.assertEquals(type(e).__module__, 'exceptions') - # Verify no ref leaks in Exc_str() - s = str(e) - for checkArgName in expected: - self.assertEquals(repr(getattr(e, checkArgName)), - repr(expected[checkArgName]), - 'exception "%s", attribute "%s"' % - (repr(e), checkArgName)) - - # test for pickling support - for p in pickle, cPickle: - for protocol in range(p.HIGHEST_PROTOCOL + 1): - new = p.loads(p.dumps(e, protocol)) - for checkArgName in expected: - got = repr(getattr(new, checkArgName)) - want = repr(expected[checkArgName]) - self.assertEquals(got, want, - 'pickled "%r", attribute "%s' % - (e, checkArgName)) - - def testSlicing(self): - # Test that you can slice an exception directly instead of requiring - # going through the 'args' attribute. - args = (1, 2, 3) - exc = BaseException(*args) - self.failUnlessEqual(exc[:], args) - - def testKeywordArgs(self): - # test that builtin exception don't take keyword args, - # but user-defined subclasses can if they want - self.assertRaises(TypeError, BaseException, a=1) - - class DerivedException(BaseException): - def __init__(self, fancy_arg): - BaseException.__init__(self) - self.fancy_arg = fancy_arg - - x = DerivedException(fancy_arg=42) - self.assertEquals(x.fancy_arg, 42) - - def testInfiniteRecursion(self): - def f(): - return f() - self.assertRaises(RuntimeError, f) - - def g(): - try: - return g() - except ValueError: - return -1 - self.assertRaises(RuntimeError, g) - - def testUnicodeStrUsage(self): - # Make sure both instances and classes have a str and unicode - # representation. - self.failUnless(str(Exception)) - self.failUnless(unicode(Exception)) - self.failUnless(str(Exception('a'))) - self.failUnless(unicode(Exception(u'a'))) - - -def test_main(): - from test import test_support - if test_support.is_jython: - # XXX: http://bugs.jython.org/issue1063 - del ExceptionTests.testInfiniteRecursion - run_unittest(ExceptionTests) - -if __name__ == '__main__': - test_main() Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-17 07:09:26 UTC (rev 5773) +++ trunk/jython/src/org/python/core/Py.java 2008-12-17 19:42:40 UTC (rev 5774) @@ -444,6 +444,8 @@ return (PyException) t; } else if (t instanceof InvocationTargetException) { return JavaError(((InvocationTargetException) t).getTargetException()); + } else if (t instanceof StackOverflowError) { + return Py.RuntimeError("maximum recursion depth exceeded"); } else if (t instanceof OutOfMemoryError) { memory_error((OutOfMemoryError) t); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-19 06:00:50
|
Revision: 5779 http://jython.svn.sourceforge.net/jython/?rev=5779&view=rev Author: zyasoft Date: 2008-12-19 06:00:48 +0000 (Fri, 19 Dec 2008) Log Message: ----------- Enabled ClassDictInit modules to set their __name__ so that it matches the name part of name:class in org.python.modules.Setup (or equivalently registry setting python.modules.builtin). This fixes introspection issues where __import__(name).__name__ != name. Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/modules/_newmodule.java trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java trunk/jython/src/org/python/modules/random/RandomModule.java trunk/jython/src/org/python/modules/time/Time.java Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/Lib/test/test_builtin_jy.py 2008-12-19 06:00:48 UTC (rev 5779) @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +1# -*- coding: utf-8 -*- import sys import unittest import test.test_support @@ -157,6 +157,18 @@ exec code in ns self.assertEqual(foo, ns['a']) +class ModuleNameTest(unittest.TestCase): + """Tests that the module when imported has the same __name__""" + + def test_names(self): + for name in sys.builtin_module_names: + if name != '_jython' and name not in ('time', '_random', 'array', '_collections', '_ast'): + module = __import__(name) + self.assertEqual(name, module.__name__) + + + + def test_main(): test.test_support.run_unittest(BuiltinTest, LoopTest, @@ -167,7 +179,9 @@ ReprTest, CallableTest, ConversionTest, - ExecEvalTest) + ExecEvalTest, + ModuleNameTest, + ) if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-12-19 06:00:48 UTC (rev 5779) @@ -281,6 +281,11 @@ try { Method m = underlying_class.getMethod("classDictInit", PyObject.class); m.invoke(null, dict); + // allow the class to override its name after it is loaded + PyObject nameSpecified = dict.__finditem__("__name__"); + if (nameSpecified != null) { + name = nameSpecified.toString(); + } } catch (Exception exc) { throw Py.JavaError(exc); } Modified: trunk/jython/src/org/python/modules/_newmodule.java =================================================================== --- trunk/jython/src/org/python/modules/_newmodule.java 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/src/org/python/modules/_newmodule.java 2008-12-19 06:00:48 UTC (rev 5779) @@ -1,6 +1,7 @@ /* Copyright (c) 2001, 2003 Finn Bock, Samuele Pedroni */ package org.python.modules; +import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyClass; import org.python.core.PyObject; @@ -11,8 +12,13 @@ * The internal new module; just provides a hack for new.classobj. * */ -public class _newmodule { +public class _newmodule implements ClassDictInit { + public static void classDictInit(PyObject dict) + { + dict.__setitem__("__name__", Py.newString("_new")); + } + public static PyObject classobj(String name, PyTuple bases, PyObject dict) { // XXX: Hack to return new style classes (originally from // r4225). types.ClassType (PyClass) should be doing this Modified: trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/src/org/python/modules/_weakref/WeakrefModule.java 2008-12-19 06:00:48 UTC (rev 5779) @@ -20,6 +20,7 @@ public static void classDictInit(PyObject dict) { dict.__setitem__("__doc__", __doc__); + dict.__setitem__("__name__", Py.newString("_weakref")); dict.__setitem__("ref", ReferenceType.TYPE); dict.__setitem__("ReferenceType", ReferenceType.TYPE); dict.__setitem__("ProxyType", ProxyType.TYPE); Modified: trunk/jython/src/org/python/modules/random/RandomModule.java =================================================================== --- trunk/jython/src/org/python/modules/random/RandomModule.java 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/src/org/python/modules/random/RandomModule.java 2008-12-19 06:00:48 UTC (rev 5779) @@ -9,6 +9,8 @@ private RandomModule() {} public static void classDictInit(PyObject dict) { + dict.invoke("clear"); dict.__setitem__("Random", PyRandom.TYPE); + dict.__setitem__("__name__", Py.newString("_random")); } } Modified: trunk/jython/src/org/python/modules/time/Time.java =================================================================== --- trunk/jython/src/org/python/modules/time/Time.java 2008-12-18 20:12:14 UTC (rev 5778) +++ trunk/jython/src/org/python/modules/time/Time.java 2008-12-19 06:00:48 UTC (rev 5779) @@ -112,6 +112,7 @@ dict.__setitem__("time", new TimeFunctions("time", 0, 0)); dict.__setitem__("clock", new TimeFunctions("clock", 1, 0)); dict.__setitem__("struct_time", PyTimeTuple.TYPE); + dict.__setitem__("__name__", Py.newString("time")); // calculate the static variables tzname, timezone, altzone, daylight TimeZone tz = TimeZone.getDefault(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-22 02:18:15
|
Revision: 5785 http://jython.svn.sourceforge.net/jython/?rev=5785&view=rev Author: cgroves Date: 2008-12-22 02:18:12 +0000 (Mon, 22 Dec 2008) Log Message: ----------- Use PyJavaType(java.lang.Class) as the metatype for instances of PyJavaType wrapping a Java class. This exposes Class methods like getMethods and getFields through the instance. Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyException.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/modules/ArrayModule.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/CoreExposed.includes 2008-12-22 02:18:12 UTC (rev 5785) @@ -19,6 +19,7 @@ org/python/core/PyFunction.class org/python/core/PyGenerator.class org/python/core/PyInteger.class +org/python/core/PyJavaType.class org/python/core/PyList.class org/python/core/PyLong.class org/python/core/PyMethod.class Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/Py.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -923,8 +923,7 @@ stderr.println("Java Traceback:"); java.io.CharArrayWriter buf = new java.io.CharArrayWriter(); if (t instanceof PyException) { - ((PyException) t).super__printStackTrace( - new java.io.PrintWriter(buf)); + ((PyException)t).super__printStackTrace(new java.io.PrintWriter(buf)); } else { t.printStackTrace(new java.io.PrintWriter(buf)); } @@ -1551,7 +1550,6 @@ */ 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) { Modified: trunk/jython/src/org/python/core/PyException.java =================================================================== --- trunk/jython/src/org/python/core/PyException.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/PyException.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -3,24 +3,20 @@ import java.io.*; /** - * A wrapper for all python exception. Note that the wellknown - * python exception are <b>not</b> subclasses of PyException. - * Instead the python exception class is stored in the - * <code>type</code> field and value or class instance is stored - * in the <code>value</code> field. + * A wrapper for all python exception. Note that the wellknown python exception are <b>not</b> + * subclasses of PyException. Instead the python exception class is stored in the <code>type</code> + * field and value or class instance is stored in the <code>value</code> field. */ - public class PyException extends RuntimeException { + /** - * The python exception class (for class exception) or - * identifier (for string exception). + * The python exception class (for class exception) or identifier (for string exception). */ public PyObject type; /** - * The exception instance (for class exception) or exception - * value (for string exception). + * The exception instance (for class exception) or exception value (for string exception). */ public PyObject value = Py.None; Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -16,10 +16,12 @@ import org.python.core.util.StringUtil; import org.python.expose.ExposeAsSuperclass; +import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; import org.python.util.Generic; -public class PyJavaType extends PyType implements ExposeAsSuperclass { +@ExposedType(name = "javatype") +public class PyJavaType extends PyType { private final static Class<?>[] OO = {PyObject.class, PyObject.class}; @@ -35,6 +37,14 @@ super(TYPE == null ? fromClass(PyType.class) : TYPE); } + @ExposedMethod(defaults = "null") + final PyList javatype_mro(PyObject o) { + if (o == null) { + return new PyList(mro); + } + return new PyList(((PyJavaType)o).mro); + } + @Override public Class<?> getProxyType() { return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; @@ -48,6 +58,10 @@ @Override protected void checkSetattr() {} + protected boolean useMetatypeFirst(PyObject attr) { + return !(attr instanceof PyReflectedField || attr instanceof PyReflectedFunction); + } + @Override protected void init() { name = underlying_class.getName(); @@ -62,10 +76,14 @@ // their interfaces computeLinearMro(baseClass); } else { + javaProxy = underlying_class; + objtype = PyType.fromClass(Class.class); // Wrapped Java types fill in their mro first using their base class and then all of // their interfaces. if (baseClass == null) { base = PyType.fromClass(PyObject.class); + } else if(underlying_class == Class.class) { + base = PyType.fromClass(PyType.class); } else { base = PyType.fromClass(baseClass); } @@ -300,8 +318,9 @@ PyBuiltinCallable equals = new PyBuiltinMethodNarrow("__eq__", 1, 1) { @Override public PyObject __call__(PyObject o) { - Object oAsJava = o.__tojava__(self.getJavaProxy().getClass()); - return self.getJavaProxy().equals(oAsJava) ? Py.True : Py.False; + Object proxy = self.getJavaProxy(); + Object oAsJava = o.__tojava__(proxy.getClass()); + return proxy.equals(oAsJava) ? Py.True : Py.False; } }; dict.__setitem__("__eq__", new PyMethodDescr(this, equals)); Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/PyObject.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -44,7 +44,7 @@ */ protected Object javaProxy; - private PyType objtype; + PyType objtype; @ExposedGet(name = "__class__") public PyType getType() { @@ -1007,7 +1007,7 @@ protected void mergeClassDict(PyDictionary accum, PyObject aClass) { // Merge in the type's dict (if any) aClass.mergeDictAttr(accum, "__dict__"); - + // Recursively merge in the base types' (if any) dicts PyObject bases = aClass.__findattr__("__bases__"); if (bases == null) { Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -46,10 +46,6 @@ return new PyMethod(this, container, wherefound); } - public boolean _doset(PyObject container) { - throw Py.TypeError("java function not settable: " + __name__); - } - public PyObject getDoc() { return __doc__; } Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/core/PyType.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -133,6 +133,12 @@ } metatype = winner; } + // Use PyType as the metaclass for Python subclasses of Java classes rather than PyJavaType. + // Using PyJavaType as metaclass exposes the java.lang.Object methods on the type, which + // doesn't make sense for python subclasses. + if (metatype == PyType.fromClass(Class.class)) { + metatype = TYPE; + } if (bases_list.length == 0) { bases_list = new PyObject[] {object_type}; } @@ -997,6 +1003,7 @@ newtype = new PyJavaType(); } + // If filling in the type above filled the type under creation, use that one PyType type = class_to_type.get(c); if (type != null) { @@ -1041,11 +1048,10 @@ PyType metatype = getType(); PyObject metaattr = metatype.lookup(name); - PyObject res = null; - if (metaattr != null) { + if (metaattr != null && useMetatypeFirst(metaattr)) { if (metaattr.isDataDescr()) { - res = metaattr.__get__(this, metatype); + PyObject res = metaattr.__get__(this, metatype); if (res != null) return res; } @@ -1054,7 +1060,7 @@ PyObject attr = lookup(name); if (attr != null) { - res = attr.__get__(null, this); + PyObject res = attr.__get__(null, this); if (res != null) { return res; } @@ -1067,6 +1073,14 @@ return null; } + /** + * Returns true if the given attribute retrieved from an object's metatype should be used before + * looking for the object on the actual object. + */ + protected boolean useMetatypeFirst(PyObject attr) { + return true; + } + @ExposedMethod final void type___setattr__(PyObject name, PyObject value) { type___setattr__(asName(name), value); Modified: trunk/jython/src/org/python/modules/ArrayModule.java =================================================================== --- trunk/jython/src/org/python/modules/ArrayModule.java 2008-12-21 23:25:39 UTC (rev 5784) +++ trunk/jython/src/org/python/modules/ArrayModule.java 2008-12-22 02:18:12 UTC (rev 5785) @@ -11,7 +11,7 @@ * The python array module, plus jython extensions from jarray. */ public class ArrayModule implements ClassDictInit { - + public static PyString __doc__ = new PyString( "This module defines a new object type which can efficiently represent\n" + "an array of basic values: characters, integers, floating point\n" + @@ -42,16 +42,16 @@ "\n" + "ArrayType -- type object for array objects\n" ); - - public static void classDictInit(PyObject dict){ + + public static void classDictInit(PyObject dict) { dict.__setitem__("array", PyType.fromClass(PyArray.class)); dict.__setitem__("ArrayType", PyType.fromClass(PyArray.class)); } - + /* - * These are jython extensions (from jarray module). + * These are jython extensions (from jarray module). * Note that the argument order is consistent with - * python array module, but is reversed from jarray module. + * python array module, but is reversed from jarray module. */ public static PyArray zeros(char typecode, int n) { return PyArray.zeros(n, typecode); @@ -59,5 +59,5 @@ public static PyArray zeros(Class type, int n) { return PyArray.zeros(n, type); - } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-23 00:35:36
|
Revision: 5788 http://jython.svn.sourceforge.net/jython/?rev=5788&view=rev Author: fwierzbicki Date: 2008-12-23 00:35:32 +0000 (Tue, 23 Dec 2008) Log Message: ----------- First cut at generating the __doc__ test for builtin types. So far I am only generating the docs for str and unicode, and I have only exposed the docs for str. Modified Paths: -------------- trunk/jython/src/org/python/core/PyString.java Added Paths: ----------- trunk/jython/Misc/make_pydocs.py trunk/jython/src/org/python/core/BuiltinDocs.java Added: trunk/jython/Misc/make_pydocs.py =================================================================== --- trunk/jython/Misc/make_pydocs.py (rev 0) +++ trunk/jython/Misc/make_pydocs.py 2008-12-23 00:35:32 UTC (rev 5788) @@ -0,0 +1,26 @@ +class PyDocGenerator(object): + def __init__(self): + self.out = open("BuiltinDocs.java", "w") + print >> self.out, '//generated by make_pydocs.py\n' + print >> self.out, 'package org.python.core;\n' + print >> self.out, 'public class BuiltinDocs {\n' + objects = [str, unicode] + for obj in objects: + print >> self.out, ' //Docs for %s' % obj + for meth in dir(obj): + self.print_doc(obj, meth) + print >> self.out, '}' + + + def print_doc(self, obj, meth): + doc = (getattr(obj, meth)).__doc__ + if doc == None: + doc = "" + lines = doc.split("\n") + out = '\\n" + \n "'.join(lines) + print >> self.out, (' public final static String %s_%s_doc = ' + % (obj.__name__, meth)) + print >> self.out, ' "%s";\n' % out + +if __name__ == '__main__': + PyDocGenerator() Added: trunk/jython/src/org/python/core/BuiltinDocs.java =================================================================== --- trunk/jython/src/org/python/core/BuiltinDocs.java (rev 0) +++ trunk/jython/src/org/python/core/BuiltinDocs.java 2008-12-23 00:35:32 UTC (rev 5788) @@ -0,0 +1,710 @@ +//generated by make_pydocs.py + +package org.python.core; + +public class BuiltinDocs { + + //Docs for <type 'str'> + public final static String str___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String str___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String str___contains___doc = + "x.__contains__(y) <==> y in x"; + + public final static String str___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String str___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String str___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String str___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String str___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String str___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String str___getnewargs___doc = + ""; + + public final static String str___getslice___doc = + "x.__getslice__(i, j) <==> x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String str___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String str___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String str___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String str___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String str___len___doc = + "x.__len__() <==> len(x)"; + + public final static String str___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String str___mod___doc = + "x.__mod__(y) <==> x%y"; + + public final static String str___mul___doc = + "x.__mul__(n) <==> x*n"; + + public final static String str___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String str___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String str___reduce___doc = + "helper for pickle"; + + public final static String str___reduce_ex___doc = + "helper for pickle"; + + public final static String str___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String str___rmod___doc = + "x.__rmod__(y) <==> y%x"; + + public final static String str___rmul___doc = + "x.__rmul__(n) <==> n*x"; + + public final static String str___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String str___str___doc = + "x.__str__() <==> str(x)"; + + public final static String str_capitalize_doc = + "S.capitalize() -> string\n" + + "\n" + + "Return a copy of the string S with only its first character\n" + + "capitalized."; + + public final static String str_center_doc = + "S.center(width[, fillchar]) -> string\n" + + "\n" + + "Return S centered in a string of length width. Padding is\n" + + "done using the specified fill character (default is a space)"; + + public final static String str_count_doc = + "S.count(sub[, start[, end]]) -> int\n" + + "\n" + + "Return the number of non-overlapping occurrences of substring sub in\n" + + "string S[start:end]. Optional arguments start and end are interpreted\n" + + "as in slice notation."; + + public final static String str_decode_doc = + "S.decode([encoding[,errors]]) -> object\n" + + "\n" + + "Decodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n" + + "as well as any other name registerd with codecs.register_error that is\n" + + "able to handle UnicodeDecodeErrors."; + + public final static String str_encode_doc = + "S.encode([encoding[,errors]]) -> object\n" + + "\n" + + "Encodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n" + + "'xmlcharrefreplace' as well as any other name registered with\n" + + "codecs.register_error that is able to handle UnicodeEncodeErrors."; + + public final static String str_endswith_doc = + "S.endswith(suffix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S ends with the specified suffix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "suffix can also be a tuple of strings to try."; + + public final static String str_expandtabs_doc = + "S.expandtabs([tabsize]) -> string\n" + + "\n" + + "Return a copy of S where all tab characters are expanded using spaces.\n" + + "If tabsize is not given, a tab size of 8 characters is assumed."; + + public final static String str_find_doc = + "S.find(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the lowest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String str_index_doc = + "S.index(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.find() but raise ValueError when the substring is not found."; + + public final static String str_isalnum_doc = + "S.isalnum() -> bool\n" + + "\n" + + "Return True if all characters in S are alphanumeric\n" + + "and there is at least one character in S, False otherwise."; + + public final static String str_isalpha_doc = + "S.isalpha() -> bool\n" + + "\n" + + "Return True if all characters in S are alphabetic\n" + + "and there is at least one character in S, False otherwise."; + + public final static String str_isdigit_doc = + "S.isdigit() -> bool\n" + + "\n" + + "Return True if all characters in S are digits\n" + + "and there is at least one character in S, False otherwise."; + + public final static String str_islower_doc = + "S.islower() -> bool\n" + + "\n" + + "Return True if all cased characters in S are lowercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String str_isspace_doc = + "S.isspace() -> bool\n" + + "\n" + + "Return True if all characters in S are whitespace\n" + + "and there is at least one character in S, False otherwise."; + + public final static String str_istitle_doc = + "S.istitle() -> bool\n" + + "\n" + + "Return True if S is a titlecased string and there is at least one\n" + + "character in S, i.e. uppercase characters may only follow uncased\n" + + "characters and lowercase characters only cased ones. Return False\n" + + "otherwise."; + + public final static String str_isupper_doc = + "S.isupper() -> bool\n" + + "\n" + + "Return True if all cased characters in S are uppercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String str_join_doc = + "S.join(sequence) -> string\n" + + "\n" + + "Return a string which is the concatenation of the strings in the\n" + + "sequence. The separator between elements is S."; + + public final static String str_ljust_doc = + "S.ljust(width[, fillchar]) -> string\n" + + "\n" + + "Return S left justified in a string of length width. Padding is\n" + + "done using the specified fill character (default is a space)."; + + public final static String str_lower_doc = + "S.lower() -> string\n" + + "\n" + + "Return a copy of the string S converted to lowercase."; + + public final static String str_lstrip_doc = + "S.lstrip([chars]) -> string or unicode\n" + + "\n" + + "Return a copy of the string S with leading whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is unicode, S will be converted to unicode before stripping"; + + public final static String str_partition_doc = + "S.partition(sep) -> (head, sep, tail)\n" + + "\n" + + "Searches for the separator sep in S, and returns the part before it,\n" + + "the separator itself, and the part after it. If the separator is not\n" + + "found, returns S and two empty strings."; + + public final static String str_replace_doc = + "S.replace (old, new[, count]) -> string\n" + + "\n" + + "Return a copy of string S with all occurrences of substring\n" + + "old replaced by new. If the optional argument count is\n" + + "given, only the first count occurrences are replaced."; + + public final static String str_rfind_doc = + "S.rfind(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the highest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String str_rindex_doc = + "S.rindex(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.rfind() but raise ValueError when the substring is not found."; + + public final static String str_rjust_doc = + "S.rjust(width[, fillchar]) -> string\n" + + "\n" + + "Return S right justified in a string of length width. Padding is\n" + + "done using the specified fill character (default is a space)"; + + public final static String str_rpartition_doc = + "S.rpartition(sep) -> (tail, sep, head)\n" + + "\n" + + "Searches for the separator sep in S, starting at the end of S, and returns\n" + + "the part before it, the separator itself, and the part after it. If the\n" + + "separator is not found, returns two empty strings and S."; + + public final static String str_rsplit_doc = + "S.rsplit([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in the string S, using sep as the\n" + + "delimiter string, starting at the end of the string and working\n" + + "to the front. If maxsplit is given, at most maxsplit splits are\n" + + "done. If sep is not specified or is None, any whitespace string\n" + + "is a separator."; + + public final static String str_rstrip_doc = + "S.rstrip([chars]) -> string or unicode\n" + + "\n" + + "Return a copy of the string S with trailing whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is unicode, S will be converted to unicode before stripping"; + + public final static String str_split_doc = + "S.split([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in the string S, using sep as the\n" + + "delimiter string. If maxsplit is given, at most maxsplit\n" + + "splits are done. If sep is not specified or is None, any\n" + + "whitespace string is a separator."; + + public final static String str_splitlines_doc = + "S.splitlines([keepends]) -> list of strings\n" + + "\n" + + "Return a list of the lines in S, breaking at line boundaries.\n" + + "Line breaks are not included in the resulting list unless keepends\n" + + "is given and true."; + + public final static String str_startswith_doc = + "S.startswith(prefix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S starts with the specified prefix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "prefix can also be a tuple of strings to try."; + + public final static String str_strip_doc = + "S.strip([chars]) -> string or unicode\n" + + "\n" + + "Return a copy of the string S with leading and trailing\n" + + "whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is unicode, S will be converted to unicode before stripping"; + + public final static String str_swapcase_doc = + "S.swapcase() -> string\n" + + "\n" + + "Return a copy of the string S with uppercase characters\n" + + "converted to lowercase and vice versa."; + + public final static String str_title_doc = + "S.title() -> string\n" + + "\n" + + "Return a titlecased version of S, i.e. words start with uppercase\n" + + "characters, all remaining cased characters have lowercase."; + + public final static String str_translate_doc = + "S.translate(table [,deletechars]) -> string\n" + + "\n" + + "Return a copy of the string S, where all characters occurring\n" + + "in the optional argument deletechars are removed, and the\n" + + "remaining characters have been mapped through the given\n" + + "translation table, which must be a string of length 256."; + + public final static String str_upper_doc = + "S.upper() -> string\n" + + "\n" + + "Return a copy of the string S converted to uppercase."; + + public final static String str_zfill_doc = + "S.zfill(width) -> string\n" + + "\n" + + "Pad a numeric string S with zeros on the left, to fill a field\n" + + "of the specified width. The string S is never truncated."; + + //Docs for <type 'unicode'> + public final static String unicode___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String unicode___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String unicode___contains___doc = + "x.__contains__(y) <==> y in x"; + + public final static String unicode___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String unicode___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String unicode___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String unicode___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String unicode___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String unicode___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String unicode___getnewargs___doc = + ""; + + public final static String unicode___getslice___doc = + "x.__getslice__(i, j) <==> x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String unicode___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String unicode___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String unicode___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String unicode___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String unicode___len___doc = + "x.__len__() <==> len(x)"; + + public final static String unicode___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String unicode___mod___doc = + "x.__mod__(y) <==> x%y"; + + public final static String unicode___mul___doc = + "x.__mul__(n) <==> x*n"; + + public final static String unicode___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String unicode___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String unicode___reduce___doc = + "helper for pickle"; + + public final static String unicode___reduce_ex___doc = + "helper for pickle"; + + public final static String unicode___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String unicode___rmod___doc = + "x.__rmod__(y) <==> y%x"; + + public final static String unicode___rmul___doc = + "x.__rmul__(n) <==> n*x"; + + public final static String unicode___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String unicode___str___doc = + "x.__str__() <==> str(x)"; + + public final static String unicode_capitalize_doc = + "S.capitalize() -> unicode\n" + + "\n" + + "Return a capitalized version of S, i.e. make the first character\n" + + "have upper case."; + + public final static String unicode_center_doc = + "S.center(width[, fillchar]) -> unicode\n" + + "\n" + + "Return S centered in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)"; + + public final static String unicode_count_doc = + "S.count(sub[, start[, end]]) -> int\n" + + "\n" + + "Return the number of non-overlapping occurrences of substring sub in\n" + + "Unicode string S[start:end]. Optional arguments start and end are\n" + + "interpreted as in slice notation."; + + public final static String unicode_decode_doc = + "S.decode([encoding[,errors]]) -> string or unicode\n" + + "\n" + + "Decodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n" + + "as well as any other name registerd with codecs.register_error that is\n" + + "able to handle UnicodeDecodeErrors."; + + public final static String unicode_encode_doc = + "S.encode([encoding[,errors]]) -> string or unicode\n" + + "\n" + + "Encodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n" + + "'xmlcharrefreplace' as well as any other name registered with\n" + + "codecs.register_error that can handle UnicodeEncodeErrors."; + + public final static String unicode_endswith_doc = + "S.endswith(suffix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S ends with the specified suffix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "suffix can also be a tuple of strings to try."; + + public final static String unicode_expandtabs_doc = + "S.expandtabs([tabsize]) -> unicode\n" + + "\n" + + "Return a copy of S where all tab characters are expanded using spaces.\n" + + "If tabsize is not given, a tab size of 8 characters is assumed."; + + public final static String unicode_find_doc = + "S.find(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the lowest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String unicode_index_doc = + "S.index(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.find() but raise ValueError when the substring is not found."; + + public final static String unicode_isalnum_doc = + "S.isalnum() -> bool\n" + + "\n" + + "Return True if all characters in S are alphanumeric\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_isalpha_doc = + "S.isalpha() -> bool\n" + + "\n" + + "Return True if all characters in S are alphabetic\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_isdecimal_doc = + "S.isdecimal() -> bool\n" + + "\n" + + "Return True if there are only decimal characters in S,\n" + + "False otherwise."; + + public final static String unicode_isdigit_doc = + "S.isdigit() -> bool\n" + + "\n" + + "Return True if all characters in S are digits\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_islower_doc = + "S.islower() -> bool\n" + + "\n" + + "Return True if all cased characters in S are lowercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String unicode_isnumeric_doc = + "S.isnumeric() -> bool\n" + + "\n" + + "Return True if there are only numeric characters in S,\n" + + "False otherwise."; + + public final static String unicode_isspace_doc = + "S.isspace() -> bool\n" + + "\n" + + "Return True if all characters in S are whitespace\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_istitle_doc = + "S.istitle() -> bool\n" + + "\n" + + "Return True if S is a titlecased string and there is at least one\n" + + "character in S, i.e. upper- and titlecase characters may only\n" + + "follow uncased characters and lowercase characters only cased ones.\n" + + "Return False otherwise."; + + public final static String unicode_isupper_doc = + "S.isupper() -> bool\n" + + "\n" + + "Return True if all cased characters in S are uppercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String unicode_join_doc = + "S.join(sequence) -> unicode\n" + + "\n" + + "Return a string which is the concatenation of the strings in the\n" + + "sequence. The separator between elements is S."; + + public final static String unicode_ljust_doc = + "S.ljust(width[, fillchar]) -> int\n" + + "\n" + + "Return S left justified in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)."; + + public final static String unicode_lower_doc = + "S.lower() -> unicode\n" + + "\n" + + "Return a copy of the string S converted to lowercase."; + + public final static String unicode_lstrip_doc = + "S.lstrip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with leading whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_partition_doc = + "S.partition(sep) -> (head, sep, tail)\n" + + "\n" + + "Searches for the separator sep in S, and returns the part before it,\n" + + "the separator itself, and the part after it. If the separator is not\n" + + "found, returns S and two empty strings."; + + public final static String unicode_replace_doc = + "S.replace (old, new[, maxsplit]) -> unicode\n" + + "\n" + + "Return a copy of S with all occurrences of substring\n" + + "old replaced by new. If the optional argument maxsplit is\n" + + "given, only the first maxsplit occurrences are replaced."; + + public final static String unicode_rfind_doc = + "S.rfind(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the highest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String unicode_rindex_doc = + "S.rindex(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.rfind() but raise ValueError when the substring is not found."; + + public final static String unicode_rjust_doc = + "S.rjust(width[, fillchar]) -> unicode\n" + + "\n" + + "Return S right justified in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)."; + + public final static String unicode_rpartition_doc = + "S.rpartition(sep) -> (tail, sep, head)\n" + + "\n" + + "Searches for the separator sep in S, starting at the end of S, and returns\n" + + "the part before it, the separator itself, and the part after it. If the\n" + + "separator is not found, returns two empty strings and S."; + + public final static String unicode_rsplit_doc = + "S.rsplit([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in S, using sep as the\n" + + "delimiter string, starting at the end of the string and\n" + + "working to the front. If maxsplit is given, at most maxsplit\n" + + "splits are done. If sep is not specified, any whitespace string\n" + + "is a separator."; + + public final static String unicode_rstrip_doc = + "S.rstrip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with trailing whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_split_doc = + "S.split([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in S, using sep as the\n" + + "delimiter string. If maxsplit is given, at most maxsplit\n" + + "splits are done. If sep is not specified or is None,\n" + + "any whitespace string is a separator."; + + public final static String unicode_splitlines_doc = + "S.splitlines([keepends]]) -> list of strings\n" + + "\n" + + "Return a list of the lines in S, breaking at line boundaries.\n" + + "Line breaks are not included in the resulting list unless keepends\n" + + "is given and true."; + + public final static String unicode_startswith_doc = + "S.startswith(prefix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S starts with the specified prefix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "prefix can also be a tuple of strings to try."; + + public final static String unicode_strip_doc = + "S.strip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with leading and trailing\n" + + "whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_swapcase_doc = + "S.swapcase() -> unicode\n" + + "\n" + + "Return a copy of S with uppercase characters converted to lowercase\n" + + "and vice versa."; + + public final static String unicode_title_doc = + "S.title() -> unicode\n" + + "\n" + + "Return a titlecased version of S, i.e. words start with title case\n" + + "characters, all remaining cased characters have lower case."; + + public final static String unicode_translate_doc = + "S.translate(table) -> unicode\n" + + "\n" + + "Return a copy of the string S, where all characters have been mapped\n" + + "through the given translation table, which must be a mapping of\n" + + "Unicode ordinals to Unicode ordinals, Unicode strings or None.\n" + + "Unmapped characters are left untouched. Characters mapped to None\n" + + "are deleted."; + + public final static String unicode_upper_doc = + "S.upper() -> unicode\n" + + "\n" + + "Return a copy of S converted to uppercase."; + + public final static String unicode_zfill_doc = + "S.zfill(width) -> unicode\n" + + "\n" + + "Pad a numeric string x with zeros on the left, to fill a field\n" + + "of the specified width. The string x is never truncated."; + +} Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2008-12-22 03:29:57 UTC (rev 5787) +++ trunk/jython/src/org/python/core/PyString.java 2008-12-23 00:35:32 UTC (rev 5788) @@ -92,7 +92,7 @@ return str___str__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___str___doc) final PyString str___str__() { if (getClass() == PyString.class) { return this; @@ -104,6 +104,7 @@ return str___unicode__(); } + //XXX: need doc @ExposedMethod final PyUnicode str___unicode__() { return new PyUnicode(this); @@ -113,7 +114,7 @@ return str___len__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___len___doc) final int str___len__() { return string.length(); } @@ -122,6 +123,7 @@ return string; } + //XXX: need doc @ExposedMethod final String str_toString() { return toString(); @@ -141,7 +143,7 @@ return str___repr__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___repr___doc) final PyString str___repr__() { return new PyString(encode_UnicodeEscape(string, true)); } @@ -471,7 +473,7 @@ return false; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___getitem___doc) final PyObject str___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if (ret == null) { @@ -480,6 +482,7 @@ return ret; } + //XXX: need doc @ExposedMethod(defaults = "null") final PyObject str___getslice__(PyObject start, PyObject stop, PyObject step) { return seq___getslice__(start, stop, step); @@ -502,7 +505,7 @@ return str___eq__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___eq___doc) final PyObject str___eq__(PyObject other) { String s = coerce(other); if (s == null) @@ -514,7 +517,7 @@ return str___ne__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___ne___doc) final PyObject str___ne__(PyObject other) { String s = coerce(other); if (s == null) @@ -526,7 +529,7 @@ return str___lt__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___lt___doc) final PyObject str___lt__(PyObject other){ String s = coerce(other); if (s == null) @@ -538,7 +541,7 @@ return str___le__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___le___doc) final PyObject str___le__(PyObject other){ String s = coerce(other); if (s == null) @@ -550,7 +553,7 @@ return str___gt__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___gt___doc) final PyObject str___gt__(PyObject other){ String s = coerce(other); if (s == null) @@ -562,7 +565,7 @@ return str___ge__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___ge___doc) final PyObject str___ge__(PyObject other){ String s = coerce(other); if (s == null) @@ -580,7 +583,7 @@ return str___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___hash___doc) final int str___hash__() { if (cached_hashcode == 0) cached_hashcode = string.hashCode(); @@ -651,7 +654,7 @@ return str___contains__(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___contains___doc) final boolean str___contains__(PyObject o) { if (!(o instanceof PyString)) throw Py.TypeError("'in <string>' requires string as left operand"); @@ -683,7 +686,7 @@ return str___mul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___mul___doc) final PyObject str___mul__(PyObject o) { if (!o.isIndex()) { return null; @@ -696,7 +699,7 @@ return str___rmul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___rmul___doc) final PyObject str___rmul__(PyObject o) { if (!o.isIndex()) { return null; @@ -708,7 +711,7 @@ return str___add__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___add___doc) final PyObject str___add__(PyObject other) { if (other instanceof PyUnicode) { return decode().__add__(other); @@ -720,7 +723,7 @@ return null; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___getnewargs___doc) final PyTuple str___getnewargs__() { return new PyTuple(new PyString(this.string)); } @@ -733,7 +736,7 @@ return str___mod__(other); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str___mod___doc) public PyObject str___mod__(PyObject other){ StringFormatter fmt = new StringFormatter(string, false); return fmt.format(other); @@ -904,7 +907,7 @@ return str_lower(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_lower_doc) final String str_lower() { return string.toLowerCase(); } @@ -913,7 +916,7 @@ return str_upper(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_upper_doc) final String str_upper() { return string.toUpperCase(); } @@ -922,7 +925,7 @@ return str_title(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_title_doc) final String str_title() { char[] chars = string.toCharArray(); int n = chars.length; @@ -949,7 +952,7 @@ return str_swapcase(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_swapcase_doc) final String str_swapcase() { char[] chars = string.toCharArray(); int n=chars.length; @@ -973,7 +976,7 @@ return str_strip(sep); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_strip_doc) final String str_strip(String sep) { char[] chars = string.toCharArray(); int n=chars.length; @@ -1009,7 +1012,7 @@ return str_lstrip(sep); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_lstrip_doc) final String str_lstrip(String sep) { char[] chars = string.toCharArray(); int n=chars.length; @@ -1028,7 +1031,7 @@ return str_rstrip(sep); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_rstrip_doc) final String str_rstrip(String sep) { char[] chars = string.toCharArray(); int n=chars.length; @@ -1056,7 +1059,7 @@ return str_split(sep, maxsplit); } - @ExposedMethod(defaults = {"null", "-1"}) + @ExposedMethod(defaults = {"null", "-1"}, doc = BuiltinDocs.str_split_doc) final PyList str_split(String sep, int maxsplit) { if (sep != null) { if (sep.length() == 0) { @@ -1107,7 +1110,7 @@ return str_rsplit(sep, maxsplit); } - @ExposedMethod(defaults = {"null", "-1"}) + @ExposedMethod(defaults = {"null", "-1"}, doc = BuiltinDocs.str_rsplit_doc) final PyList str_rsplit(String sep, int maxsplit) { if (sep != null) { if (sep.length() == 0) { @@ -1169,7 +1172,7 @@ return str_partition(sepObj); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_partition_doc) final PyTuple str_partition(PyObject sepObj) { String sep; @@ -1220,7 +1223,7 @@ return str_rpartition(sepObj); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_rpartition_doc) final PyTuple str_rpartition(PyObject sepObj) { String sep; @@ -1338,7 +1341,7 @@ return str_splitlines(keepends); } - @ExposedMethod(defaults = "false") + @ExposedMethod(defaults = "false", doc = BuiltinDocs.str_splitlines_doc) final PyList str_splitlines(boolean keepends) { PyList list = new PyList(); @@ -1387,7 +1390,7 @@ return str_index(sub, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_index_doc) final int str_index(String sub, int start, PyObject end) { int index = str_find(sub, start, end); if (index == -1) @@ -1407,7 +1410,7 @@ return str_rindex(sub, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_rindex_doc) final int str_rindex(String sub, int start, PyObject end) { int index = str_rfind(sub, start, end); if(index == -1) @@ -1427,7 +1430,7 @@ return str_count(sub, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_count_doc) final int str_count(String sub, int start, PyObject end) { int[] indices = translateIndices(start, end); int n = sub.length(); @@ -1461,7 +1464,7 @@ return str_find(sub, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_find_doc) final int str_find(String sub, int start, PyObject end) { int[] indices = translateIndices(start, end); int index = string.indexOf(sub, indices[0]); @@ -1483,7 +1486,7 @@ return str_rfind(sub, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_rfind_doc) final int str_rfind(String sub, int start, PyObject end) { int[] indices = translateIndices(start, end); int index = string.lastIndexOf(sub, indices[1] - sub.length()); @@ -1690,7 +1693,7 @@ return str_ljust(width, padding); } - @ExposedMethod(defaults="null") + @ExposedMethod(defaults="null", doc = BuiltinDocs.str_ljust_doc) final String str_ljust(int width, String fillchar) { char pad = parse_fillchar("ljust", fillchar); int n = width-string.length(); @@ -1703,7 +1706,7 @@ return str_rjust(width, null); } - @ExposedMethod(defaults="null") + @ExposedMethod(defaults="null", doc = BuiltinDocs.str_rjust_doc) final String str_rjust(int width, String fillchar) { char pad = parse_fillchar("rjust", fillchar); int n = width-string.length(); @@ -1716,7 +1719,7 @@ return str_center(width, null); } - @ExposedMethod(defaults="null") + @ExposedMethod(defaults="null", doc = BuiltinDocs.str_center_doc) final String str_center(int width, String fillchar) { char pad = parse_fillchar("center", fillchar); int n = width-string.length(); @@ -1733,7 +1736,7 @@ return str_zfill(width); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_zfill_doc) final String str_zfill(int width) { String s = string; int n = s.length(); @@ -1767,7 +1770,7 @@ return str_expandtabs(tabsize); } - @ExposedMethod(defaults = "8") + @ExposedMethod(defaults = "8", doc = BuiltinDocs.str_expandtabs_doc) final String str_expandtabs(int tabsize) { String s = string; StringBuilder buf = new StringBuilder((int)(s.length()*1.5)); @@ -1798,7 +1801,7 @@ return str_capitalize(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_capitalize_doc) final String str_capitalize() { if (string.length() == 0) return string; @@ -1806,7 +1809,7 @@ return first.concat(string.substring(1).toLowerCase()); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_replace_doc) final PyString str_replace(PyObject oldPiece, PyObject newPiece, PyObject maxsplit) { if(!(oldPiece instanceof PyString) || !(newPiece instanceof PyString)) { throw Py.TypeError("str or unicode required for replace"); @@ -1853,7 +1856,7 @@ return str_join(seq); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_join_doc) final PyString str_join(PyObject obj) { PySequence seq = fastSequence(obj, ""); int seqLen = seq.__len__(); @@ -1987,7 +1990,7 @@ return str_startswith(prefix, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_startswith_doc) final boolean str_startswith(PyObject prefix, int start, PyObject end) { int[] indices = translateIndices(start, end); @@ -2029,7 +2032,7 @@ return str_endswith(suffix, start, Py.newInteger(end)); } - @ExposedMethod(defaults = {"0", "null"}) + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_endswith_doc) final boolean str_endswith(PyObject suffix, int start, PyObject end) { int[] indices = translateIndices(start, end); @@ -2097,7 +2100,7 @@ return str_translate(table, deletechars); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_translate_doc) final String str_translate(String table, String deletechars) { if (table.length() != 256) throw Py.ValueError( @@ -2161,7 +2164,7 @@ return str_islower(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_islower_doc) final boolean str_islower() { int n = string.length(); @@ -2185,7 +2188,7 @@ return str_isupper(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_isupper_doc) final boolean str_isupper() { int n = string.length(); @@ -2209,7 +2212,7 @@ return str_isalpha(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_isalpha_doc) final boolean str_isalpha() { int n = string.length(); @@ -2233,7 +2236,7 @@ return str_isalnum(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_isalnum_doc) final boolean str_isalnum() { int n = string.length(); @@ -2266,7 +2269,7 @@ return str_isdecimal(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.unicode_isdecimal_doc) final boolean str_isdecimal() { int n = string.length(); @@ -2297,7 +2300,7 @@ return str_isdigit(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_isdigit_doc) final boolean str_isdigit() { int n = string.length(); @@ -2321,7 +2324,7 @@ return str_isnumeric(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.unicode_isnumeric_doc) final boolean str_isnumeric() { int n = string.length(); @@ -2351,7 +2354,7 @@ return str_istitle(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_istitle_doc) final boolean str_istitle() { int n = string.length(); @@ -2387,7 +2390,7 @@ return str_isspace(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.str_isspace_doc) final boolean str_isspace() { int n = string.length(); @@ -2411,7 +2414,8 @@ return str_isunicode(); } - @ExposedMethod + //XXX: need doc + @ExposedMethod/*(doc = BuiltinDocs.unicode_isunicode_doc)*/ final boolean str_isunicode() { int n = string.length(); for (int i = 0; i < n; i++) { @@ -2434,7 +2438,7 @@ return str_encode(encoding, errors); } - @ExposedMethod(defaults = {"null", "null"}) + @ExposedMethod(defaults = {"null", "null"}, doc = BuiltinDocs.str_encode_doc) final String str_encode(String encoding, String errors) { return codecs.encode(this, encoding, errors); } @@ -2451,7 +2455,7 @@ return str_decode(encoding, errors); } - @ExposedMethod(defaults = {"null", "null"}) + @ExposedMethod(defaults = {"null", "null"}, doc = BuiltinDocs.str_decode_doc) final PyObject str_decode(String encoding, String errors) { return codecs.decode(this, encoding, errors); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-23 02:34:23
|
Revision: 5790 http://jython.svn.sourceforge.net/jython/?rev=5790&view=rev Author: fwierzbicki Date: 2008-12-23 02:34:17 +0000 (Tue, 23 Dec 2008) Log Message: ----------- Added in most of the types from make_checker and created a more complete BuiltinDocs.java. Still need to actually expose the docs in each of the builtins. Modified Paths: -------------- trunk/jython/Misc/make_pydocs.py trunk/jython/src/org/python/core/BuiltinDocs.java Modified: trunk/jython/Misc/make_pydocs.py =================================================================== --- trunk/jython/Misc/make_pydocs.py 2008-12-23 01:41:45 UTC (rev 5789) +++ trunk/jython/Misc/make_pydocs.py 2008-12-23 02:34:17 UTC (rev 5790) @@ -47,6 +47,14 @@ complex, opt('bool'), classmethod, +#buffer, +# + +type(f), +type(m), +type(f.func_code), +type(sys._getframe()), +type(tb), +#type(slice), ] outfile = open("BuiltinDocs.java", "w") Modified: trunk/jython/src/org/python/core/BuiltinDocs.java =================================================================== --- trunk/jython/src/org/python/core/BuiltinDocs.java 2008-12-23 01:41:45 UTC (rev 5789) +++ trunk/jython/src/org/python/core/BuiltinDocs.java 2008-12-23 02:34:17 UTC (rev 5790) @@ -4,6 +4,1470 @@ public class BuiltinDocs { + //Docs for <type 'object'> + public final static String object___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String object___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String object___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String object___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String object___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String object___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String object___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String object___reduce___doc = + "helper for pickle"; + + public final static String object___reduce_ex___doc = + "helper for pickle"; + + public final static String object___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String object___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String object___str___doc = + "x.__str__() <==> str(x)"; + + //Docs for <type 'type'> + public final static String type___base___doc = + "The most base type"; + + public final static String type___bases___doc = + "tuple() -> an empty tuple\n" + + "tuple(sequence) -> tuple initialized from sequence's items\n" + + "\n" + + "If the argument is a tuple, the return value is the same object."; + + public final static String type___basicsize___doc = + "int(x[, base]) -> integer\n" + + "\n" + + "Convert a string or number to an integer, if possible. A floating point\n" + + "argument will be truncated towards zero (this does not include a string\n" + + "representation of a floating point number!) When converting a string, use\n" + + "the optional base. It is an error to supply a base when converting a\n" + + "non-string. If the argument is outside the integer range a long object\n" + + "will be returned instead."; + + public final static String type___call___doc = + "x.__call__(...) <==> x(...)"; + + public final static String type___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String type___cmp___doc = + "x.__cmp__(y) <==> cmp(x,y)"; + + public final static String type___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String type___dict___doc = + ""; + + public final static String type___dictoffset___doc = + "int(x[, base]) -> integer\n" + + "\n" + + "Convert a string or number to an integer, if possible. A floating point\n" + + "argument will be truncated towards zero (this does not include a string\n" + + "representation of a floating point number!) When converting a string, use\n" + + "the optional base. It is an error to supply a base when converting a\n" + + "non-string. If the argument is outside the integer range a long object\n" + + "will be returned instead."; + + public final static String type___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String type___flags___doc = + "int(x[, base]) -> integer\n" + + "\n" + + "Convert a string or number to an integer, if possible. A floating point\n" + + "argument will be truncated towards zero (this does not include a string\n" + + "representation of a floating point number!) When converting a string, use\n" + + "the optional base. It is an error to supply a base when converting a\n" + + "non-string. If the argument is outside the integer range a long object\n" + + "will be returned instead."; + + public final static String type___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String type___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String type___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String type___itemsize___doc = + "int(x[, base]) -> integer\n" + + "\n" + + "Convert a string or number to an integer, if possible. A floating point\n" + + "argument will be truncated towards zero (this does not include a string\n" + + "representation of a floating point number!) When converting a string, use\n" + + "the optional base. It is an error to supply a base when converting a\n" + + "non-string. If the argument is outside the integer range a long object\n" + + "will be returned instead."; + + public final static String type___module___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String type___mro___doc = + "tuple() -> an empty tuple\n" + + "tuple(sequence) -> tuple initialized from sequence's items\n" + + "\n" + + "If the argument is a tuple, the return value is the same object."; + + public final static String type___name___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String type___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String type___reduce___doc = + "helper for pickle"; + + public final static String type___reduce_ex___doc = + "helper for pickle"; + + public final static String type___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String type___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String type___str___doc = + "x.__str__() <==> str(x)"; + + public final static String type___subclasses___doc = + "__subclasses__() -> list of immediate subclasses"; + + public final static String type___weakrefoffset___doc = + "int(x[, base]) -> integer\n" + + "\n" + + "Convert a string or number to an integer, if possible. A floating point\n" + + "argument will be truncated towards zero (this does not include a string\n" + + "representation of a floating point number!) When converting a string, use\n" + + "the optional base. It is an error to supply a base when converting a\n" + + "non-string. If the argument is outside the integer range a long object\n" + + "will be returned instead."; + + public final static String type_mro_doc = + "mro() -> list\n" + + "return a type's method resolution order"; + + //Docs for <type 'unicode'> + public final static String unicode___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String unicode___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String unicode___contains___doc = + "x.__contains__(y) <==> y in x"; + + public final static String unicode___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String unicode___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String unicode___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String unicode___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String unicode___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String unicode___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String unicode___getnewargs___doc = + ""; + + public final static String unicode___getslice___doc = + "x.__getslice__(i, j) <==> x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String unicode___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String unicode___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String unicode___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String unicode___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String unicode___len___doc = + "x.__len__() <==> len(x)"; + + public final static String unicode___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String unicode___mod___doc = + "x.__mod__(y) <==> x%y"; + + public final static String unicode___mul___doc = + "x.__mul__(n) <==> x*n"; + + public final static String unicode___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String unicode___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String unicode___reduce___doc = + "helper for pickle"; + + public final static String unicode___reduce_ex___doc = + "helper for pickle"; + + public final static String unicode___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String unicode___rmod___doc = + "x.__rmod__(y) <==> y%x"; + + public final static String unicode___rmul___doc = + "x.__rmul__(n) <==> n*x"; + + public final static String unicode___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String unicode___str___doc = + "x.__str__() <==> str(x)"; + + public final static String unicode_capitalize_doc = + "S.capitalize() -> unicode\n" + + "\n" + + "Return a capitalized version of S, i.e. make the first character\n" + + "have upper case."; + + public final static String unicode_center_doc = + "S.center(width[, fillchar]) -> unicode\n" + + "\n" + + "Return S centered in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)"; + + public final static String unicode_count_doc = + "S.count(sub[, start[, end]]) -> int\n" + + "\n" + + "Return the number of non-overlapping occurrences of substring sub in\n" + + "Unicode string S[start:end]. Optional arguments start and end are\n" + + "interpreted as in slice notation."; + + public final static String unicode_decode_doc = + "S.decode([encoding[,errors]]) -> string or unicode\n" + + "\n" + + "Decodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n" + + "as well as any other name registerd with codecs.register_error that is\n" + + "able to handle UnicodeDecodeErrors."; + + public final static String unicode_encode_doc = + "S.encode([encoding[,errors]]) -> string or unicode\n" + + "\n" + + "Encodes S using the codec registered for encoding. encoding defaults\n" + + "to the default encoding. errors may be given to set a different error\n" + + "handling scheme. Default is 'strict' meaning that encoding errors raise\n" + + "a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n" + + "'xmlcharrefreplace' as well as any other name registered with\n" + + "codecs.register_error that can handle UnicodeEncodeErrors."; + + public final static String unicode_endswith_doc = + "S.endswith(suffix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S ends with the specified suffix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "suffix can also be a tuple of strings to try."; + + public final static String unicode_expandtabs_doc = + "S.expandtabs([tabsize]) -> unicode\n" + + "\n" + + "Return a copy of S where all tab characters are expanded using spaces.\n" + + "If tabsize is not given, a tab size of 8 characters is assumed."; + + public final static String unicode_find_doc = + "S.find(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the lowest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String unicode_index_doc = + "S.index(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.find() but raise ValueError when the substring is not found."; + + public final static String unicode_isalnum_doc = + "S.isalnum() -> bool\n" + + "\n" + + "Return True if all characters in S are alphanumeric\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_isalpha_doc = + "S.isalpha() -> bool\n" + + "\n" + + "Return True if all characters in S are alphabetic\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_isdecimal_doc = + "S.isdecimal() -> bool\n" + + "\n" + + "Return True if there are only decimal characters in S,\n" + + "False otherwise."; + + public final static String unicode_isdigit_doc = + "S.isdigit() -> bool\n" + + "\n" + + "Return True if all characters in S are digits\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_islower_doc = + "S.islower() -> bool\n" + + "\n" + + "Return True if all cased characters in S are lowercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String unicode_isnumeric_doc = + "S.isnumeric() -> bool\n" + + "\n" + + "Return True if there are only numeric characters in S,\n" + + "False otherwise."; + + public final static String unicode_isspace_doc = + "S.isspace() -> bool\n" + + "\n" + + "Return True if all characters in S are whitespace\n" + + "and there is at least one character in S, False otherwise."; + + public final static String unicode_istitle_doc = + "S.istitle() -> bool\n" + + "\n" + + "Return True if S is a titlecased string and there is at least one\n" + + "character in S, i.e. upper- and titlecase characters may only\n" + + "follow uncased characters and lowercase characters only cased ones.\n" + + "Return False otherwise."; + + public final static String unicode_isupper_doc = + "S.isupper() -> bool\n" + + "\n" + + "Return True if all cased characters in S are uppercase and there is\n" + + "at least one cased character in S, False otherwise."; + + public final static String unicode_join_doc = + "S.join(sequence) -> unicode\n" + + "\n" + + "Return a string which is the concatenation of the strings in the\n" + + "sequence. The separator between elements is S."; + + public final static String unicode_ljust_doc = + "S.ljust(width[, fillchar]) -> int\n" + + "\n" + + "Return S left justified in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)."; + + public final static String unicode_lower_doc = + "S.lower() -> unicode\n" + + "\n" + + "Return a copy of the string S converted to lowercase."; + + public final static String unicode_lstrip_doc = + "S.lstrip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with leading whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_partition_doc = + "S.partition(sep) -> (head, sep, tail)\n" + + "\n" + + "Searches for the separator sep in S, and returns the part before it,\n" + + "the separator itself, and the part after it. If the separator is not\n" + + "found, returns S and two empty strings."; + + public final static String unicode_replace_doc = + "S.replace (old, new[, maxsplit]) -> unicode\n" + + "\n" + + "Return a copy of S with all occurrences of substring\n" + + "old replaced by new. If the optional argument maxsplit is\n" + + "given, only the first maxsplit occurrences are replaced."; + + public final static String unicode_rfind_doc = + "S.rfind(sub [,start [,end]]) -> int\n" + + "\n" + + "Return the highest index in S where substring sub is found,\n" + + "such that sub is contained within s[start:end]. Optional\n" + + "arguments start and end are interpreted as in slice notation.\n" + + "\n" + + "Return -1 on failure."; + + public final static String unicode_rindex_doc = + "S.rindex(sub [,start [,end]]) -> int\n" + + "\n" + + "Like S.rfind() but raise ValueError when the substring is not found."; + + public final static String unicode_rjust_doc = + "S.rjust(width[, fillchar]) -> unicode\n" + + "\n" + + "Return S right justified in a Unicode string of length width. Padding is\n" + + "done using the specified fill character (default is a space)."; + + public final static String unicode_rpartition_doc = + "S.rpartition(sep) -> (tail, sep, head)\n" + + "\n" + + "Searches for the separator sep in S, starting at the end of S, and returns\n" + + "the part before it, the separator itself, and the part after it. If the\n" + + "separator is not found, returns two empty strings and S."; + + public final static String unicode_rsplit_doc = + "S.rsplit([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in S, using sep as the\n" + + "delimiter string, starting at the end of the string and\n" + + "working to the front. If maxsplit is given, at most maxsplit\n" + + "splits are done. If sep is not specified, any whitespace string\n" + + "is a separator."; + + public final static String unicode_rstrip_doc = + "S.rstrip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with trailing whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_split_doc = + "S.split([sep [,maxsplit]]) -> list of strings\n" + + "\n" + + "Return a list of the words in S, using sep as the\n" + + "delimiter string. If maxsplit is given, at most maxsplit\n" + + "splits are done. If sep is not specified or is None,\n" + + "any whitespace string is a separator."; + + public final static String unicode_splitlines_doc = + "S.splitlines([keepends]]) -> list of strings\n" + + "\n" + + "Return a list of the lines in S, breaking at line boundaries.\n" + + "Line breaks are not included in the resulting list unless keepends\n" + + "is given and true."; + + public final static String unicode_startswith_doc = + "S.startswith(prefix[, start[, end]]) -> bool\n" + + "\n" + + "Return True if S starts with the specified prefix, False otherwise.\n" + + "With optional start, test S beginning at that position.\n" + + "With optional end, stop comparing S at that position.\n" + + "prefix can also be a tuple of strings to try."; + + public final static String unicode_strip_doc = + "S.strip([chars]) -> unicode\n" + + "\n" + + "Return a copy of the string S with leading and trailing\n" + + "whitespace removed.\n" + + "If chars is given and not None, remove characters in chars instead.\n" + + "If chars is a str, it will be converted to unicode before stripping"; + + public final static String unicode_swapcase_doc = + "S.swapcase() -> unicode\n" + + "\n" + + "Return a copy of S with uppercase characters converted to lowercase\n" + + "and vice versa."; + + public final static String unicode_title_doc = + "S.title() -> unicode\n" + + "\n" + + "Return a titlecased version of S, i.e. words start with title case\n" + + "characters, all remaining cased characters have lower case."; + + public final static String unicode_translate_doc = + "S.translate(table) -> unicode\n" + + "\n" + + "Return a copy of the string S, where all characters have been mapped\n" + + "through the given translation table, which must be a mapping of\n" + + "Unicode ordinals to Unicode ordinals, Unicode strings or None.\n" + + "Unmapped characters are left untouched. Characters mapped to None\n" + + "are deleted."; + + public final static String unicode_upper_doc = + "S.upper() -> unicode\n" + + "\n" + + "Return a copy of S converted to uppercase."; + + public final static String unicode_zfill_doc = + "S.zfill(width) -> unicode\n" + + "\n" + + "Pad a numeric string x with zeros on the left, to fill a field\n" + + "of the specified width. The string x is never truncated."; + + //Docs for <type 'dict'> + public final static String dict___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String dict___cmp___doc = + "x.__cmp__(y) <==> cmp(x,y)"; + + public final static String dict___contains___doc = + "D.__contains__(k) -> True if D has a key k, else False"; + + public final static String dict___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String dict___delitem___doc = + "x.__delitem__(y) <==> del x[y]"; + + public final static String dict___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String dict___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String dict___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String dict___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String dict___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String dict___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String dict___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String dict___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String dict___iter___doc = + "x.__iter__() <==> iter(x)"; + + public final static String dict___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String dict___len___doc = + "x.__len__() <==> len(x)"; + + public final static String dict___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String dict___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String dict___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String dict___reduce___doc = + "helper for pickle"; + + public final static String dict___reduce_ex___doc = + "helper for pickle"; + + public final static String dict___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String dict___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String dict___setitem___doc = + "x.__setitem__(i, y) <==> x[i]=y"; + + public final static String dict___str___doc = + "x.__str__() <==> str(x)"; + + public final static String dict_clear_doc = + "D.clear() -> None. Remove all items from D."; + + public final static String dict_copy_doc = + "D.copy() -> a shallow copy of D"; + + public final static String dict_fromkeys_doc = + "dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n" + + "v defaults to None."; + + public final static String dict_get_doc = + "D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; + + public final static String dict_has_key_doc = + "D.has_key(k) -> True if D has a key k, else False"; + + public final static String dict_items_doc = + "D.items() -> list of D's (key, value) pairs, as 2-tuples"; + + public final static String dict_iteritems_doc = + "D.iteritems() -> an iterator over the (key, value) items of D"; + + public final static String dict_iterkeys_doc = + "D.iterkeys() -> an iterator over the keys of D"; + + public final static String dict_itervalues_doc = + "D.itervalues() -> an iterator over the values of D"; + + public final static String dict_keys_doc = + "D.keys() -> list of D's keys"; + + public final static String dict_pop_doc = + "D.pop(k[,d]) -> v, remove specified key and return the corresponding value\n" + + "If key is not found, d is returned if given, otherwise KeyError is raised"; + + public final static String dict_popitem_doc = + "D.popitem() -> (k, v), remove and return some (key, value) pair as a\n" + + "2-tuple; but raise KeyError if D is empty"; + + public final static String dict_setdefault_doc = + "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"; + + public final static String dict_update_doc = + "D.update(E, **F) -> None. Update D from E and F: for k in E: D[k] = E[k]\n" + + "(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]"; + + public final static String dict_values_doc = + "D.values() -> list of D's values"; + + //Docs for <type 'list'> + public final static String list___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String list___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String list___contains___doc = + "x.__contains__(y) <==> y in x"; + + public final static String list___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String list___delitem___doc = + "x.__delitem__(y) <==> del x[y]"; + + public final static String list___delslice___doc = + "x.__delslice__(i, j) <==> del x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String list___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String list___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String list___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String list___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String list___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String list___getslice___doc = + "x.__getslice__(i, j) <==> x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String list___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String list___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String list___iadd___doc = + "x.__iadd__(y) <==> x+=y"; + + public final static String list___imul___doc = + "x.__imul__(y) <==> x*=y"; + + public final static String list___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String list___iter___doc = + "x.__iter__() <==> iter(x)"; + + public final static String list___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String list___len___doc = + "x.__len__() <==> len(x)"; + + public final static String list___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String list___mul___doc = + "x.__mul__(n) <==> x*n"; + + public final static String list___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String list___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String list___reduce___doc = + "helper for pickle"; + + public final static String list___reduce_ex___doc = + "helper for pickle"; + + public final static String list___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String list___reversed___doc = + "L.__reversed__() -- return a reverse iterator over the list"; + + public final static String list___rmul___doc = + "x.__rmul__(n) <==> n*x"; + + public final static String list___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String list___setitem___doc = + "x.__setitem__(i, y) <==> x[i]=y"; + + public final static String list___setslice___doc = + "x.__setslice__(i, j, y) <==> x[i:j]=y\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String list___str___doc = + "x.__str__() <==> str(x)"; + + public final static String list_append_doc = + "L.append(object) -- append object to end"; + + public final static String list_count_doc = + "L.count(value) -> integer -- return number of occurrences of value"; + + public final static String list_extend_doc = + "L.extend(iterable) -- extend list by appending elements from the iterable"; + + public final static String list_index_doc = + "L.index(value, [start, [stop]]) -> integer -- return first index of value"; + + public final static String list_insert_doc = + "L.insert(index, object) -- insert object before index"; + + public final static String list_pop_doc = + "L.pop([index]) -> item -- remove and return item at index (default last)"; + + public final static String list_remove_doc = + "L.remove(value) -- remove first occurrence of value"; + + public final static String list_reverse_doc = + "L.reverse() -- reverse *IN PLACE*"; + + public final static String list_sort_doc = + "L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;\n" + + "cmp(x, y) -> -1, 0, 1"; + + //Docs for <type 'slice'> + public final static String slice___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String slice___cmp___doc = + "x.__cmp__(y) <==> cmp(x,y)"; + + public final static String slice___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String slice___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String slice___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String slice___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String slice___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String slice___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String slice___reduce___doc = + "helper for pickle"; + + public final static String slice___reduce_ex___doc = + "helper for pickle"; + + public final static String slice___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String slice___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String slice___str___doc = + "x.__str__() <==> str(x)"; + + public final static String slice_indices_doc = + "S.indices(len) -> (start, stop, stride)\n" + + "\n" + + "Assuming a sequence of length len, calculate the start and stop\n" + + "indices, and the stride length of the extended slice described by\n" + + "S. Out of bounds indices are clipped in a manner consistent with the\n" + + "handling of normal slices."; + + public final static String slice_start_doc = + ""; + + public final static String slice_step_doc = + ""; + + public final static String slice_stop_doc = + ""; + + //Docs for <type 'super'> + public final static String super___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String super___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String super___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String super___get___doc = + "descr.__get__(obj[, type]) -> value"; + + public final static String super___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String super___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String super___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String super___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String super___reduce___doc = + "helper for pickle"; + + public final static String super___reduce_ex___doc = + "helper for pickle"; + + public final static String super___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String super___self___doc = + "the instance invoking super(); may be None"; + + public final static String super___self_class___doc = + "the type of the instance invoking super(); may be None"; + + public final static String super___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String super___str___doc = + "x.__str__() <==> str(x)"; + + public final static String super___thisclass___doc = + "the class invoking super()"; + + //Docs for <type 'staticmethod'> + public final static String staticmethod___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String staticmethod___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String staticmethod___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String staticmethod___get___doc = + "descr.__get__(obj[, type]) -> value"; + + public final static String staticmethod___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String staticmethod___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String staticmethod___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String staticmethod___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String staticmethod___reduce___doc = + "helper for pickle"; + + public final static String staticmethod___reduce_ex___doc = + "helper for pickle"; + + public final static String staticmethod___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String staticmethod___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String staticmethod___str___doc = + "x.__str__() <==> str(x)"; + + //Docs for <type 'float'> + public final static String float___abs___doc = + "x.__abs__() <==> abs(x)"; + + public final static String float___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String float___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String float___coerce___doc = + "x.__coerce__(y) <==> coerce(x, y)"; + + public final static String float___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String float___div___doc = + "x.__div__(y) <==> x/y"; + + public final static String float___divmod___doc = + "x.__divmod__(y) <==> divmod(x, y)"; + + public final static String float___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String float___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String float___float___doc = + "x.__float__() <==> float(x)"; + + public final static String float___floordiv___doc = + "x.__floordiv__(y) <==> x//y"; + + public final static String float___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String float___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String float___getformat___doc = + "float.__getformat__(typestr) -> string\n" + + "\n" + + "You probably don't want to use this function. It exists mainly to be\n" + + "used in Python's test suite.\n" + + "\n" + + "typestr must be 'double' or 'float'. This function returns whichever of\n" + + "'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the\n" + + "format of floating point numbers used by the C type named by typestr."; + + public final static String float___getnewargs___doc = + ""; + + public final static String float___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String float___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String float___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String float___int___doc = + "x.__int__() <==> int(x)"; + + public final static String float___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String float___long___doc = + "x.__long__() <==> long(x)"; + + public final static String float___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String float___mod___doc = + "x.__mod__(y) <==> x%y"; + + public final static String float___mul___doc = + "x.__mul__(y) <==> x*y"; + + public final static String float___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String float___neg___doc = + "x.__neg__() <==> -x"; + + public final static String float___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String float___nonzero___doc = + "x.__nonzero__() <==> x != 0"; + + public final static String float___pos___doc = + "x.__pos__() <==> +x"; + + public final static String float___pow___doc = + "x.__pow__(y[, z]) <==> pow(x, y[, z])"; + + public final static String float___radd___doc = + "x.__radd__(y) <==> y+x"; + + public final static String float___rdiv___doc = + "x.__rdiv__(y) <==> y/x"; + + public final static String float___rdivmod___doc = + "x.__rdivmod__(y) <==> divmod(y, x)"; + + public final static String float___reduce___doc = + "helper for pickle"; + + public final static String float___reduce_ex___doc = + "helper for pickle"; + + public final static String float___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String float___rfloordiv___doc = + "x.__rfloordiv__(y) <==> y//x"; + + public final static String float___rmod___doc = + "x.__rmod__(y) <==> y%x"; + + public final static String float___rmul___doc = + "x.__rmul__(y) <==> y*x"; + + public final static String float___rpow___doc = + "y.__rpow__(x[, z]) <==> pow(x, y[, z])"; + + public final static String float___rsub___doc = + "x.__rsub__(y) <==> y-x"; + + public final static String float___rtruediv___doc = + "x.__rtruediv__(y) <==> y/x"; + + public final static String float___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String float___setformat___doc = + "float.__setformat__(typestr, fmt) -> None\n" + + "\n" + + "You probably don't want to use this function. It exists mainly to be\n" + + "used in Python's test suite.\n" + + "\n" + + "typestr must be 'double' or 'float'. fmt must be one of 'unknown',\n" + + "'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be\n" + + "one of the latter two if it appears to match the underlying C reality.\n" + + "\n" + + "Overrides the automatic determination of C-level floating point type.\n" + + "This affects how floats are converted to and from binary strings."; + + public final static String float___str___doc = + "x.__str__() <==> str(x)"; + + public final static String float___sub___doc = + "x.__sub__(y) <==> x-y"; + + public final static String float___truediv___doc = + "x.__truediv__(y) <==> x/y"; + + //Docs for <type 'enumerate'> + public final static String enumerate___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String enumerate___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String enumerate___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String enumerate___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String enumerate___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String enumerate___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String enumerate___iter___doc = + "x.__iter__() <==> iter(x)"; + + public final static String enumerate___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String enumerate___reduce___doc = + "helper for pickle"; + + public final static String enumerate___reduce_ex___doc = + "helper for pickle"; + + public final static String enumerate___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String enumerate___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String enumerate___str___doc = + "x.__str__() <==> str(x)"; + + public final static String enumerate_next_doc = + "x.next() -> the next value, or raise StopIteration"; + + //Docs for <type 'basestring'> + public final static String basestring___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String basestring___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String basestring___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String basestring___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String basestring___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String basestring___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String basestring___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String basestring___reduce___doc = + "helper for pickle"; + + public final static String basestring___reduce_ex___doc = + "helper for pickle"; + + public final static String basestring___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String basestring___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String basestring___str___doc = + "x.__str__() <==> str(x)"; + + //Docs for <type 'long'> + public final static String long___abs___doc = + "x.__abs__() <==> abs(x)"; + + public final static String long___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String long___and___doc = + "x.__and__(y) <==> x&y"; + + public final static String long___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String long___cmp___doc = + "x.__cmp__(y) <==> cmp(x,y)"; + + public final static String long___coerce___doc = + "x.__coerce__(y) <==> coerce(x, y)"; + + public final static String long___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String long___div___doc = + "x.__div__(y) <==> x/y"; + + public final static String long___divmod___doc = + "x.__divmod__(y) <==> divmod(x, y)"; + + public final static String long___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String long___float___doc = + "x.__float__() <==> float(x)"; + + public final static String long___floordiv___doc = + "x.__floordiv__(y) <==> x//y"; + + public final static String long___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String long___getnewargs___doc = + ""; + + public final static String long___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String long___hex___doc = + "x.__hex__() <==> hex(x)"; + + public final static String long___index___doc = + "x[y:z] <==> x[y.__index__():z.__index__()]"; + + public final static String long___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String long___int___doc = + "x.__int__() <==> int(x)"; + + public final static String long___invert___doc = + "x.__invert__() <==> ~x"; + + public final static String long___long___doc = + "x.__long__() <==> long(x)"; + + public final static String long___lshift___doc = + "x.__lshift__(y) <==> x<<y"; + + public final static String long___mod___doc = + "x.__mod__(y) <==> x%y"; + + public final static String long___mul___doc = + "x.__mul__(y) <==> x*y"; + + public final static String long___neg___doc = + "x.__neg__() <==> -x"; + + public final static String long___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String long___nonzero___doc = + "x.__nonzero__() <==> x != 0"; + + public final static String long___oct___doc = + "x.__oct__() <==> oct(x)"; + + public final static String long___or___doc = + "x.__or__(y) <==> x|y"; + + public final static String long___pos___doc = + "x.__pos__() <==> +x"; + + public final static String long___pow___doc = + "x.__pow__(y[, z]) <==> pow(x, y[, z])"; + + public final static String long___radd___doc = + "x.__radd__(y) <==> y+x"; + + public final static String long___rand___doc = + "x.__rand__(y) <==> y&x"; + + public final static String long___rdiv___doc = + "x.__rdiv__(y) <==> y/x"; + + public final static String long___rdivmod___doc = + "x.__rdivmod__(y) <==> divmod(y, x)"; + + public final static String long___reduce___doc = + "helper for pickle"; + + public final static String long___reduce_ex___doc = + "helper for pickle"; + + public final static String long___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String long___rfloordiv___doc = + "x.__rfloordiv__(y) <==> y//x"; + + public final static String long___rlshift___doc = + "x.__rlshift__(y) <==> y<<x"; + + public final static String long___rmod___doc = + "x.__rmod__(y) <==> y%x"; + + public final static String long___rmul___doc = + "x.__rmul__(y) <==> y*x"; + + public final static String long___ror___doc = + "x.__ror__(y) <==> y|x"; + + public final static String long___rpow___doc = + "y.__rpow__(x[, z]) <==> pow(x, y[, z])"; + + public final static String long___rrshift___doc = + "x.__rrshift__(y) <==> y>>x"; + + public final static String long___rshift___doc = + "x.__rshift__(y) <==> x>>y"; + + public final static String long___rsub___doc = + "x.__rsub__(y) <==> y-x"; + + public final static String long___rtruediv___doc = + "x.__rtruediv__(y) <==> y/x"; + + public final static String long___rxor___doc = + "x.__rxor__(y) <==> y^x"; + + public final static String long___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String long___str___doc = + "x.__str__() <==> str(x)"; + + public final static String long___sub___doc = + "x.__sub__(y) <==> x-y"; + + public final static String long___truediv___doc = + "x.__truediv__(y) <==> x/y"; + + public final static String long___xor___doc = + "x.__xor__(y) <==> x^y"; + + //Docs for <type 'tuple'> + public final static String tuple___add___doc = + "x.__add__(y) <==> x+y"; + + public final static String tuple___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String tuple___contains___doc = + "x.__contains__(y) <==> y in x"; + + public final static String tuple___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String tuple___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String tuple___eq___doc = + "x.__eq__(y) <==> x==y"; + + public final static String tuple___ge___doc = + "x.__ge__(y) <==> x>=y"; + + public final static String tuple___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String tuple___getitem___doc = + "x.__getitem__(y) <==> x[y]"; + + public final static String tuple___getnewargs___doc = + ""; + + public final static String tuple___getslice___doc = + "x.__getslice__(i, j) <==> x[i:j]\n" + + " \n" + + " Use of negative indices is not supported."; + + public final static String tuple___gt___doc = + "x.__gt__(y) <==> x>y"; + + public final static String tuple___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String tuple___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String tuple___iter___doc = + "x.__iter__() <==> iter(x)"; + + public final static String tuple___le___doc = + "x.__le__(y) <==> x<=y"; + + public final static String tuple___len___doc = + "x.__len__() <==> len(x)"; + + public final static String tuple___lt___doc = + "x.__lt__(y) <==> x<y"; + + public final static String tuple___mul___doc = + "x.__mul__(n) <==> x*n"; + + public final static String tuple___ne___doc = + "x.__ne__(y) <==> x!=y"; + + public final static String tuple___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String tuple___reduce___doc = + "helper for pickle"; + + public final static String tuple___reduce_ex___doc = + "helper for pickle"; + + public final static String tuple___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String tuple___rmul___doc = + "x.__rmul__(n) <==> n*x"; + + public final static String tuple___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String tuple___str___doc = + "x.__str__() <==> str(x)"; + //Docs for <type 'str'> public final static String str___add___doc = "x.__add__(y) <==> x+y"; @@ -349,362 +1813,1135 @@ "Pad a numeric string S with zeros on the left, to fill a field\n" + "of the specified width. The string S is never truncated."; - //Docs for <type 'unicode'> - public final static String unicode___add___doc = + //Docs for <type 'property'> + public final static String property___class___doc = + "type(object) -> the object's type\n" + + "type(name, bases, dict) -> a new type"; + + public final static String property___delattr___doc = + "x.__delattr__('name') <==> del x.name"; + + public final static String property___delete___doc = + "descr.__delete__(obj)"; + + public final static String property___doc___doc = + "str(object) -> string\n" + + "\n" + + "Return a nice string representation of the object.\n" + + "If the argument is a string, the return value is the same object."; + + public final static String property___get___doc = + "descr.__get__(obj[, type]) -> value"; + + public final static String property___getattribute___doc = + "x.__getattribute__('name') <==> x.name"; + + public final static String property___hash___doc = + "x.__hash__() <==> hash(x)"; + + public final static String property___init___doc = + "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"; + + public final static String property___new___doc = + "T.__new__(S, ...) -> a new object with type S, a subtype of T"; + + public final static String property___reduce___doc = + "helper for pickle"; + + public final static String property___reduce_ex___doc = + "helper for pickle"; + + public final static String property___repr___doc = + "x.__repr__() <==> repr(x)"; + + public final static String property___set___doc = + "descr.__set__(obj, value)"; + + public final static String property___setattr___doc = + "x.__setattr__('name', value) <==> x.name = value"; + + public final static String property___str___doc = + "x.__str__() <==> str(x)"; + + public final static String property_fdel_doc = + ""; + + public final static String property_fget_doc = + ""; + + public final static String property_fset_doc = + ""; + + //Docs for <type 'int'> + public final static String int___abs___doc = + "x.__abs__() <==> abs(x)"; + + public final static String int___add___doc = "x.__add__(y) <==> x+y"; - public final static String unicode___class___doc = + public final static String int___and___doc = + "x.__and__(y) <==> x&y"; + + public final static String int___class___doc = "type(object) -> the object's type\n"... [truncated message content] |
From: <cg...@us...> - 2008-12-25 00:49:37
|
Revision: 5799 http://jython.svn.sourceforge.net/jython/?rev=5799&view=rev Author: cgroves Date: 2008-12-25 00:49:33 +0000 (Thu, 25 Dec 2008) Log Message: ----------- test_091 - moved to test_java_visibility.py test_092 - deleted; not testing anything test_093 - deleted; check of a jythonc hack test_094 - deleted; tested by test_import_jy test_100 - deleted; tested by test_userdict test_101 - deleted; tested by test_jser2 test_104 - moved to test_java_integration.py test_114 - deleted; testing importing Tkinter from someone's i:\ drive test_116 - moved to test_java_integration.py Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py Added Paths: ----------- trunk/jython/tests/java/org/python/tests/Coercions.java Removed Paths: ------------- trunk/jython/bugtests/test091.py trunk/jython/bugtests/test091j.java trunk/jython/bugtests/test092.py trunk/jython/bugtests/test093.py trunk/jython/bugtests/test094.py trunk/jython/bugtests/test100.py trunk/jython/bugtests/test100j.java trunk/jython/bugtests/test101.py trunk/jython/bugtests/test104.py trunk/jython/bugtests/test114.py trunk/jython/bugtests/test116.py Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -5,11 +5,13 @@ from test import test_support from java.awt import (Dimension, Component, Rectangle, Button, Color, - HeadlessException) + HeadlessException) from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte +from java.lang import (Boolean, Integer, Object, String, Runnable, + Thread, ThreadGroup, System, Runtime, Math, Byte) +from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath from java.math import BigDecimal @@ -150,22 +152,22 @@ v.indexOf(X()) class IOTest(unittest.TestCase): - def test_io_errors(self): "Check that IOException isn't mangled into an IOError" from java.io import UnsupportedEncodingException - self.assertRaises(UnsupportedEncodingException, OutputStreamWriter, - System.out, "garbage") - + self.assertRaises(UnsupportedEncodingException, OutputStreamWriter, System.out, "garbage") + self.assertRaises(IOError, OutputStreamWriter, System.out, "garbage") + def test_fileio_error(self): from java.io import FileInputStream, FileNotFoundException self.assertRaises(FileNotFoundException, FileInputStream, "garbage") - def test_unsupported(self): + def test_unsupported_tell(self): from org.python.core.util import FileUtil fp = FileUtil.wrap(System.out) self.assertRaises(IOError, fp.tell) + class VectorTest(unittest.TestCase): def test_looping(self): @@ -354,7 +356,34 @@ treePath = TreePath([1,2,3]) self.assertEquals(len(treePath.path), 3, "Object[] not passed correctly") self.assertEquals(TreePath(treePath.path).path, treePath.path, "Object[] not passed and returned correctly") - + +class TableModelTest(unittest.TestCase): + def test_column_classes(self): + class TableModel(AbstractTableModel): + columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" + data = [("Mary", "Campione", "Snowboarding", 5, False)] + + def getColumnCount(self): + return len(self.columnNames) + + def getRowCount(self): + return len(self.data) + + def getColumnName(self, col): + return self.columnNames[col] + + def getValueAt(self, row, col): + return self.data[row][col] + + def getColumnClass(self, c): + return Object.getClass(self.getValueAt(0, c)) + + def isCellEditable(self, row, col): + return col >= 2 + model = TableModel() + for i, expectedClass in enumerate([String, String, String, Integer, Boolean]): + self.assertEquals(expectedClass, model.getColumnClass(i)) + class BigDecimalTest(unittest.TestCase): def test_coerced_bigdecimal(self): @@ -460,6 +489,7 @@ PyReservedNamesTest, ImportTest, ColorTest, + TableModelTest, TreePathTest, BigDecimalTest, MethodInvTest, Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -91,9 +91,18 @@ 'java.lang.Class bean methods should be visible on instances') self.assertEquals(3, len(HashMap.getInterfaces())) +class NumberCoercionTest(unittest.TestCase): + def test_int_coercion(self): + from org.python.tests import Coercions + c = Coercions() + self.assertEquals("5", c.takeInt(5)) + self.assertEquals("15", c.takeInteger(15)) + self.assertEquals("150", c.takeNumber(150)) + def test_main(): test_support.run_unittest(VisibilityTest, - JavaClassTest) + JavaClassTest, + NumberCoercionTest) if __name__ == "__main__": test_main() Deleted: trunk/jython/bugtests/test091.py =================================================================== --- trunk/jython/bugtests/test091.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test091.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,18 +0,0 @@ -""" -Coercion of Integer and Number. -""" - -import support - -support.compileJava("test091j.java") - -import test091j - -r = test091j.takeInt(12) -support.compare(r, "takeInt") - -r = test091j.takeInteger(12) -support.compare(r, "takeInteger") - -r = test091j.takeNumber(12) -support.compare(r, "takeNumber") Deleted: trunk/jython/bugtests/test091j.java =================================================================== --- trunk/jython/bugtests/test091j.java 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test091j.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,11 +0,0 @@ -public class test091j { - public static String takeInt(int num) { - return "takeInt"; - } - public static String takeInteger(Integer num) { - return "takeInteger"; - } - public static String takeNumber(Number num) { - return "takeNumber"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test092.py =================================================================== --- trunk/jython/bugtests/test092.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test092.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,64 +0,0 @@ -""" -Check reload a java package (not a java class) (properly shouldn't work). -""" - -import support - -j1file = """ -package test092m; -public class test092j1 { - final static String j1_Version = "j1 Version %s"; - public String getJ1Version() { - return j1_Version; - } -} -""" - -j2file = """ -package test092m; -public class test092j2 extends test092j1 { - final static String j2_Version = "j2 Version %s"; - public String getJ2Version() { - return j2_Version; - } -} -""" - -def mkj1(v): - f = open("classes/test092m/test092j1.java", "w") - f.write(j1file % v) - f.close() - support.compileJava("classes/test092m/test092j1.java") - -def mkj2(v): - f = open("classes/test092m/test092j2.java", "w") - f.write(j2file % v); - f.close(); - support.compileJava("classes/test092m/test092j2.java") - -import sys - -mkj1("1") -mkj2("2") - -import test092m - -foo = test092m.test092j2() - -support.compare(foo.j1Version, "j1 Version 1") -support.compare(foo.j2Version, "j2 Version 2") - -mkj1("3") -mkj2("4") - -# -# Removed. Reloading java packages is not supposed to work -# -#reload(test092m) -# -#foo = test092m.test092j2() -#support.compare(foo.j1Version, "j1 Version 3") -#support.compare(foo.j2Version, "j2 Version 4") - - - Deleted: trunk/jython/bugtests/test093.py =================================================================== --- trunk/jython/bugtests/test093.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test093.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Check name of the pawt.swing package. -""" - -import support - -from pawt import swing - - -support.compare(swing, "java package") -support.compare(swing.__name__, "javax.swing") -support.compare(swing.__jpythonc_name__, "pawt.swing") -#support.compare(swing.__file__, r"Lib\\pawt\\swing.py") - Deleted: trunk/jython/bugtests/test094.py =================================================================== --- trunk/jython/bugtests/test094.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test094.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,13 +0,0 @@ -""" -Check simple __import__ call with 4 args. -""" - -import support - -mod = __import__("pawt", globals(), locals(), "swing") - -import pawt - -if pawt != mod: - raise support.TestError("__import__ returned wrong module") - Deleted: trunk/jython/bugtests/test100.py =================================================================== --- trunk/jython/bugtests/test100.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test100.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Iterate over the "keys" sequence. -""" - -import support - -support.compileJava("test100j.java") - -import test100j - -r = test100j().iterate({'a':'1', 'b':'2', 3:'c'}) - -if len(r) != 6: - raise support.TestError("len should be 6, %d" % len(r)) Deleted: trunk/jython/bugtests/test100j.java =================================================================== --- trunk/jython/bugtests/test100j.java 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test100j.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,16 +0,0 @@ - -import java.util.*; -import org.python.core.*; - -public class test100j { - public Vector iterate(PyObject dict) { - Vector v = new Vector(); - PyObject keys = dict.invoke("keys"); - PyObject key; - for (int i = 0; (key = keys.__finditem__(i)) != null; i++) { - v.addElement(key); - v.addElement(dict.__getitem__(key)); - } - return v; - } -} Deleted: trunk/jython/bugtests/test101.py =================================================================== --- trunk/jython/bugtests/test101.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test101.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,41 +0,0 @@ -""" -Serialization test. -#unitcheck -""" - -import support - - -class Data: - data = "Hello World" - -class Test: - text = Data() - -class Factory: - def createTest(x): - return Test() - -factory = Factory() -foo = factory.createTest() - - -from java import io -import sys - -filename = "test101.out" - -fout = io.ObjectOutputStream(io.FileOutputStream(filename)) -fout.writeObject(foo) -fout.close() - -fin = io.ObjectInputStream(io.FileInputStream(filename)) -foo = fin.readObject() -fin.close() - - -support.compare(foo, "<(__main__|test101).Test instance") -support.compare(foo.text, "<(__main__|test101).Data instance") -support.compare(foo.text.data, "Hello World") - - Deleted: trunk/jython/bugtests/test104.py =================================================================== --- trunk/jython/bugtests/test104.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test104.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,38 +0,0 @@ -""" - -""" - -import support - - -import java -from pawt import swing, test - -class TableModel0(swing.table.AbstractTableModel): - columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" - data = [("Mary", "Campione", "Snowboarding", 5, java.lang.Boolean(0))] - - def getColumnCount(self): - return len(self.columnNames) - - def getRowCount(self): - return len(self.data) - - def getColumnName(self, col): - return self.columnNames[col] - - def getValueAt(self, row, col): - return self.data[row][col] - - def getColumnClass(self, c): - return java.lang.Class.getClass(self.getValueAt(0, c)) - - def isCellEditable(self, row, col): - return col >= 2 - -model0 = TableModel0() -support.compare(model0.getColumnClass(0), "java.lang.String") -support.compare(model0.getColumnClass(1), "java.lang.String") -support.compare(model0.getColumnClass(2), "java.lang.String") -support.compare(model0.getColumnClass(3), "java.lang.Integer") -support.compare(model0.getColumnClass(4), "java.lang.Boolean") Deleted: trunk/jython/bugtests/test114.py =================================================================== --- trunk/jython/bugtests/test114.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test114.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Check sane error when importing TKinter. -""" - -import support - - -import sys -sys.path.append(r"i:\Python-1.5.2\Lib\lib-tk") - -try: - from Tkinter import * -except ImportError, e: - support.compare(e, "_tkinter|Tkinter") Deleted: trunk/jython/bugtests/test116.py =================================================================== --- trunk/jython/bugtests/test116.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test116.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,23 +0,0 @@ -""" -Check that UEE also matches IOError. -""" - -import support - - -import java - -try: - x = java.io.OutputStreamWriter(java.lang.System.out, "garbage") -except java.io.UnsupportedEncodingException, e: - pass -else: - raise support.TestError("Should raise an exception") - - -try: - x = java.io.OutputStreamWriter(java.lang.System.out, "garbage") -except IOError, e: - pass -else: - raise support.TestError("Should raise an exception") Added: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -0,0 +1,16 @@ +package org.python.tests; + +public class Coercions { + + public String takeInt(int i) { + return "" + i; + } + + public String takeInteger(Integer i) { + return "" + i; + } + + public String takeNumber(Number n) { + return "" + n; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-25 15:30:22
|
Revision: 5800 http://jython.svn.sourceforge.net/jython/?rev=5800&view=rev Author: cgroves Date: 2008-12-25 15:30:20 +0000 (Thu, 25 Dec 2008) Log Message: ----------- test_117,119,120 - Tested by test_jser2 test_121 - Moved to test_java_visibility test_122 - Testing java package reloading that never worked test_123 - Moved to org.python.util.InterpreterTest test_129 - Tested by test_array_jy Modified Paths: -------------- trunk/jython/Lib/test/test_array_jy.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/tests/java/org/python/tests/Invisible.java trunk/jython/tests/java/org/python/tests/SubVisible.java trunk/jython/tests/java/org/python/util/InterpreterTest.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/OnlySubclassable.java Removed Paths: ------------- trunk/jython/bugtests/classes/test092m/ trunk/jython/bugtests/classes/test119j.java trunk/jython/bugtests/classes/test121p/ trunk/jython/bugtests/test117.py trunk/jython/bugtests/test117j.java trunk/jython/bugtests/test119.py trunk/jython/bugtests/test120.py trunk/jython/bugtests/test121.py trunk/jython/bugtests/test122.py trunk/jython/bugtests/test122p/ trunk/jython/bugtests/test123.py trunk/jython/bugtests/test123j.java trunk/jython/bugtests/test125m.py trunk/jython/bugtests/test129.py trunk/jython/bugtests/test129j.java Modified: trunk/jython/Lib/test/test_array_jy.py =================================================================== --- trunk/jython/Lib/test/test_array_jy.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/Lib/test/test_array_jy.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -28,20 +28,20 @@ (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) - import java # require for eval to work + import java.lang.String # require for eval to work self.assertEqual(jStringArr, eval(str(jStringArr))) def test_java_compat(self): - from java import awt - hsb = awt.Color.RGBtoHSB(0,255,255, None) + from java.awt import Color + hsb = Color.RGBtoHSB(0,255,255, None) self.assertEqual(hsb, array('f', [0.5,1,1]), "output hsb float array does not correspond to input rgb values") - rgb = apply(awt.Color.HSBtoRGB, tuple(hsb)) + rgb = apply(Color.HSBtoRGB, tuple(hsb)) self.assertEqual(rgb, -0xff0001, "output rgb bytes don't match input hsb floats") hsb1 = zeros('f', 3) - awt.Color.RGBtoHSB(0,255,255, hsb1) + Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") def test_main(): Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +1,8 @@ import unittest from test import test_support from java.util import HashMap -from org.python.tests import InterfaceCombination, Invisible, SubVisible, Visible, VisibleOverride +from org.python.tests import (InterfaceCombination, Invisible, OnlySubclassable, SubVisible, + Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -10,6 +11,8 @@ self.assert_(not item.startswith("package")) self.assert_(not item.startswith("private")) self.assert_(not item.startswith("protected")) + self.assertRaises(TypeError, Invisible, + "Calling a Java class with package protected constructors should raise a TypeError") def test_protected_from_python_subclass(self): class SubVisible(Visible): @@ -24,7 +27,17 @@ self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) + self.assertRaises(TypeError, OnlySubclassable, + "Calling a Java class with protected constructors should raise a TypeError") + class SubSubclassable(OnlySubclassable): + pass + sub = SubSubclassable() + self.assert_(not sub.filledInByConstructor == 0, + '''Creating SubSubclassable should call OnlySubclassable's constructor to fill in + filledInByConstructor''') + + def test_visible(self): v = Visible() self.assertEquals(Results.PUBLIC_FIELD, v.visibleField) Deleted: trunk/jython/bugtests/classes/test119j.java =================================================================== --- trunk/jython/bugtests/classes/test119j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/classes/test119j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,5 +0,0 @@ - - -public class test119j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/test117.py =================================================================== --- trunk/jython/bugtests/test117.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test117.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,41 +0,0 @@ -""" -Check serialization of PyJavaInstance subclasses. (from Lib). -#unitcheck -""" - -import support - -support.compileJava("test117j.java") - -import java, org -pi = java.io.PipedInputStream() -po = java.io.PipedOutputStream(pi) -oo = java.io.ObjectOutputStream(po) -oi = org.python.util.PythonObjectInputStream(pi) - -import test117j - -class B: - b = 2 - -class C(test117j): - c = 3 - -foo = test117j() -oo.writeObject(foo) -bar = oi.readObject() -#print type(foo), type(bar) -#print foo.__class__, bar.__class__ -if bar.a != 1: - raise support.TestError("Restored attrib should be 1") - -oo.writeObject(B()) -x = oi.readObject() -if x.b != 2: - raise support.TestError("Restored attrib should be 2") - -oo.writeObject(C()) -x = oi.readObject() -if x.c != 3: - raise support.TestError("Restored attrib should be 3") - Deleted: trunk/jython/bugtests/test117j.java =================================================================== --- trunk/jython/bugtests/test117j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test117j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,6 +0,0 @@ - -import java.io.*; - -public class test117j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/test119.py =================================================================== --- trunk/jython/bugtests/test119.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test119.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,35 +0,0 @@ -""" -Check serialization of PyJavaInstance subclasses. (from classpath). -#unitcheck -""" - -import support - -support.compileJava("classes/test119j.java") - -import java, org -pi = java.io.PipedInputStream() -po = java.io.PipedOutputStream(pi) -oo = java.io.ObjectOutputStream(po) -oi = org.python.util.PythonObjectInputStream(pi) - -import test119j - -class B: - b = 2 - -class C(test119j): - c = 3 - -oo.writeObject(test119j()) -if oi.readObject().a != 1: - raise support.TestError("Deser of java class failed") - - -oo.writeObject(B()) -if oi.readObject().b != 2: - raise support.TestError("Deser of python class failed") - -oo.writeObject(C()) -if oi.readObject().c != 3: - raise support.TestError("Deser of java subclass class failed") Deleted: trunk/jython/bugtests/test120.py =================================================================== --- trunk/jython/bugtests/test120.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test120.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,20 +0,0 @@ -""" -Check serialization of java subclasses. -#unitcheck -""" - -import support - -import java, org - -class V(java.util.Vector): - foo = 1 - -#print java.io.ObjectStreamClass.lookup(V); - -oo = java.io.ObjectOutputStream(java.io.FileOutputStream("test120.out")) -oo.writeObject(V()) - -oi = org.python.util.PythonObjectInputStream(java.io.FileInputStream("test120.out")) -o = oi.readObject() -#print o Deleted: trunk/jython/bugtests/test121.py =================================================================== --- trunk/jython/bugtests/test121.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test121.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,16 +0,0 @@ -""" -Check nonpublic constructor. -""" - -import support - -support.compileJava("classes/test121p/test121j.java") - -from test121p import test121j - -try: - test121j() -except TypeError, e: - support.compare(e, "no public constructor") -else: - raise support.TestError("Should fail (access)") Deleted: trunk/jython/bugtests/test122.py =================================================================== --- trunk/jython/bugtests/test122.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test122.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,33 +0,0 @@ -""" -Should reloading a python module cause java classes to be reloaded? -""" - -import support -src= """ -package test122p; -public class test122j { - public String version = "%s"; -} -""" - -def mk(v): - f = open("test122p/test122j.java", "w") - f.write(src % v) - f.close() - support.compileJava("test122p/test122j.java") - -mk(1) - -import test122p -bar1 = test122p.test122j() -if bar1.version != "1": - raise support.TestError("Wrong version#1 %s" % bar1.version) - -# -# Test removed. Reloading java packages are not supposed to work. -# -#mk(2) -#reload(test122p) -#bar2 = test122p.test122j() -#if bar2.version != "2": -# raise support.TestError("Wrong version#2 %s" % bar2.version) Deleted: trunk/jython/bugtests/test123.py =================================================================== --- trunk/jython/bugtests/test123.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test123.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,14 +0,0 @@ - -""" - -""" - -import support - -support.compileJava("test123j.java") - -import test123j - -test123j.main(None) - - Deleted: trunk/jython/bugtests/test123j.java =================================================================== --- trunk/jython/bugtests/test123j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test123j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,24 +0,0 @@ - -import org.python.util.PythonInterpreter; -import org.python.core.*; - -public class test123j { - public static void main(String args[]) { - for(int i=0; i<10; i++) { - PyThread p1 = new PyThread(); - Thread t1 = new Thread(p1); - t1.start(); - } - } - - public static class PyThread implements Runnable { - public void run() { - PythonInterpreter interp = new PythonInterpreter(); - interp.exec("import sys"); - interp.set("a", new PyInteger(41)); - //interp.exec("print a"); - interp.exec("x = 2+2"); - PyObject x = interp.get("x"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test125m.py =================================================================== --- trunk/jython/bugtests/test125m.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test125m.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,3 +0,0 @@ - -def fun2(): - return 2 Deleted: trunk/jython/bugtests/test129.py =================================================================== --- trunk/jython/bugtests/test129.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test129.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,18 +0,0 @@ -""" - -""" - -import support -import java, jarray - -support.compileJava("test129j.java") - -arr = jarray.zeros(10, java.lang.Class.forName('[I')) -for x in range(10): arr[x] = jarray.zeros(10, 'i') - -import test129j - -test129j.chk(arr) - -if arr[0][0] != 47: - raise support.TestError("Array[0][0] should be 47: %d" % arr[0][0]) Deleted: trunk/jython/bugtests/test129j.java =================================================================== --- trunk/jython/bugtests/test129j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test129j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +0,0 @@ - -public class test129j { - public static int chk(int[][] arr) { - arr[0][0] = 47; - return arr.length * arr[0].length; - } -} \ No newline at end of file Modified: trunk/jython/tests/java/org/python/tests/Invisible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Invisible.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/tests/Invisible.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -18,6 +18,8 @@ int packageField = PACKAGE_FIELD; + Invisible() {} + private static int privateStaticMethod() { return 7; } Added: trunk/jython/tests/java/org/python/tests/OnlySubclassable.java =================================================================== --- trunk/jython/tests/java/org/python/tests/OnlySubclassable.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/OnlySubclassable.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -0,0 +1,10 @@ +package org.python.tests; + +public class OnlySubclassable { + + public int filledInByConstructor; + + protected OnlySubclassable() { + filledInByConstructor = 1; + } +} Modified: trunk/jython/tests/java/org/python/tests/SubVisible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/SubVisible.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/tests/SubVisible.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +1,6 @@ package org.python.tests; public class SubVisible extends Visible implements VisibleOverride { - /** * Overrides {@link Visible#visibleStatic(int)} */ Modified: trunk/jython/tests/java/org/python/util/InterpreterTest.java =================================================================== --- trunk/jython/tests/java/org/python/util/InterpreterTest.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/util/InterpreterTest.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,8 +1,11 @@ package org.python.util; +import java.util.concurrent.CountDownLatch; import junit.framework.TestCase; +import org.python.core.Py; import org.python.core.PyDictionary; +import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyUnicode; @@ -19,4 +22,28 @@ PyObject pyo = interp.eval("{u'one': u'two'}"); assertEquals(test, pyo); } + + public void testMultipleThreads() { + final CountDownLatch doneSignal = new CountDownLatch(10); + for (int i = 0; i < 10; i++) { + new Thread() { + @Override + public void run() { + PythonInterpreter interp = new PythonInterpreter(); + interp.exec("import sys"); + interp.set("a", new PyInteger(41)); + int set = Py.tojava(interp.get("a"), Integer.class); + assertEquals(41, set); + interp.exec("x = 'hello ' + 'goodbye'"); + assertEquals("hello goodbye", Py.tojava(interp.get("x"), String.class)); + doneSignal.countDown(); + } + }.start(); + } + try { + doneSignal.await(); + } catch (InterruptedException e) { + System.err.println("Interpreters in multiple threads test interrupted, bailing"); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-28 17:39:07
|
Revision: 5801 http://jython.svn.sourceforge.net/jython/?rev=5801&view=rev Author: cgroves Date: 2008-12-28 17:39:01 +0000 (Sun, 28 Dec 2008) Log Message: ----------- test132 - Moved to org.python.util. test137 - Tested by test_array_jy test145 - Tested by test_java_integration test146 - Tested by test_java_integration test147 - Tested by test_builtin test148 - Tested by test_str test149 - Moved to test_int_jy test150 - Moved to test_java_visibility test151 - Not sure what it was testing; deleted test152 - Tested by regrtest with the tokenize option test153 - Tested by test_java_integration test154 - Not sure what it was testing; deleted test155 - Subclassing Java Python Types as that class from Python is no longer supported; deleted test156 - Tested by test_jser2 test157 - Moved to test_java_visibility test158 - Tested by test_userdict test159 - Tested by test_exceptions test160 - Seems to be testing Java static calling; deleted test161 - Moved to test_java_visibility test162 - Moved Jython specific test to test_class_jy test163 - Module tests handled by test_class_jy; Java test moved to test_java_visibility test164,test165 - Tested by test_str test166 - Tested by test_exceptions test167 - Moved to test_thread_jy test168 - Tested by test_import test169 - Testing jythonc; deleted test170,test171 - Tested by test_cpickle test172 - Moved to test_java_visibility test173 - Tested by test_builtins test174 - Tested by test_classes test175,test176 - Tested by test_list test177 - Tested by test_userdict test178 - Moved to test_grammar_jy test179 - Tested by test_compiler test180 - Tested by test_builtin test181 - Moved to test_grammar_jy test182 - Testing jythonc; deleted test183 - Tested by test_re test184-199 - Testing jythonc; deleted test200 - Tested by test_java_integration test201 - Testing jythonc; deleted test202,203 - Tested by test_jser2 test204,205 - Moved to test_java_visibility test206 - Tested by test_java_integration Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/Lib/test/test_grammar_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_thread_jy.py trunk/jython/tests/java/org/python/tests/Coercions.java trunk/jython/tests/java/org/python/tests/SubVisible.java trunk/jython/tests/java/org/python/tests/VisibilityResults.java trunk/jython/tests/java/org/python/tests/Visible.java trunk/jython/tests/java/org/python/util/InterpreterTest.java Added Paths: ----------- trunk/jython/Lib/test/test_int_jy.py Removed Paths: ------------- trunk/jython/bugtests/classes/test139j1.java trunk/jython/bugtests/classes/test139j2.java trunk/jython/bugtests/classes/test139j3.java trunk/jython/bugtests/classes/test142j.java trunk/jython/bugtests/classes/test160j1.java trunk/jython/bugtests/classes/test160j2.java trunk/jython/bugtests/classes/test182j.java trunk/jython/bugtests/classes/test202j.java trunk/jython/bugtests/classes/test204j0.java trunk/jython/bugtests/classes/test204j1.java trunk/jython/bugtests/classes/test204j2.java trunk/jython/bugtests/classes/test204j3.java trunk/jython/bugtests/classes/test205j0.java trunk/jython/bugtests/classes/test205j1.java trunk/jython/bugtests/classes/test205j2.java trunk/jython/bugtests/classes/test206j0.java trunk/jython/bugtests/classes/test206j1.java trunk/jython/bugtests/test132.py trunk/jython/bugtests/test132j.java trunk/jython/bugtests/test132m.py trunk/jython/bugtests/test137.py trunk/jython/bugtests/test137j.java trunk/jython/bugtests/test145.py trunk/jython/bugtests/test146.py trunk/jython/bugtests/test147.py trunk/jython/bugtests/test148.py trunk/jython/bugtests/test149.py trunk/jython/bugtests/test150.py trunk/jython/bugtests/test151.py trunk/jython/bugtests/test152.py trunk/jython/bugtests/test153.py trunk/jython/bugtests/test154.py trunk/jython/bugtests/test154p/ trunk/jython/bugtests/test155.py trunk/jython/bugtests/test156.py trunk/jython/bugtests/test157.py trunk/jython/bugtests/test157j.java trunk/jython/bugtests/test158.py trunk/jython/bugtests/test159.py trunk/jython/bugtests/test160.py trunk/jython/bugtests/test161.py trunk/jython/bugtests/test162.py trunk/jython/bugtests/test162m.py trunk/jython/bugtests/test163.py trunk/jython/bugtests/test164.py trunk/jython/bugtests/test165.py trunk/jython/bugtests/test166.py trunk/jython/bugtests/test167.py trunk/jython/bugtests/test168.py trunk/jython/bugtests/test168p/ trunk/jython/bugtests/test169.py trunk/jython/bugtests/test169c.py trunk/jython/bugtests/test170.py trunk/jython/bugtests/test170p/ trunk/jython/bugtests/test171.py trunk/jython/bugtests/test171p/ trunk/jython/bugtests/test172.py trunk/jython/bugtests/test172j.java trunk/jython/bugtests/test173.py trunk/jython/bugtests/test173p/ trunk/jython/bugtests/test174.py trunk/jython/bugtests/test175.py trunk/jython/bugtests/test176.py trunk/jython/bugtests/test177.py trunk/jython/bugtests/test178.py trunk/jython/bugtests/test179.py trunk/jython/bugtests/test180.py trunk/jython/bugtests/test181.py trunk/jython/bugtests/test182.py trunk/jython/bugtests/test182c.py trunk/jython/bugtests/test183.py trunk/jython/bugtests/test184.py trunk/jython/bugtests/test184s1.py trunk/jython/bugtests/test184s2.py trunk/jython/bugtests/test185.html trunk/jython/bugtests/test185.py trunk/jython/bugtests/test185a.py trunk/jython/bugtests/test185m.py trunk/jython/bugtests/test186.html trunk/jython/bugtests/test186.py trunk/jython/bugtests/test186a.py trunk/jython/bugtests/test187.py trunk/jython/bugtests/test187c.py trunk/jython/bugtests/test188.py trunk/jython/bugtests/test188c.py trunk/jython/bugtests/test189.py trunk/jython/bugtests/test189c.py trunk/jython/bugtests/test190.py trunk/jython/bugtests/test190c.py trunk/jython/bugtests/test191.py trunk/jython/bugtests/test191c.py trunk/jython/bugtests/test192.html trunk/jython/bugtests/test192.py trunk/jython/bugtests/test192c.py trunk/jython/bugtests/test192c1.py trunk/jython/bugtests/test192c2.py trunk/jython/bugtests/test193.py trunk/jython/bugtests/test193c.py trunk/jython/bugtests/test194.html trunk/jython/bugtests/test194.py trunk/jython/bugtests/test194c.py trunk/jython/bugtests/test194m/ trunk/jython/bugtests/test195.py trunk/jython/bugtests/test195c.py trunk/jython/bugtests/test196.py trunk/jython/bugtests/test196c.py trunk/jython/bugtests/test197.py trunk/jython/bugtests/test197c.py trunk/jython/bugtests/test198.py trunk/jython/bugtests/test198c.py trunk/jython/bugtests/test199.py trunk/jython/bugtests/test199c.py trunk/jython/bugtests/test200.py trunk/jython/bugtests/test200p1.py trunk/jython/bugtests/test201.py trunk/jython/bugtests/test201c.py trunk/jython/bugtests/test202.py trunk/jython/bugtests/test203.py trunk/jython/bugtests/test204.py trunk/jython/bugtests/test205.py trunk/jython/bugtests/test206.py Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_class_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -6,6 +6,7 @@ import __builtin__ import new import unittest +from java.lang import Object from test import test_support class ClassGeneralTestCase(unittest.TestCase): @@ -24,11 +25,14 @@ class Bar(object): pass - self.assertEqual(Bar.__module__, __name__) - self.assertEqual(str(Bar), "<class '%s.Bar'>" % __name__) - self.assertEqual(repr(Bar), "<class '%s.Bar'>" % __name__) - bar = Bar() - self.assert_(str(bar).startswith('<%s.Bar object at' % __name__)) + class Baz(Object): + pass + for cls in Bar, Baz: + 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__)) + self.assert_(str(Bar()).startswith('<%s.Bar object at' % __name__)) + self.assert_(str(Baz()).startswith("org.python.proxies.%s$Baz" % __name__)) def test_builtin_attributes(self): Modified: trunk/jython/Lib/test/test_grammar_jy.py =================================================================== --- trunk/jython/Lib/test/test_grammar_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_grammar_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -5,7 +5,19 @@ import unittest class GrammarTest(unittest.TestCase): + def test_triple_quote_len(self): + s1 = r""" + \""" 1.triple-quote + \""" 2.triple-quote + """ + s2 = r''' + \""" 1.triple-quote + \""" 2.triple-quote + ''' + self.assert_(not '\r' in s1) + self.assertEquals(len(s1), len(s2)) + def testStringPrefixes(self): self.assertEquals(u"spam",U"spam") self.assertEquals(r"spam", R"spam") Added: trunk/jython/Lib/test/test_int_jy.py =================================================================== --- trunk/jython/Lib/test/test_int_jy.py (rev 0) +++ trunk/jython/Lib/test/test_int_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -0,0 +1,18 @@ +"""Int tests + +Additional tests for Jython. +""" +import unittest +import types +from test import test_support + +class IntTestCase(unittest.TestCase): + + def test_type_matches(self): + self.assert_(isinstance(1, types.IntType)) + +def test_main(): + test_support.run_unittest(IntTestCase) + +if __name__ == '__main__': + test_main() Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -4,8 +4,7 @@ import re from test import test_support -from java.awt import (Dimension, Component, Rectangle, Button, Color, - HeadlessException) +from java.awt import Dimension, Color, Component, Rectangle from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter @@ -95,7 +94,6 @@ class ExtendJavaTest(unittest.TestCase): def test_override_tostring(self): - from java.lang import Object, String class A(Object): def toString(self): return 'name' @@ -109,8 +107,6 @@ except TypeError: pass - - class SysIntegrationTest(unittest.TestCase): def test_stdout_outputstream(self): out = FileOutputStream(test_support.TESTFN) @@ -124,7 +120,6 @@ sys.stdout = out class AutoSuperTest(unittest.TestCase): - def test_auto_super(self): class R(Rectangle): def __init__(self): @@ -142,7 +137,6 @@ self.assertRaises(TypeError, Math) class PyObjectCmpTest(unittest.TestCase): - def test_vect_cmp(self): "Check comparing a PyJavaClass with a Object." class X(Runnable): @@ -169,7 +163,6 @@ class VectorTest(unittest.TestCase): - def test_looping(self): for i in Vector(): pass @@ -432,12 +425,10 @@ self.fail("Shouldn't be callable with a no args") self.assertRaises(TypeError, Callbacker.callNoArg, PyBadCallback()) - class JavaStringTest(unittest.TestCase): def test_string_not_iterable(self): - from java import lang - x = lang.String('test') + x = String('test') self.assertRaises(TypeError, list, x) class JavaDelegationTest(unittest.TestCase): Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +1,10 @@ +import array import unittest from test import test_support -from java.util import HashMap -from org.python.tests import (InterfaceCombination, Invisible, OnlySubclassable, SubVisible, - Visible, VisibleOverride) +from java.lang import Class +from java.util import HashMap, Observable, Observer +from org.python.tests import (Coercions, InterfaceCombination, Invisible, OnlySubclassable, + SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -21,14 +23,17 @@ Visible.__init__(self, publicValue) else: Visible.__init__(self) + class SubSubVisible(SubVisible): + pass # TODO - protectedStaticMethod, protectedStaticField, StaticInner, and protectedField should # be here - s = SubVisible() - self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) - self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) - self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) - self.assertRaises(TypeError, OnlySubclassable, - "Calling a Java class with protected constructors should raise a TypeError") + for cls in SubVisible, SubSubVisible: + s = cls() + self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) + self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) + self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) + self.assertRaises(TypeError, OnlySubclassable, + "Calling a Java class with protected constructors should raise a TypeError") class SubSubclassable(OnlySubclassable): pass sub = SubSubclassable() @@ -36,7 +41,26 @@ '''Creating SubSubclassable should call OnlySubclassable's constructor to fill in filledInByConstructor''') + # Check that the protected setChanged method on Observable is visible and propogates + # properly from a python subclass + class TestObservable(Observable): + def __init__(self): + self.props = {} + def set(self, key, val): + self.props[key] = val + self.setChanged() + self.notifyObservers() + to = TestObservable() + self.updated = False + class TestObserver(Observer): + def update(observerself, observable, arg): + self.assertEquals(to, observable) + self.assertEquals(None, arg) + self.updated = True + to.addObserver(TestObserver()) + to.set('k', 'v') + self.assert_(self.updated, "Calling set should notify the added observer") def test_visible(self): v = Visible() @@ -74,6 +98,11 @@ # return the subclass value here. self.assertEquals(Results.SUBCLASS_OVERRIDE, Visible.visibleInstance(s, 3)) self.assertEquals(Results.PUBLIC_STATIC_FIELD, SubVisible.StaticInner.visibleStaticField) + + self.assertEquals(Results.VISIBLE_SHARED_NAME_FIELD, Visible.sharedNameField) + self.assertEquals(Results.SUBVISIBLE_SHARED_NAME_FIELD, SubVisible.sharedNameField) + self.assertEquals(Results.VISIBLE_SHARED_NAME_FIELD * 10, Visible().sharedNameField) + self.assertEquals(Results.SUBVISIBLE_SHARED_NAME_FIELD * 10, s.sharedNameField) def test_in_dict(self): @@ -104,14 +133,25 @@ 'java.lang.Class bean methods should be visible on instances') self.assertEquals(3, len(HashMap.getInterfaces())) + def test_python_fields(self): + self.assertEquals('java.util', HashMap.__module__) + self.assertEquals(Class, HashMap.__class__) + self.assertEquals(None, HashMap.__doc__) + class NumberCoercionTest(unittest.TestCase): def test_int_coercion(self): - from org.python.tests import Coercions c = Coercions() self.assertEquals("5", c.takeInt(5)) self.assertEquals("15", c.takeInteger(15)) self.assertEquals("150", c.takeNumber(150)) + def test_array_coercion(self): + self.assertEquals("double", Coercions.takeArray(array.zeros('d', 2))) + self.assertEquals("float", Coercions.takeArray(array.zeros('f', 2))) + self.assertEquals("4", Coercions.takePyObj(1, 2, 3, 4)) + c = Coercions() + self.assertEquals("5", c.takePyObjInst(1, 2, 3, 4, 5)) + def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, Modified: trunk/jython/Lib/test/test_thread_jy.py =================================================================== --- trunk/jython/Lib/test/test_thread_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_thread_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +1,9 @@ import thread +import synchronize import unittest import test.test_support +from java.lang import Thread +from java.util.concurrent import CountDownLatch class AllocateLockTest(unittest.TestCase): @@ -10,8 +13,23 @@ self.assertEquals(t, type(thread.allocate_lock()), "thread.LockType has wrong value") +class SynchronizeTest(unittest.TestCase): + def test_make_synchronized(self): + self.doneSignal = CountDownLatch(10) + self.i = 0 + class SynchedRun(Thread): + def run(synchself): + self.i = self.i + 1 + self.doneSignal.countDown() + run = synchronize.make_synchronized(run) + for _ in xrange(10): + SynchedRun().start() + self.doneSignal.await() + self.assertEquals(10, self.i) + + def test_main(): - test.test_support.run_unittest(AllocateLockTest) + test.test_support.run_unittest(AllocateLockTest, SynchronizeTest) if __name__ == "__main__": test_main() Deleted: trunk/jython/bugtests/classes/test139j1.java =================================================================== --- trunk/jython/bugtests/classes/test139j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public class test139j1 { - public void foo() {} -} Deleted: trunk/jython/bugtests/classes/test139j2.java =================================================================== --- trunk/jython/bugtests/classes/test139j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test139j2 { - public void bar(); -} Deleted: trunk/jython/bugtests/classes/test139j3.java =================================================================== --- trunk/jython/bugtests/classes/test139j3.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j3.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -public class test139j3 { - public static boolean baz(test139j1 o) { - return o instanceof test139j2; - } -} Deleted: trunk/jython/bugtests/classes/test142j.java =================================================================== --- trunk/jython/bugtests/classes/test142j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test142j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,27 +0,0 @@ - -import org.python.core.*; - -public class test142j extends PyObject { - double[] data; - int len; - public test142j(double[] darray) { - data=darray; - len=data.length; - } - public int __len__() { - return len; - } - - public PyString __repr__() { - StringBuffer buf = new StringBuffer(); - for(int i=0; i<len; i++) { - buf.append(data[i]); - buf.append(", "); - } - return new PyString(buf.toString()); - } - - public static test142j new$(double[] array) { - return new test142j(array); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test160j1.java =================================================================== --- trunk/jython/bugtests/classes/test160j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test160j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,18 +0,0 @@ - -public class test160j1 { - public static test160j1 clField; - - public void go() { - clField = this; - test160j2 b = new test160j2(); - } - - public String func() { - return "success!"; - } - - public static void main( String[] arg ) { - test160j1 a = new test160j1(); - a.go(); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test160j2.java =================================================================== --- trunk/jython/bugtests/classes/test160j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test160j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -public class test160j2 { - public test160j2() { - test160j1.clField.func(); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test182j.java =================================================================== --- trunk/jython/bugtests/classes/test182j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test182j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,46 +0,0 @@ - -public abstract class test182j { - public String tstPublic() { - return "tstPublic"; - } - - protected String tstProtected() { - return "tstProtected"; - } - - final protected String tstFinalProtected() { - return "tstFinalProtected"; - } - - final public String tstFinalPublic() { - return "tstFinalPublic"; - } - - - - public String tstOverridePublic() { - return "tstOverridePublic"; - } - - protected String tstOverrideProtected() { - return "tstOverrideProtected"; - } - - final protected String tstOverrideFinalProtected() { - return "tstOverrideFinalProtected"; - } - - final public String tstOverrideFinalPublic() { - return "tstOverrideFinalPublic"; - } - - - abstract public String tstAbstractPublic(); - - abstract protected String tstAbstractProtected(); - - abstract public String tstOverrideAbstractPublic(); - - abstract protected String tstOverrideAbstractProtected(); - -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test202j.java =================================================================== --- trunk/jython/bugtests/classes/test202j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test202j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,5 +0,0 @@ - - -public class test202j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j0.java =================================================================== --- trunk/jython/bugtests/classes/test204j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test204j0 { - public long getClassID(); -} Deleted: trunk/jython/bugtests/classes/test204j1.java =================================================================== --- trunk/jython/bugtests/classes/test204j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j1 implements test204j0 { - public static final long classID = 2041; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j2.java =================================================================== --- trunk/jython/bugtests/classes/test204j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j2 extends test204j1 { - public static final long classID = 2042; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j3.java =================================================================== --- trunk/jython/bugtests/classes/test204j3.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j3.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j3 extends test204j1 { - public static final long classID = 2043; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test205j0.java =================================================================== --- trunk/jython/bugtests/classes/test205j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test205j0 { - public long getClassID(); -} Deleted: trunk/jython/bugtests/classes/test205j1.java =================================================================== --- trunk/jython/bugtests/classes/test205j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ - -public class test205j1 implements test205j0 { - public static final long classID = 2051; - - public long getClassID() { - return classID*10; - } - -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test205j2.java =================================================================== --- trunk/jython/bugtests/classes/test205j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test205j2 extends test205j1 { - public static final long classID = 2052; - - public long getClassID() { - return classID*10; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test206j0.java =================================================================== --- trunk/jython/bugtests/classes/test206j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test206j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -interface test206j0 { - public int getInt(); -} Deleted: trunk/jython/bugtests/classes/test206j1.java =================================================================== --- trunk/jython/bugtests/classes/test206j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test206j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ - -public class test206j1 implements test206j0 { - public int getInt() { - return 3; - } - public int getInt2() { - return 4; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test132.py =================================================================== --- trunk/jython/bugtests/test132.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test132j.java") - -import test132j -test132j.main(None) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test132j.java =================================================================== --- trunk/jython/bugtests/test132j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -import org.python.core.*; -import org.python.util.PythonInterpreter; - -public class test132j { - public static void main(String[] args) { - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile("test132m.py"); - PyObject FooClass = interp.get("Foo"); - PyObject fooInstance = FooClass.__call__(new PyInteger(42)); - for (int i=0; i<4; i++) { - fooInstance.invoke("execute"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test132m.py =================================================================== --- trunk/jython/bugtests/test132m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -class Foo: - def __init__(self, x): - self.x = x - - def execute(self): - return self.x \ No newline at end of file Deleted: trunk/jython/bugtests/test137.py =================================================================== --- trunk/jython/bugtests/test137.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test137.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test137j.java") - -import jarray -a = jarray.array(range(5), 'i') - -import test137j - - -test137j.zeroOutArray(a) -if a[-1] != 0: - raise support.TestError("All elements should be 0") Deleted: trunk/jython/bugtests/test137j.java =================================================================== --- trunk/jython/bugtests/test137j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test137j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test137j { - public static void zeroOutArray(int [] array){ - for(int i=0; i < array.length; i++){ - array[i] = 0; - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test145.py =================================================================== --- trunk/jython/bugtests/test145.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test145.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" -Check autocreate of proxy. -""" - -import support - -import java - -class myPanel(java.awt.Panel) : - def __init__(self) : - self.layout = java.awt.GridLayout(1,2) - -p = myPanel() -if p.layout != p.getLayout(): - raise support.TestError("Should be same") Deleted: trunk/jython/bugtests/test146.py =================================================================== --- trunk/jython/bugtests/test146.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test146.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,16 +0,0 @@ -""" - -""" - -import support - -from javax.swing import * -class TestAction(AbstractAction): - def __init__(self, verb): - AbstractAction.__init__(self, verb) - def actionPerformed(self, evt): - print str(self.getValue(Action.NAME)) + " performed by " + str(self) - -m = TestAction("Crash") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test147.py =================================================================== --- trunk/jython/bugtests/test147.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test147.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -if 'abc' is 'a'+'b'+'c': - raise support.TestError("Test1") -if not intern('abc') is intern('a'+'b'+'c'): - raise support.TestError("Test2") - Deleted: trunk/jython/bugtests/test148.py =================================================================== --- trunk/jython/bugtests/test148.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test148.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -import string -support.compare(string.replace("Synnove Finden Meierier ASA", "AS", "B"), "Synnove Finden Meierier BA") - Deleted: trunk/jython/bugtests/test149.py =================================================================== --- trunk/jython/bugtests/test149.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test149.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -from types import * -if not isinstance(1, IntType): - raise support.TestError("Test") Deleted: trunk/jython/bugtests/test150.py =================================================================== --- trunk/jython/bugtests/test150.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test150.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,27 +0,0 @@ -""" -setChanged was not found. -""" - -import support - -from java.util import Observable -class TestProperties( Observable ): - def __init__( self ): - self.props = { - 'logFileDir' : "./", - 'logFileName' : "testLog.txt", - 'maxFailures' : 1, - } - - def get( self, name ): - return self.props[ name ] - - def set( self, name, value ): - self.props[ name ] = value - self.notifyObservers() - self.setChanged() - -t = TestProperties() -t.set("k", "v") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test151.py =================================================================== --- trunk/jython/bugtests/test151.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test151.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -class Test: - def method1( self ): - __local = "buttercup" - __local - - -Test().method1() - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test152.py =================================================================== --- trunk/jython/bugtests/test152.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test152.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,24 +0,0 @@ -""" - -""" - -import support - -import tokenize - -f = open("test152.out", "w") -f.write("for i in range(1,10):") -f.close() - -f = open("test152.out") - -s = "" -def gettoken(type, token, (srow, scol), (erow, ecol), line): # for testing - global s - s = s + " " + token - -r = tokenize.tokenize(f.readline, gettoken) - -support.compare(s, "for") - -#raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test153.py =================================================================== --- trunk/jython/bugtests/test153.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test153.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -from java.util import Hashtable -class Test(Hashtable): - def isEmpty(self): - return Hashtable.isEmpty(self) - -t = Test() -if not t.isEmpty(): - raise support.TestError("Should be empty") Deleted: trunk/jython/bugtests/test154.py =================================================================== --- trunk/jython/bugtests/test154.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test154.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -import test154p -from test154p.testing import testing - -reload(test154p.testing) -reload(test154p.testing) -reload(test154p.testing) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test155.py =================================================================== --- trunk/jython/bugtests/test155.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test155.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ -""" - -""" - -import support - -#raise support.TestError("Test removed, it destroyes the test environment") - - -from org.python.core import PyList -class Test2(PyList): - def foo(self): - return self[0] - -y = Test2() -y.append('spam') -v = y.foo() - -if v != "spam": - raise support.TestError("Should return 'spam' : " + `v`) Deleted: trunk/jython/bugtests/test156.py =================================================================== --- trunk/jython/bugtests/test156.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test156.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,36 +0,0 @@ -""" -#unitcheck -""" - -import support - -import sys, org -from java import io -from java.awt import Panel - -class MyPanel (Panel): - pass - -def serialize_object (obj, filename): - #print "serializing", obj, "to", filename - file = io.FileOutputStream (filename) - objstream = io.ObjectOutputStream (file) - objstream.writeObject (obj) - objstream.close() ; file.close() - #print "done" - -def unserialize_object (filename): - #print "reading serialized object from", filename - file = io.FileInputStream (filename) - objstream = org.python.util.PythonObjectInputStream (file) - obj = objstream.readObject () - objstream.close() ; file.close() - #print "unserialized", obj - -filename = 'test156.ser' - -p = MyPanel () -serialize_object (p, filename) -unserialize_object (filename) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test157.py =================================================================== --- trunk/jython/bugtests/test157.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test157.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,22 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test157j.java") - -import test157j - -from jarray import * -f = zeros(2,'d'); -support.compare(test157j.test(f), "double"); -if f[0] == 0: - raise support.TestError("array not changed") - - -f = zeros(2,'f'); -support.compare(test157j.test(f), "float"); -if f[0] == 0: - raise support.TestError("array not changed") - Deleted: trunk/jython/bugtests/test157j.java =================================================================== --- trunk/jython/bugtests/test157j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test157j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -public class test157j { - public static String test(double[] arr) { - arr[0]=100; - return "double"; - } - public static String test(float[] arr) { - arr[0]=100; - return "float"; - } -} Deleted: trunk/jython/bugtests/test158.py =================================================================== --- trunk/jython/bugtests/test158.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test158.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -alfa = {} -alfa["test"] = "test1" -try: - del alfa["beta"] -except KeyError, e: - pass -else: - raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test159.py =================================================================== --- trunk/jython/bugtests/test159.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test159.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -try: - raise RuntimeError -except RuntimeError: - pass -else: - raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test160.py =================================================================== --- trunk/jython/bugtests/test160.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test160.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test160j1.java") - -import test160j1 -a = test160j1() -a.go() - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test161.py =================================================================== --- trunk/jython/bugtests/test161.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test161.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -from javax import swing -class a(swing.JPanel): - pass - -class b(a): - pass - - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test162.py =================================================================== --- trunk/jython/bugtests/test162.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test162.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -import test162m -support.compare(test162m.ParentlessClass.__module__, "test162m") -support.compare(test162m.DerivedPyClass.__module__, "test162m") -support.compare(test162m.DerivedJClass.__module__, "test162m") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test162m.py =================================================================== --- trunk/jython/bugtests/test162m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test162m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -import java, java.lang - -class ParentlessClass: - pass - -class DerivedPyClass(ParentlessClass): - pass - -class DerivedJClass(java.lang.Object): - pass \ No newline at end of file Deleted: trunk/jython/bugtests/test163.py =================================================================== --- trunk/jython/bugtests/test163.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test163.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,28 +0,0 @@ -""" - -""" - -import support - -from java.lang import Object - -class A: - pass - -class B(A): - pass - -class C(Object): - pass - -class D: - pass - -support.compare(A.__module__, "__main__|test163") -support.compare(B.__module__, "__main__|test163") -support.compare(C.__module__, "__main__|test163") -support.compare(D.__module__, "__main__|test163") -if hasattr(Object, "__module__"): - raise support.TestError("a java object should not have a __module__") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test164.py =================================================================== --- trunk/jython/bugtests/test164.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test164.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -import string -support.compare(string.replace ("2. .. 3.", ". .", " ."), "2 \.\. 3\.") - - Deleted: trunk/jython/bugtests/test165.py =================================================================== --- trunk/jython/bugtests/test165.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test165.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compare("%g" % 1, "1") -support.compare("%g .. %g" % (1,2), "1 .. 2") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test166.py =================================================================== --- trunk/jython/bugtests/test166.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test166.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" - -""" - -import support - -try: - raise KeyError, "abc" -except KeyError, value: - support.compare(value, "abc") - support.compare(value.__class__, "exceptions.KeyError") - - Deleted: trunk/jython/bugtests/test167.py =================================================================== --- trunk/jython/bugtests/test167.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test167.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - - -from java import lang -import synchronize - -class test167(lang.Thread): - def run(self): pass - run = synchronize.make_synchronized(run) - -test167().start() \ No newline at end of file Deleted: trunk/jython/bugtests/test168.py =================================================================== --- trunk/jython/bugtests/test168.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test168.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -import test168p - -import support - -support.compare(test168p.foo(), "foo") -support.compare(test168p.bar.bar(), "bar") Deleted: trunk/jython/bugtests/test169.py =================================================================== --- trunk/jython/bugtests/test169.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test169.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test169c.py", core=1, jar="test169c.jar", output="test169.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test169c.py =================================================================== --- trunk/jython/bugtests/test169c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test169c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -#import urllib - -a = None -if string.split('abc'): - a = "abc" - -if a: - import base64 - -import base64 \ No newline at end of file Deleted: trunk/jython/bugtests/test170.py =================================================================== --- trunk/jython/bugtests/test170.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test170.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,24 +0,0 @@ -""" - -""" - -import support - -import cPickle, cStringIO - -#print cPickle.__version__ - -import test170p.Stack - -s = test170p.Stack.Stack() - -#print s - -cs = cStringIO.StringIO() - -cPickle.dump(s, cs) -#print cs.getvalue() -cs.seek(0) -cPickle.load(cs) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test171.py =================================================================== --- trunk/jython/bugtests/test171.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test171.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -import cPickle - -import test171p.Stack - -s = test171p.Stack.Stack() - -cPickle.dumps(s) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test172.py =================================================================== --- trunk/jython/bugtests/test172.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test172.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - - -import support - -support.compileJava("test172j.java") - -import test172j - -support.compare(test172j.foo(1,2,3,4), "foo called with 4 arguments") - -support.compare(test172j().bar(1,2,3,4), "bar called with 4 arguments") Deleted: trunk/jython/bugtests/test172j.java =================================================================== --- trunk/jython/bugtests/test172j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test172j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ - -import org.python.core.*; - -public class test172j { - public static String foo(PyObject[] args) { - return "foo called with " + args.length + " arguments"; - } - - public String bar(PyObject[] args) { - return "bar called with " + args.length + " arguments"; - } -} Deleted: trunk/jython/bugtests/test173.py =================================================================== --- trunk/jython/bugtests/test173.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test173.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -import support - - -import test173p -support.compare(test173p, "sys") \ No newline at end of file Deleted: trunk/jython/bugtests/test174.py =================================================================== --- trunk/jython/bugtests/test174.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test174.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,21 +0,0 @@ - -import support - -class A: - def foo(self): - return "A.foo" - -class B: - def foo(self): - return "B.foo" - -class C(A, B): - pass - - -list(C.__bases__).reverse() - - -c = C() -#print c.foo -support.compare(c.foo(), "A.foo") Deleted: trunk/jython/bugtests/test175.py =================================================================== --- trunk/jython/bugtests/test175.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test175.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -import support - -t = (1,2,3) -list(t).reverse() -support.compare(t, "1, 2, 3") Deleted: trunk/jython/bugtests/test176.py =================================================================== --- trunk/jython/bugtests/test176.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test176.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" -Check that a list based on a tuple can not change the tuple -""" - -import support - -t1 = (1,2,3) -t2 = (1,2,3) -list(t1).reverse() - -if t1 != t2: - raise support.TestError('tuple was modified.') - Deleted: trunk/jython/bugtests/test177.py =================================================================== --- trunk/jython/bugtests/test177.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test177.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" -Check that two equal, but diffrently sorted dict compare equal. -""" - -import support - -d1 = {'status':1, 'background':2, 'borderwidth':3, 'foreground':4} -d2 = {'status':1, 'background':2, 'foreground':4, 'borderwidth':3} - -if d1 != d2: - raise support.TestError('equal dicts does not compare equal.') - Deleted: trunk/jython/bugtests/test178.py =================================================================== --- trunk/jython/bugtests/test178.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test178.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ - -import support - -s1 = r""" - \""" 1.triple-quote - \""" 2.triple-quote -""" - -s2 = r''' - \""" 1.triple-quote - \""" 2.triple-quote -''' - - -for i in range(len(s2)): - if s1[i] != s2[i]: print "diff at", i - - -if s1 != s2: - raise support.TestError, "TQS different" \ No newline at end of file Deleted: trunk/jython/bugtests/test179.py =================================================================== --- trunk/jython/bugtests/test179.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test179.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,22 +0,0 @@ -""" - The traceback linenumber does not match the throw line. -""" -import support - -def foo(): - assert 0 - -try: - try: - - - foo() - - - - finally: - pass -except: - import sys - info = sys.exc_info() - support.compare(info[2].tb_lineno, "13") Deleted: trunk/jython/bugtests/test180.py =================================================================== --- trunk/jython/bugtests/test180.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test180.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,18 +0,0 @@ -""" - -""" - -import support - - -class A: - def __init__(self): - self.foo = 'bar' - -def f(*args, **kw): - #print args, kw - support.compare(args, "(1, 2, 3)") - support.compare(kw, "{'foo': 'bar'}") - -apply(f, (1,2,3), A().__dict__) - Deleted: trunk/jython/bugtests/test181.py =================================================================== --- trunk/jython/bugtests/test181.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test181.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" -Test TQS -""" - -import support - -s1 = r""" - \""" 1.triple-quote - \""" 2.triple-quote -""" - -import string - -if '\r' in s1: - raise support.TestError, "TQS should not contain CR" \ No newline at end of file Deleted: trunk/jython/bugtests/test182.py =================================================================== --- trunk/jython/bugtests/test182.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test182.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test182j.java") - -support.compileJPythonc("test182c.py", core=1, jar="test182c.jar", output="test182.err") -support.runJava("test182c", classpath="test182c.jar") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test182c.py =================================================================== --- trunk/jython/bugtests/test182c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test182c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,38 +0,0 @@ - -import support - -import test182j - -class test182c(test182j): - def tstOverridePublic(self): - #print "her1" - return "test182c." + test182j.tstOverridePublic(self) - def tstOverrideProtected(self): - #print "her2" - return "test182c." + self.super__tstOverrideProtected() - def tstOverrideFinalProtected(self): - return "test182c." + self.super__tstOverrideFinalProtected() - def tstOverrideFinalPublic(self): - return "test182c." + test182j.tstOverrideFinalPublic(self) - - def tstAbstractPublic(self): - return "test182c.tstAbstractPublic" - def tstAbstractProtected(self): - return "test182c.tstAbstractProtected" - -i = test182c() - -support.compare(i.tstPublic(), "tstPublic") -support.compare(i.tstProtected(), "tstProtected") -support.compare(i.super__tstFinalProtected(), "tstFinalProtected") -support.compare(i.tstFinalPublic(), "tstFinalPublic") - - -support.compare(i.tstOverridePublic(), "test182c.tstOverridePublic") -support.compare(i.tstOverrideProtected(), "test182c.tstOverrideProtected") -support.compare(i.tstOverrideFinalProtected(), "test182c.tstOverrideFinalProtected") -support.compare(i.tstOverrideFinalPublic(), "test182c.tstOverrideFinalPublic") - - -support.compare(i.tstAbstractPublic(), "test182c.tstAbstractPublic") -support.compare(i.tstAbstractProtected(), "test182c.tstAbstractProtected") Deleted: trunk/jython/bugtests/test183.py =================================================================== --- trunk/jython/bugtests/test183.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test183.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,19 +0,0 @@ -""" -Test the re.M flag. Fails when using re. Success with sre. -""" - -import support - -import re - -var ="T\nO" - -m = re.search("^O",var,re.M) -if m == None: - raise support.TestError("Should match") - - -m = re.search("^O",var) -if m != None: - raise support.TestError("Should not match") - Deleted: trunk/jython/bugtests/test184.py =================================================================== --- trunk/jython/bugtests/test184.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test184s1.py", "test184s2.py", deep=1, output="test184.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test184s1.py =================================================================== --- trunk/jython/bugtests/test184s1.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184s1.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,16 +0,0 @@ - -from javax.servlet.http import HttpServlet - -import test184p - -class test184s1(HttpServlet): - def doGet(self, request, response): - response.setContentType("text/html") - out = response.getOutputStream() - out.println("<html>") - out.println("<head> <title> JPython test184s1 servlet </title></head>") - out.println("<body> <h2> Hello World! JPython %s </h2> </body>" % test184p.foo()) - out.println(" </html>") - - -print test184s1, Exception Deleted: trunk/jython/bugtests/test184s2.py =================================================================== --- trunk/jython/bugtests/test184s2.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184s2.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ - -from javax.servlet.http import * - -import test184p - - -class test184s2(HttpServlet): - def doGet(self, request, response): - response.setContentType("text/html") - out = response.getOutputStream() - out.println("<html>") - out.println("<head> <title> JPython test184s2 servlet </title></head>") - out.println("<body> <h2> Hello World! JPython %s </h2> </body>" % test184p.foo()) - out.println(" </html>") - - -print test184s2, ServletConfig Deleted: trunk/jython/bugtests/test185.html =================================================================== --- trunk/jython/bugtests/test185.html 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185.html 2008-12-28 17:39:01 UTC (rev 5801) @@ -1 +0,0 @@ -<applet code="test185a" archive="test185.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test185.py =================================================================== --- trunk/jython/bugtests/test185.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test185a.py", core=1, jar="test185.jar", output="test185.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test185a.py =================================================================== --- trunk/jython/bugtests/test185a.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185a.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ -from java.awt import Frame -from java.applet import Applet -from test185m import * - -class test185a(Applet): - def __init__(self): - self.mydd = dd() - self.add(self.mydd) - - -class foo: - pass - -class bar(foo): - pass - -if __name__ == "__main__": - f = Frame(); c = c() - f.add(c); f.pack(); f.show() - Deleted: trunk/jython/bugtests/test185m.py =================================================================== --- trunk/jython/bugtests/test185m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -from java.awt import * - -class dd(Panel): - def __init__(self): - self.add(Label("Running")) - \ No newline at end of file Deleted: trunk/jython/bugtests/test186.html =================================================================== --- trunk/jython/bugtests/test186.html 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186.html 2008-12-28 17:39:01 UTC (rev 5801) @@ -1 +0,0 @@ -<applet code="com.mycompany.mypackage.test186a" archive="test186.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test186.py =================================================================== --- trunk/jython/bugtests/test186.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test186a.py", core=1, package="com.mycompany.mypackage", - jar="test186.jar", output="test186.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test186a.py =================================================================== --- trunk/jython/bugtests/test186a.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186a.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ -import java - -# Define a Python class that subclasses the Applet class -# (java.applet.Applet) - -class test186a (java.applet.Applet): - def __init__(self): - self.list = java.awt.List() - self.add(self.list) - def init(self): - self.list.add("Init called") - def destroy(self): - self.list.add("Destroy called") - def start(self): - self.list.add("Start called") - def stop(self): - self.list.add("Stop called") Deleted: trunk/jython/bugtests/test187.py =================================================================== --- trunk/jython/bugtests/test187.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test187.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test187c.py", output="test187.err") - Deleted: trunk/jython/bugtests/test187c.py =================================================================== --- trunk/jython/bugtests/test187c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test187c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,40 +0,0 @@ - -def a1(): - if a: - return 22 - else: - return 10 - print "abc" - - -def a2(): - if a: - return 22 - else: - return 10 - return None - - -def a3(): - """docstring""" - if a: - return 22 - else: - return 10 - 5 - -def a4(): - """docstring""" - a = 1 - raise "Error", 1 - b... [truncated message content] |
From: <cg...@us...> - 2008-12-29 05:45:49
|
Revision: 5804 http://jython.svn.sourceforge.net/jython/?rev=5804&view=rev Author: cgroves Date: 2008-12-29 05:45:42 +0000 (Mon, 29 Dec 2008) Log Message: ----------- test207 - Moved to test_unicode_jy test208 - Moved to test_java_visibility test209,211 - Tested by test_cpickle test210 - Tested by test_pickle test212 - Moved to test_str test213 - Tested by test_str test214,217,218,220-224,226-229,237,242,246,249,251-257 - Testing jythonc; deleted test215 - Tested by test_list test219 - Moved to org.python.tests.ExceptionTest test225 - Moved to test_grammar_jy test230,235,239,240 - Not sure what it's testing; deleted test231 - Moved to test_java_integration test232 - Moved to test_java_visibility test233 - Tested by test_import_jy test234 - Tested by test_copy test238 - Was already disabled; deleted test245 - Tested by org.python.util.InterpreterTest test247 - Moved to test_java_integration test248 - Dupe of test247 test250 - Moved to test_java_visibility test258 - Tested by test_import_jy Modified Paths: -------------- trunk/jython/Lib/test/string_tests.py trunk/jython/Lib/test/test_grammar_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/bugtests/test230.py trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java trunk/jython/tests/java/org/python/tests/Callbacker.java trunk/jython/tests/java/org/python/tests/Coercions.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/BadStaticInitializer.java trunk/jython/tests/java/org/python/tests/ExceptionTest.java trunk/jython/tests/java/org/python/tests/HiddenSuper.java trunk/jython/tests/java/org/python/tests/OtherSubVisible.java trunk/jython/tests/java/org/python/tests/SomePyMethods.java Removed Paths: ------------- trunk/jython/bugtests/classes/test208j.java trunk/jython/bugtests/classes/test208j0.java trunk/jython/bugtests/classes/test208j1.java trunk/jython/bugtests/classes/test208j2.java trunk/jython/bugtests/classes/test217p/ trunk/jython/bugtests/classes/test219e.java trunk/jython/bugtests/classes/test219i.java trunk/jython/bugtests/classes/test219j.java trunk/jython/bugtests/classes/test220e.java trunk/jython/bugtests/classes/test220i.java trunk/jython/bugtests/classes/test220j.java trunk/jython/bugtests/classes/test231j.java trunk/jython/bugtests/classes/test231j2.java trunk/jython/bugtests/classes/test232p/ trunk/jython/bugtests/classes/test236j1.java trunk/jython/bugtests/classes/test236j2.java trunk/jython/bugtests/classes/test246p/ trunk/jython/bugtests/classes/test248j.java trunk/jython/bugtests/test207.py trunk/jython/bugtests/test208.py trunk/jython/bugtests/test209.py trunk/jython/bugtests/test209p/ trunk/jython/bugtests/test210.py trunk/jython/bugtests/test212.py trunk/jython/bugtests/test213.py trunk/jython/bugtests/test214.html trunk/jython/bugtests/test214.py trunk/jython/bugtests/test215.py trunk/jython/bugtests/test217.py trunk/jython/bugtests/test217c.py trunk/jython/bugtests/test217t.java trunk/jython/bugtests/test218.py trunk/jython/bugtests/test218c.py trunk/jython/bugtests/test219.py trunk/jython/bugtests/test220.py trunk/jython/bugtests/test220c.py trunk/jython/bugtests/test221.py trunk/jython/bugtests/test221c.py trunk/jython/bugtests/test222.py trunk/jython/bugtests/test222s.py trunk/jython/bugtests/test223.py trunk/jython/bugtests/test223s.py trunk/jython/bugtests/test224.py trunk/jython/bugtests/test224s.py trunk/jython/bugtests/test225.py trunk/jython/bugtests/test225s.py trunk/jython/bugtests/test226.py trunk/jython/bugtests/test226c.py trunk/jython/bugtests/test227.py trunk/jython/bugtests/test227c.py trunk/jython/bugtests/test228.py trunk/jython/bugtests/test228s.py trunk/jython/bugtests/test229.py trunk/jython/bugtests/test229c.py trunk/jython/bugtests/test231.py trunk/jython/bugtests/test232.py trunk/jython/bugtests/test233.py trunk/jython/bugtests/test234.py trunk/jython/bugtests/test237.py trunk/jython/bugtests/test237m1.py trunk/jython/bugtests/test237m2.py trunk/jython/bugtests/test238.py trunk/jython/bugtests/test242.py trunk/jython/bugtests/test242c.py trunk/jython/bugtests/test245.py trunk/jython/bugtests/test245j.java trunk/jython/bugtests/test246.py trunk/jython/bugtests/test246c.py trunk/jython/bugtests/test247.py trunk/jython/bugtests/test247j.java trunk/jython/bugtests/test248.py trunk/jython/bugtests/test249.py trunk/jython/bugtests/test249c.py trunk/jython/bugtests/test250.py trunk/jython/bugtests/test250j.java trunk/jython/bugtests/test251.py trunk/jython/bugtests/test251c.py trunk/jython/bugtests/test251c2.py trunk/jython/bugtests/test252.py trunk/jython/bugtests/test252c.py trunk/jython/bugtests/test252c2.py trunk/jython/bugtests/test253.py trunk/jython/bugtests/test253c.py trunk/jython/bugtests/test253c2.py trunk/jython/bugtests/test254.html trunk/jython/bugtests/test254.py trunk/jython/bugtests/test254c.py trunk/jython/bugtests/test255.py trunk/jython/bugtests/test255s1.py trunk/jython/bugtests/test255s2.py trunk/jython/bugtests/test256.html trunk/jython/bugtests/test256.py trunk/jython/bugtests/test256a.py trunk/jython/bugtests/test257.py trunk/jython/bugtests/test258.py trunk/jython/bugtests/test258m1.py Modified: trunk/jython/Lib/test/string_tests.py =================================================================== --- trunk/jython/Lib/test/string_tests.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/string_tests.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -917,7 +917,9 @@ self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 3)) self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 1000)) self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1)) + self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1L)) self.checkequal(u'', 'abc', '__getitem__', slice(0, 0)) + self.checkequal(u'', 'abc', '__getitem__', slice(0L, 0L)) # FIXME What about negative indices? This is handled differently by [] and __getitem__(slice) self.checkraises(TypeError, 'abc', '__getitem__', 'def') Modified: trunk/jython/Lib/test/test_grammar_jy.py =================================================================== --- trunk/jython/Lib/test/test_grammar_jy.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_grammar_jy.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -24,6 +24,14 @@ self.assertEquals(uR"spam", Ur"spam") self.assertEquals(ur"spam", UR"spam") + def testKeywordOperations(self): + def foo(a=1, b=2 + 4): + return b + self.assertEquals(6, foo()) + self.assertEquals(6, foo(1)) + self.assertEquals(7, foo(1, 7)) + self.assertEquals(10, foo(b=10)) + def test_main(): test_support.run_unittest(GrammarTest) Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -8,7 +8,7 @@ from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import (Boolean, Integer, Object, String, Runnable, +from java.lang import (Boolean, ExceptionInInitializerError, Integer, Object, String, Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath @@ -322,10 +322,12 @@ self.assertEquals(self.kws.yield(), "yield") class ImportTest(unittest.TestCase): - def test_bad_input_exception(self): self.assertRaises(ValueError, __import__, '') + def test_broken_static_initializer(self): + self.assertRaises(ExceptionInInitializerError, __import__, "org.python.tests.BadStaticInitializer") + class ColorTest(unittest.TestCase): def test_assigning_over_method(self): @@ -417,9 +419,9 @@ def call(self, extraarg=None): called.append(extraarg) Callbacker.callNoArg(PyCallback()) - Callbacker.callOneArg(PyCallback(), "arg") + Callbacker.callOneArg(PyCallback(), 4294967295L) self.assertEquals(None, called[0]) - self.assertEquals("arg", called[1]) + self.assertEquals(4294967295L, called[1]) class PyBadCallback(Callbacker.Callback): def call(pyself, extraarg): self.fail("Shouldn't be callable with a no args") Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -3,8 +3,8 @@ from test import test_support from java.lang import Class from java.util import HashMap, Observable, Observer -from org.python.tests import (Coercions, InterfaceCombination, Invisible, OnlySubclassable, - SubVisible, Visible, VisibleOverride) +from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, OnlySubclassable, + OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -125,6 +125,10 @@ self.assertFalse(hasattr(i, "internalMethod"), "methods from private interfaces shouldn't be visible on a private class") + def test_super_methods_visible(self): + '''Bug #222847 - Can't access public member of package private base class''' + self.assertEquals("hi", HiddenSuper().hi()) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), @@ -138,7 +142,13 @@ self.assertEquals(Class, HashMap.__class__) self.assertEquals(None, HashMap.__doc__) -class NumberCoercionTest(unittest.TestCase): + def test_python_methods(self): + s = SomePyMethods() + self.assertEquals(6, s[3]) + self.assertEquals(2, s.a, "Undefined attributes should go through to __getattr__") + self.assertEquals(3, s.b, "Defined fields should take precedence") + +class CoercionTest(unittest.TestCase): def test_int_coercion(self): c = Coercions() self.assertEquals("5", c.takeInt(5)) @@ -151,11 +161,13 @@ self.assertEquals("4", Coercions.takePyObj(1, 2, 3, 4)) c = Coercions() self.assertEquals("5", c.takePyObjInst(1, 2, 3, 4, 5)) + self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) + self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, - NumberCoercionTest) + CoercionTest) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -83,7 +83,32 @@ self.assertRaises(UnicodeDecodeError, u''.join, ['foo', '毛泽东']) self.assertRaises(UnicodeDecodeError, '毛泽东'.join, [u'foo', u'bar']) + def test_file_encoding(self): + '''Ensure file writing doesn't attempt to encode things by default and reading doesn't + decode things by default. This was jython's behavior prior to 2.2.1''' + EURO_SIGN = u"\u20ac" + try: + EURO_SIGN.encode() + except UnicodeEncodeError: + # This default encoding can't handle the encoding the Euro sign. Skip the test + return + f = open(test_support.TESTFN, "w") + self.assertRaises(UnicodeEncodeError, f, write, EURO_SIGN, + "Shouldn't be able to write out a Euro sign without first encoding") + f.close() + + f = open(test_support.TESTFN, "w") + f.write(EURO_SIGN.encode('utf-8')) + f.close() + + f = open(test_support.TESTFN, "r") + encoded_euro = f.read() + f.close() + os.remove(test_support.TESTFN) + self.assertEquals('\xe2\x82\xac', encoded_euro) + self.assertEquals(EURO_SIGN, encoded_euro.decode('utf-8')) + def test_main(): test_support.run_unittest(UnicodeTestCase) Deleted: trunk/jython/bugtests/classes/test208j.java =================================================================== --- trunk/jython/bugtests/classes/test208j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,14 +0,0 @@ -public class test208j { - public static String foo(test208j1[] p) { - return "test208j1[]"; - } - public static String foo(test208j2[] p) { - return "test208j2[]"; - } - public static String foo(Object p) { - return "Object"; - } - public static String foo(Object[] p) { - return "Object[]"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j0.java =================================================================== --- trunk/jython/bugtests/classes/test208j0.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j0.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j1.java =================================================================== --- trunk/jython/bugtests/classes/test208j1.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j1.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j1 extends test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j2.java =================================================================== --- trunk/jython/bugtests/classes/test208j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j2 extends test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test219e.java =================================================================== --- trunk/jython/bugtests/classes/test219e.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219e.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ - -public class test219e extends Exception { - public test219e(String msg) { - super(msg); - } -} - Deleted: trunk/jython/bugtests/classes/test219i.java =================================================================== --- trunk/jython/bugtests/classes/test219i.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219i.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,5 +0,0 @@ - -public interface test219i { - public void foo() throws test219e; - public void foo2(int i) throws test219e, Throwable; -} Deleted: trunk/jython/bugtests/classes/test219j.java =================================================================== --- trunk/jython/bugtests/classes/test219j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,25 +0,0 @@ - -public class test219j { - public static void checkFoo(test219i o) { - try { - o.foo(); - } catch (test219e t) { - // Success. - } catch (Throwable t) { - System.out.println(t.getClass() + " " + t); - } - } - - - public static void checkFoo2(test219i o, int i) { - try { - o.foo2(i); - } catch (test219e t) { - if (i != 0) - System.out.println("failure to catch test219e"); - } catch (Throwable t) { - if (i != 1) - System.out.println("failure to catch Throwable"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test220e.java =================================================================== --- trunk/jython/bugtests/classes/test220e.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220e.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ - -public class test220e extends Exception { - public test220e(String msg) { - super(msg); - } -} - Deleted: trunk/jython/bugtests/classes/test220i.java =================================================================== --- trunk/jython/bugtests/classes/test220i.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220i.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,5 +0,0 @@ - -public interface test220i { - public void foo() throws test220e; - public void foo2(int i) throws test220e, Throwable; -} Deleted: trunk/jython/bugtests/classes/test220j.java =================================================================== --- trunk/jython/bugtests/classes/test220j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,25 +0,0 @@ - -public class test220j { - public static void checkFoo(test220i o) { - try { - o.foo(); - } catch (test220e t) { - // Success. - } catch (Throwable t) { - System.out.println(t.getClass() + " " + t); - } - } - - - public static void checkFoo2(test220i o, int i) { - try { - o.foo2(i); - } catch (test220e t) { - if (i != 0) - System.out.println("failure to catch test220e"); - } catch (Throwable t) { - if (i != 1) - System.out.println("failure to catch Throwable"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test231j.java =================================================================== --- trunk/jython/bugtests/classes/test231j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test231j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ - -public interface test231j{ - public void handleRemove(long start); -} Deleted: trunk/jython/bugtests/classes/test231j2.java =================================================================== --- trunk/jython/bugtests/classes/test231j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test231j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,6 +0,0 @@ - -public class test231j2 { - public static void callback(test231j t) { - t.handleRemove(4294967295l); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test236j1.java =================================================================== --- trunk/jython/bugtests/classes/test236j1.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test236j1.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ -public class test236j1 { - static int foo_ = test236j2.foo(); -} - Deleted: trunk/jython/bugtests/classes/test236j2.java =================================================================== --- trunk/jython/bugtests/classes/test236j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test236j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,3 +0,0 @@ -public class test236j2 { - public static int foo() { return 12; } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test248j.java =================================================================== --- trunk/jython/bugtests/classes/test248j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test248j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ - -public class test248j { - static { - //System.out.println("hello1"); - String s = null; - s.length(); - //It seems like jdk1.4 doesn't like a naked throws in static. - //throw new NullPointerException("init failure"); - } -} Deleted: trunk/jython/bugtests/test207.py =================================================================== --- trunk/jython/bugtests/test207.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test207.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,34 +0,0 @@ -""" -Test that file writing doesn't attempt to encode things by default and reading -doesn't decode things by default. -""" - -import support - -EURO_SIGN = u"\u20ac" -try: - EURO_SIGN.encode() - import sys - raise support.TestError('Your default encoding, %s, can handle encoding the Euro sign. This test needs the default encoding to be unable to handle on its test character' % - sys.getdefaultencoding()) -except UnicodeEncodeError: - pass - -f = open("test207.out", "w") -try: - f.write(EURO_SIGN) - raise support.TestError("Shouldn't be able to write out a Euro sign without first encoding") -except UnicodeEncodeError: - pass -f.close() - -f = open("test207.out", "w") -f.write(EURO_SIGN.encode('utf-8')) -f.close() - -f = open("test207.out", "r") -encoded_euro = f.read() -f.close() -if encoded_euro != '\xe2\x82\xac' or encoded_euro.decode('utf-8') != EURO_SIGN: - raise support.TestError("Read something other than the euro sign that we wrote out") -f.close() Deleted: trunk/jython/bugtests/test208.py =================================================================== --- trunk/jython/bugtests/test208.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test208.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,17 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test208j.java") - -import test208j -import test208j1 -import test208j2 - -p=[test208j2()] -support.compare(test208j.foo(p), "test208j2\[\]") - -p=[test208j1()] -support.compare(test208j.foo(p), "test208j1\[\]") Deleted: trunk/jython/bugtests/test209.py =================================================================== --- trunk/jython/bugtests/test209.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test209.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -import cPickle - -import test209p.foo.bar - -o = test209p.foo.bar.baz() - -s = cPickle.dumps(o) -#print s - -o2 = cPickle.loads(s) - - - Deleted: trunk/jython/bugtests/test210.py =================================================================== --- trunk/jython/bugtests/test210.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test210.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,29 +0,0 @@ - -import sys -import pickle -tmpfile = "test210.tmp" - -try: - import test118 -except: - pass - -def saveValue( value): - f = open(tmpfile,"wb") - p = pickle.Pickler(f,1) - p.dump(value) - f.close() - -def loadValue(): - f=open(tmpfile,"rb") - retVal = pickle.Unpickler(f).load() - f.close() - return retVal - -for x in range(256): - saveValue(x) - y = loadValue() - if x != y: - print "saved: ", x, - print "loaded: ", y - Deleted: trunk/jython/bugtests/test212.py =================================================================== --- trunk/jython/bugtests/test212.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test212.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,14 +0,0 @@ -""" -Test long indexing of sequences (1.6) -""" - -import support - - -l = (0,1,2,3) - -if l[2L:4L] != (2, 3): - raise support.TestError, "long slice error #1" - -if "abcbdef"[2L:4L] != "cb": - raise support.TestError, "long slice error #2" Deleted: trunk/jython/bugtests/test213.py =================================================================== --- trunk/jython/bugtests/test213.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test213.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ -""" -Test %r on strings -""" - -import support - - - - -r = "%s %r" % ("abc", "abc") - -if r != "abc 'abc'": - raise support.TestError, "wrong output %s" % r - - Deleted: trunk/jython/bugtests/test214.html =================================================================== --- trunk/jython/bugtests/test214.html 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test214.html 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -<applet code="test214a" archive="test214.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test214.py =================================================================== --- trunk/jython/bugtests/test214.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test214.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test214a.py", core=1, jar="test214.jar", output="test214.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test215.py =================================================================== --- trunk/jython/bugtests/test215.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test215.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,24 +0,0 @@ -""" - -""" - -import support - - - -l = [] -try: - l.insert('a', 1) -except TypeError: - pass -else: - raise support.TestError("Should raise TypeError") - - - -l = [] -l.insert(1, 'a') -l.insert(6, 'b') -l.insert(-1, 'c') -l.insert(3, 'd') - Deleted: trunk/jython/bugtests/test217.py =================================================================== --- trunk/jython/bugtests/test217.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import os -import support -support.compileJava("classes/test217p/test217i.java") - -support.compileJPythonc("test217c.py", output="test217.err") -support.compileJava("test217t.java", classpath="jpywork") -support.runJava("test217t", classpath="jpywork" + os.pathsep + ".") Deleted: trunk/jython/bugtests/test217c.py =================================================================== --- trunk/jython/bugtests/test217c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ -from java.lang import Object, String -from java.io import Serializable -from test217p import test217i -import java - -class test217c(Object, Serializable, test217i): - def add(self, x, y): - "@sig public java.lang.String add(int x, int y)" - return "The sum of %d and %d is %d" % (x, y, x+y) - Deleted: trunk/jython/bugtests/test217t.java =================================================================== --- trunk/jython/bugtests/test217t.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217t.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,8 +0,0 @@ -public class test217t { - public static void main(String args[]) { - test217p.test217i c = new test217c(); - String s = c.add(1, 2); - if (!"The sum of 1 and 2 is 3".equals(s)) - System.out.println("Wrong output:" + s); - } -} Deleted: trunk/jython/bugtests/test218.py =================================================================== --- trunk/jython/bugtests/test218.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test218.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test218c.py", output="test218.err") - -support.runJava("test218c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test218c.py =================================================================== --- trunk/jython/bugtests/test218c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test218c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -a,b, = 1,2 Deleted: trunk/jython/bugtests/test219.py =================================================================== --- trunk/jython/bugtests/test219.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test219.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,22 +0,0 @@ - -import support - -support.compileJava("classes/test219j.java") - -import test219i, test219e, test219j - -class test219(test219i): - def foo(self): - raise test219e("raised in foo()") - def foo2(self, i): - if i == 0: - raise test219e("test219e raised in foo()") - else: - raise java.lang.Throwable("Throwable raised in foo()") - - -a = test219() - -test219j.checkFoo(a) -test219j.checkFoo2(a, 0) -test219j.checkFoo2(a, 1) Deleted: trunk/jython/bugtests/test220.py =================================================================== --- trunk/jython/bugtests/test220.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test220.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test220j.java") -support.compileJPythonc("test220c.py", output="test220.err") - -support.runJava("test220c", classpath="jpywork") Deleted: trunk/jython/bugtests/test220c.py =================================================================== --- trunk/jython/bugtests/test220c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test220c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,18 +0,0 @@ - -import test219i, test219e, test219j - -class test219(test219i): - def foo(self): - raise test219e("raised in foo()") - def foo2(self, i): - if i == 0: - raise test219e("test219e raised in foo()") - else: - raise java.lang.Throwable("Throwable raised in foo()") - - -a = test219() - -test219j.checkFoo(a) -test219j.checkFoo2(a, 0) -test219j.checkFoo2(a, 1) Deleted: trunk/jython/bugtests/test221.py =================================================================== --- trunk/jython/bugtests/test221.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test221.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test221c - -support.compileJPythonc("test221c.py", deep=1, output="test221.err") - -support.runJava("test221c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test221c.py =================================================================== --- trunk/jython/bugtests/test221c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test221c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,33 +0,0 @@ - -import support - -a = 1 -a += 1 + 2 -if a != 4: - raise support.TestError, "Wrong result #1 %s" % a - -a=[0,1,2,3,4,5] -if a[1:3] != [1, 2]: - raise support.TestError, "Wrong result #2 %s" % a[1:3] - -a[1:3] += ["a", "b"] -if a != [0, 1, 2, 'a', 'b', 3, 4, 5]: - raise support.TestError, "Wrong result #3 %s" % a - - -s = None - -class A: - def __getitem__(self, i): - global s - if s is None: - s = i - else: - raise support.TestError, "__getitem__ should only be called once" - return 11 - def __setitem__(self, i, v): - if s != i: - raise support.TestError, "__setitem__ should have same index af __getitem__" - -a = A() -a[:, ..., ::, 0:10:2, :10:, 1, 2:, ::-1] += 1 \ No newline at end of file Deleted: trunk/jython/bugtests/test222.py =================================================================== --- trunk/jython/bugtests/test222.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test222.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test222s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test222s.py", output="test222.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test222s.py =================================================================== --- trunk/jython/bugtests/test222s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test222s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -(a, b, c) += 1,2,3 Deleted: trunk/jython/bugtests/test223.py =================================================================== --- trunk/jython/bugtests/test223.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test223.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test223s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test223s.py", output="test223.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test223s.py =================================================================== --- trunk/jython/bugtests/test223s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test223s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -a += b += c Deleted: trunk/jython/bugtests/test224.py =================================================================== --- trunk/jython/bugtests/test224.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test224.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test224s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test224s.py", output="test224.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test224s.py =================================================================== --- trunk/jython/bugtests/test224s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test224s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -[a, b, c] += 1,2,3 Deleted: trunk/jython/bugtests/test225.py =================================================================== --- trunk/jython/bugtests/test225.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test225.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -import test225s Deleted: trunk/jython/bugtests/test225s.py =================================================================== --- trunk/jython/bugtests/test225s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test225s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ - -import support - -def foo(a=1, b=2+4): - return b - -v = foo() - -if v != 6: - raise support.TestError, "Wrong return value %d" % d - Deleted: trunk/jython/bugtests/test226.py =================================================================== --- trunk/jython/bugtests/test226.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test226.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test226c.py", output="test226.err") - -support.runJava("test226c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test226c.py =================================================================== --- trunk/jython/bugtests/test226c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test226c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,20 +0,0 @@ - -cnt = 0 - -def f(i): - global cnt - cnt = cnt + 1 - return i - - -l=[1,2,3,4,5,6] - -l[f(2):f(4)] += ['a', 'b', 'c'] - -if cnt != 2: - raise support.TestError('Number of calls is wrong') - - -if l != [1, 2, 3, 4, 'a', 'b', 'c', 5, 6]: - raise support.TestError('list is wrong') - Deleted: trunk/jython/bugtests/test227.py =================================================================== --- trunk/jython/bugtests/test227.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test227.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test227c.py", output="test227.err") - -support.runJava("test227c", classpath="jpywork", output="test227.out") \ No newline at end of file Deleted: trunk/jython/bugtests/test227c.py =================================================================== --- trunk/jython/bugtests/test227c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test227c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,232 +0,0 @@ - -# Augmented assignment test. - -x = 2 -x += 1 -x *= 2 -x **= 2 -x -= 8 -x /= 2 -x %= 12 -x &= 2 -x |= 5 -x ^= 1 - -print x - -x = [2] -x[0] += 1 -x[0] *= 2 -x[0] **= 2 -x[0] -= 8 -x[0] /= 2 -x[0] %= 12 -x[0] &= 2 -x[0] |= 5 -x[0] ^= 1 - -print x - -x = {0: 2} -x[0] += 1 -x[0] *= 2 -x[0] **= 2 -x[0] -= 8 -x[0] /= 2 -x[0] %= 12 -x[0] &= 2 -x[0] |= 5 -x[0] ^= 1 - -print x[0] - -x = [1,2] -x += [3,4] -x *= 2 - -print x - -x = [1, 2, 3] -y = x -x[1:2] *= 2 -y[1:2] += [1] - -print x -print x is y - -class aug_test: - def __init__(self, value): - self.val = value - def __radd__(self, val): - return self.val + val - def __add__(self, val): - return aug_test(self.val + val) - - -class aug_test2(aug_test): - def __iadd__(self, val): - self.val = self.val + val - return self - -class aug_test3(aug_test): - def __iadd__(self, val): - return aug_test3(self.val + val) - -x = aug_test(1) -y = x -x += 10 - -print isinstance(x, aug_test) -print y is not x -print x.val - -x = aug_test2(2) -y = x -x += 10 - -print y is x -print x.val - -x = aug_test3(3) -y = x -x += 10 - -print isinstance(x, aug_test3) -print y is not x -print x.val - -class testall: - - def __add__(self, val): - print "__add__ called" - def __radd__(self, val): - print "__radd__ called" - def __iadd__(self, val): - print "__iadd__ called" - return self - - def __sub__(self, val): - print "__sub__ called" - def __rsub__(self, val): - print "__rsub__ called" - def __isub__(self, val): - print "__isub__ called" - return self - - def __mul__(self, val): - print "__mul__ called" - def __rmul__(self, val): - print "__rmul__ called" - def __imul__(self, val): - print "__imul__ called" - return self - - def __div__(self, val): - print "__div__ called" - def __rdiv__(self, val): - print "__rdiv__ called" - def __idiv__(self, val): - print "__idiv__ called" - return self - - def __mod__(self, val): - print "__mod__ called" - def __rmod__(self, val): - print "__rmod__ called" - def __imod__(self, val): - print "__imod__ called" - return self - - def __pow__(self, val): - print "__pow__ called" - def __rpow__(self, val): - print "__rpow__ called" - def __ipow__(self, val): - print "__ipow__ called" - return self - - def __or__(self, val): - print "__or__ called" - def __ror__(self, val): - print "__ror__ called" - def __ior__(self, val): - print "__ior__ called" - return self - - def __and__(self, val): - print "__and__ called" - def __rand__(self, val): - print "__rand__ called" - def __iand__(self, val): - print "__iand__ called" - return self - - def __xor__(self, val): - print "__xor__ called" - def __rxor__(self, val): - print "__rxor__ called" - def __ixor__(self, val): - print "__ixor__ called" - return self - - def __rshift__(self, val): - print "__rshift__ called" - def __rrshift__(self, val): - print "__rrshift__ called" - def __irshift__(self, val): - print "__irshift__ called" - return self - - def __lshift__(self, val): - print "__lshift__ called" - def __rlshift__(self, val): - print "__rlshift__ called" - def __ilshift__(self, val): - print "__ilshift__ called" - return self - -x = testall() -x + 1 -1 + x -x += 1 - -x - 1 -1 - x -x -= 1 - -x * 1 -1 * x -x *= 1 - -x / 1 -1 / x -x /= 1 - -x % 1 -1 % x -x %= 1 - -x ** 1 -1 ** x -x **= 1 - -x | 1 -1 | x -x |= 1 - -x & 1 -1 & x -x &= 1 - -x ^ 1 -1 ^ x -x ^= 1 - -x >> 1 -1 >> x -x >>= 1 - -x << 1 -1 << x -x <<= 1 - Deleted: trunk/jython/bugtests/test228.py =================================================================== --- trunk/jython/bugtests/test228.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test228.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test228s - -support.compileJPythonc("test228s.py", deep=1, output="test228.err") - -support.runJava("test228s", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test228s.py =================================================================== --- trunk/jython/bugtests/test228s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test228s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,26 +0,0 @@ - -from java import util as ut, io, awt as aw, text as te -import java - -import support - -if java.util != ut: - raise support.TestError("util not the same") -if java.awt != aw: - raise support.TestError("awt not the same") -if java.io != io: - raise support.TestError("io not the same") -if java.text != te: - raise support.TestError("text not the same") - - -import java.util.Vector as vec -import java.util.Date as date, java.io.File as file - -if java.util.Vector != vec: - raise support.TestError("Vector not the same") -if java.util.Date != date: - raise support.TestError("Date not the same") -if java.io.File != file: - raise support.TestError("File not the same") - Deleted: trunk/jython/bugtests/test229.py =================================================================== --- trunk/jython/bugtests/test229.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test229.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,8 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test229c.py", output="test229.err") - Deleted: trunk/jython/bugtests/test229c.py =================================================================== --- trunk/jython/bugtests/test229c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test229c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -zeros((3,3))[:,0] Modified: trunk/jython/bugtests/test230.py =================================================================== --- trunk/jython/bugtests/test230.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test230.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -7,8 +7,7 @@ class P: def do_help(self, arg): - pass - #print "do_help", arg + print "do_help", arg #print do_help, id(do_help) def onecmd(self, cmd, arg): Deleted: trunk/jython/bugtests/test231.py =================================================================== --- trunk/jython/bugtests/test231.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test231.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ - -import support - -support.compileJava("classes/test231j2.java") - -import test231j, test231j2 - -class MyHandler(test231j): - def handleRemove(self, start): - if start != 4294967295L: - raise support.TestError("long not passed correcttly") - -m = MyHandler() - -test231j2.callback(m); Deleted: trunk/jython/bugtests/test232.py =================================================================== --- trunk/jython/bugtests/test232.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test232.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ -""" -Bug #222847 - Can't access public member of package private base class -""" - -import support - -support.compileJava("classes/test232p/Foo.java") - -from test232p import Foo -try: - Foo().hi() -except IllegalAccessException: - raise support.TestError('Should be able to call public method on package protected superclass') - - Deleted: trunk/jython/bugtests/test233.py =================================================================== --- trunk/jython/bugtests/test233.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test233.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ - -import support - -try: - from test233s import foobar -except ImportError: - pass -else: - raise support.TestError("Should raise ImportError") Deleted: trunk/jython/bugtests/test234.py =================================================================== --- trunk/jython/bugtests/test234.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test234.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ -import copy -class X: pass - -x=X() -y=copy.deepcopy(x) - -y=copy.copy(x) Deleted: trunk/jython/bugtests/test237.py =================================================================== --- trunk/jython/bugtests/test237.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ -import support - -support.compileJPythonc("test237m2.py", output="test237.err", deep=1) - Deleted: trunk/jython/bugtests/test237m1.py =================================================================== --- trunk/jython/bugtests/test237m1.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237m1.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,97 +0,0 @@ -from jarray import array - -from javax import swing -from java import awt -from java.beans import PropertyChangeListener - -import java.lang -import string - - -class DlgClick(PropertyChangeListener) : - # - # this delegates propertyChange events - # subclassing and interface extending doesn't seem to work - # properly - # - def __init__(self, delegate) : - self.cb = delegate - - def propertyChange(self, e) : - self.cb(e) - -class UiDialog(swing.JDialog) : - - def __init__(self, widget, title="") : - swing.JDialog.__init__(self, swing.JOptionPane.getFrameForComponent(widget), 1) - - self.setTitle(title) - self.dlg_body = None - self.create_body() - - self.dlg_option_pane = swing.JOptionPane( \ - array(self.dlg_body, java.lang.Object), \ - self.get_type(), \ - self.get_options(), \ - self.get_icon(), \ - self.get_buttons(), \ - self.get_default()) - - self.setContentPane(self.dlg_option_pane) - self.setDefaultCloseOperation(swing.JDialog.DO_NOTHING_ON_CLOSE) - - self.dlg_option_pane.addPropertyChangeListener(DlgClick(self.dlg_click)) - - - self.pack() - self.setResizable(0) - self.show() - - def create_body(self) : - if self.dlg_body is None : - self.dlg_body = ["This is a dialog"] - - def get_type(self) : - return swing.JOptionPane.PLAIN_MESSAGE - - def get_options(self) : - return swing.JOptionPane.OK_CANCEL_OPTION - - def get_icon(self) : - return None - - def get_buttons(self) : - return ["Ok", "Cancel"] - - def get_default(self) : - return self.get_buttons()[0] - - def dlg_click(self, event) : - - prop = event.getPropertyName() - value = self.dlg_option_pane.getValue() - - # don't run after initialisation - if self.isVisible() and (event.getSource() == self.dlg_option_pane) \ - and (prop == swing.JOptionPane.VALUE_PROPERTY or prop == swing.JOptionPane.INPUT_VALUE_PROPERTY) : - - # reset for new input - if value == swing.JOptionPane.UNINITIALIZED_VALUE : - return - - self.dlg_option_pane.setValue(swing.JOptionPane.UNINITIALIZED_VALUE) - - if self.dlg_validate(value) : - self.dlg_make_result(value) - self.dispose() - - def dlg_validate(self, pressed) : - # return whether input is valid depending on pressed button - return 1 - - def dlg_make_result(self, pressed) : - # the result is read afterwards to figure out the outcome of the user input - if pressed == "Ok" : - self.result = 1 - else : - self.result = 0 Deleted: trunk/jython/bugtests/test237m2.py =================================================================== --- trunk/jython/bugtests/test237m2.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237m2.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,56 +0,0 @@ -import test237m1 -from javax import swing -from java import awt -import string - -class PSetNameDlg(test237m1.UiDialog) : - - def __init__(self, frame, label="Enter a name for the property set:", must_not_exist=1, must_exist=0) : - self.must_exist = must_exist - self.must_not_exist = must_not_exist - self.label_text = label - - test237m1.UiDialog.__init__(self, frame, title="property set name") - - def create_body(self) : - self.ps_name_input = swing.JTextField(10) - self.label_widget = swing.JLabel(self.label_text) - - - if self.dlg_body is None : - self.dlg_body = [self.label_widget, self.ps_name_input] - - - def dlg_validate(self, pressed) : - # check whether the name is correct - if pressed != "Ok" : - return 1 - - name = self.ps_name_input.getText() - - # comment this out for testing - #if len(name) < 1 : - # error = "A reasonbale name should at least have one character." - # test237m1.ErrorMsg(self, error) - # return 0 - #if self.must_not_exist : - # if conf.main.psb.find_property_set(name) is not None : - # error = "There is already a property set with this name." - # test237m1.ErrorMsg(self, error) - # return 0 - #if self.must_exist : - # if conf.main.psb.find_property_set(name) is None : - # error = "There is no property set with this name." - # test237m1.ErrorMsg(self, error) - # return 0 - # comment out until here - - - return 1 - - def dlg_make_result(self, pressed) : - # input value as result or None for cancel - if pressed != "Ok" : - self.result = None - else : - self.result = self.ps_name_input.getText() \ No newline at end of file Deleted: trunk/jython/bugtests/test238.py =================================================================== --- trunk/jython/bugtests/test238.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test238.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,43 +0,0 @@ -""" -Try reloading a javaclass located on sys.path. -""" - -import support -import java -import sys - -def mkspam(a): - f = open("test238p/test238j.java", "w") - f.write(""" -package test238p; -public class test238j { - public static String spam() { return "%s"; } - public static void %s() {} -} -""" % (a, a)) - f.close() - support.compileJava("test238p/test238j.java") - - -mkspam("foo") - -import test238p - -spam1 = test238p.test238j.spam() -support.compare(spam1, "foo") - -mkspam("bar") - -# -# Test removed. Reloading a java package is not supposed to work. -# -#reload(test238p) -#spam1 = test238p.test238j.spam() -#support.compare(spam1, "bar") -# -#mkspam("baz") -# -#reload(test238p) -#spam1 = test238p.test238j.spam() -#support.compare(spam1, "baz") - Deleted: trunk/jython/bugtests/test242.py =================================================================== --- trunk/jython/bugtests/test242.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test242.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test242c - -support.compileJPythonc("test242c.py", deep=1, output="test242.err") - -support.runJava("test242c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test242c.py =================================================================== --- trunk/jython/bugtests/test242c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test242c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,67 +0,0 @@ - -import support - -# list comprehension tests -nums = [1, 2, 3, 4, 5] -strs = ["Apple", "Banana", "Coconut"] -spcs = [" Apple", " Banana ", "Coco nut "] - -if [s.strip() for s in spcs] != ['Apple', 'Banana', 'Coco nut']: - raise support.TestError, "Wrong value #1" - -if [3 * x for x in nums] != [3, 6, 9, 12, 15]: - raise support.TestError, "Wrong value #2" - -if [x for x in nums if x > 2] != [3, 4, 5]: - raise support.TestError, "Wrong value #3" - -if len([(i, s) for i in nums for s in strs]) != len(nums) * len(strs): - raise support.TestError, "Wrong value #4" - -if [(i, s) for i in nums for s in [f for f in strs if "n" in f]] != [ - (1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Banana'), (5, 'Coconut')]: - raise support.TestError, "Wrong value #5" - - -try: - eval("[i, s for i in nums for s in strs]") - print "FAIL: should have raised a SyntaxError!" -except SyntaxError: - pass - -try: - eval("[x if y]") - print "FAIL: should have raised a SyntaxError!" -except SyntaxError: - pass - -suppliers = [ - (1, "Boeing"), - (2, "Ford"), - (3, "Macdonalds") -] - -parts = [ - (10, "Airliner"), - (20, "Engine"), - (30, "Cheeseburger") -] - -suppart = [ - (1, 10), (1, 20), (2, 20), (3, 30) -] - -l = [ - (sname, pname) - for (sno, sname) in suppliers - for (pno, pname) in parts - for (sp_sno, sp_pno) in suppart - if sno == sp_sno and pno == sp_pno -] - - -if l != [('Boeing', 'Airliner'), ('Boeing', 'Engine'), - ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]: - raise support.TestError, "Wrong value #6" Deleted: trunk/jython/bugtests/test245.py =================================================================== --- trunk/jython/bugtests/test245.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test245.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ - - -import support - -support.compileJava("test245j.java") - -#import test245j -#test245j.main([]) - -support.runJava("test245j", classpath=".") - Deleted: trunk/jython/bugtests/test245j.java =================================================================== --- trunk/jython/bugtests/test245j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test245j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,75 +0,0 @@ -import java.util.*; -import org.python.util.PythonInterpreter; -import org.python.core.*; -import java.lang.reflect.*; - -public abstract class test245j { - - public static test245j createPythonScriptClass( - String var[],String script,String name) { - StringTokenizer st=new StringTokenizer(script,"\n\r"); - - StringBuffer scr=new StringBuffer( - "import test245j\n"); - - scr.append("class PySS"); - scr.append(name); - scr.append("(test245j):\n def get(self,variables):\n"); - - for (int i=0;i<var.length;i++) { - scr.append(" "); - scr.append(var[i]); - scr.append("=variables["); - scr.append(i); - scr.append("]\n"); - } - - while (st.hasMoreTokens()) { - scr.append(" "); - scr.append(st.nextToken()); - scr.append("\n"); - } - scr.append(" return "); - scr.append(name); - scr.append("\nrr=PySS"); - scr.append(name); - scr.append("()\n\n"); - - String scriptString=scr.toString(); - -//System.out.println("------------------------\n"+scriptString+"------------------------\n"); - PythonInterpreter interp = new PythonInterpreter(); - interp.exec("import sys"); - interp.exec(scriptString); - - - Object pso = interp.get("rr",Object.class); -// System.out.println("pso class: "+pso.getClass().getName()); -// System.out.println("pso superclass:"+(pso.getClass()).getSuperclass().getName()); -// Method met[]=pso.getClass().getMethods(); -// for(int i=0;i<met.length;i++) -// System.out.println("Met: "+met[i]); - - test245j psc = null; - - psc =(test245j) pso; //<-------------------------------------------------------------------------EXCEPTION -// System.out.println(" psc class: "+psc.getClass().getName()); -// System.out.println(" psc superclass:"+(psc.getClass()).getSuperclass().getName()); - return psc; - } - - public double get(double variable[]) { - return 0.0; - }; - - public static void main(String args[]) throws Exception { - String names[]={"a","b"}; - double variables[]={1.0,2.0}; - String script="c = a + b"; - test245j psc=test245j.createPythonScriptClass(names,script,"c"); - double c=psc.get(variables); - if (c != 3.0) - throw new Exception("Wrong result"); - //System.out.println("C = "+c); - } -} Deleted: trunk/jython/bugtests/test246.py =================================================================== --- trunk/jython/bugtests/test246.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test246.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,35 +0,0 @@ - -import support - -support.compileJava("classes/test246p/test246j.java") - -support.compileJPythonc("test246c.py", package="test246p", output="test246.err") - - -# -# This will fuck up the remaining tests if this test is aborted midways. -# -import sys -sys.path[:0] = ["jpywork"] - -# make the test246 a package. Hmm. -open("jpywork/test246p/__init__.py", "w").close() - -from test246c import testStatic -#from test246p.test246c import testStatic - -v = testStatic.staticMethode('test') -if v != "staticMethode called in testStaticBase": - raise support.TestError, "wrong result #1: %s" % v - -t=testStatic() - -v = t.staticMethode('test') -if v != "staticMethode called in testStaticBase": - raise support.TestError, "wrong result #2: %s" % v - -v = t.notStaticMethode('test') -if v != "notStaticMethode is called in testStatic": - raise support.TestError, "wrong result #3: %s" % v - -del sys.path[0] Deleted: trunk/jython/bugtests/test246c.py =================================================================== --- trunk/jython/bugtests/test246c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test246c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,13 +0,0 @@ -import java -from test246p import test246j - -class testStatic(test246j): - def __init__(self): - #return "testStatic.__init__ is called" - pass - - def notStaticMethode(self,group): - return "notStaticMethode is called in testStatic" - -def staticMethode(group): - return "staticMethode is called in test246c" Deleted: trunk/jython/bugtests/te... [truncated message content] |
From: <zy...@us...> - 2008-12-29 08:33:26
|
Revision: 5806 http://jython.svn.sourceforge.net/jython/?rev=5806&view=rev Author: zyasoft Date: 2008-12-29 08:33:23 +0000 (Mon, 29 Dec 2008) Log Message: ----------- PySystemState (aka 'sys') now supports shadowing on builtins and warnoptions. Other non-final statics are now immutable from Jython (but shadowing could be readily extended to them). PyFile also supports an encoding, a 2.5 feature, that is used by ipython. Modified Paths: -------------- trunk/jython/Lib/test/test_sys_jy.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/exceptions.java trunk/jython/src/org/python/util/InteractiveConsole.java trunk/jython/src/org/python/util/jython.java Added Paths: ----------- trunk/jython/Lib/test/sys_jy_test_module.py Added: trunk/jython/Lib/test/sys_jy_test_module.py =================================================================== --- trunk/jython/Lib/test/sys_jy_test_module.py (rev 0) +++ trunk/jython/Lib/test/sys_jy_test_module.py 2008-12-29 08:33:23 UTC (rev 5806) @@ -0,0 +1,2 @@ +class Foobar(object): + pass Modified: trunk/jython/Lib/test/test_sys_jy.py =================================================================== --- trunk/jython/Lib/test/test_sys_jy.py 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/Lib/test/test_sys_jy.py 2008-12-29 08:33:23 UTC (rev 5806) @@ -62,8 +62,75 @@ reload(sys) self.assert_(type(sys.getdefaultencoding) == type(gde)) + +def exec_code_separately(function, sharing=False): + """Runs code in a separate context: (thread, PySystemState, PythonInterpreter) + + A PySystemState is used in conjunction with its thread + context. This is not so desirable - at the very least it means + that a thread pool cannot be shared. But this is not the place to + revisit ancient design decisions.""" + + def function_context(): + from org.python.core import Py + from org.python.util import PythonInterpreter + from org.python.core import PySystemState + + ps = PySystemState() + pi = PythonInterpreter({}, ps) + if not sharing: + ps.shadow() + ps.builtins = ps.builtins.copy() + pi.exec(function.func_code) + + import threading + context = threading.Thread(target=function_context) + context.start() + context.join() + + +def set_globally(): + import sys + import test.sys_jy_test_module # used as a probe + + # can't use 'foo', test_with wants to have that undefined + sys.builtins['test_sys_jy_foo'] = 42 + + +def set_shadow(): + import sys + sys.builtins['fum'] = 24 + +class ShadowingTest(unittest.TestCase): + + def setUp(self): + exec_code_separately(set_globally, sharing=True) + exec_code_separately(set_shadow) + + def test_super_globals(self): + import sys, __builtin__ + + def get_sym(sym): + return sys.builtins.get(sym) + def get_sym_attr(sym): + return hasattr(__builtin__, sym) + + self.assertEqual(test_sys_jy_foo, 42, "should be able to install a new builtin ('super global')") + self.assertEqual(get_sym('test_sys_jy_foo'), 42) + self.assertTrue(get_sym_attr('test_sys_jy_foo')) + + def is_fum_there(): fum + self.assertRaises(NameError, is_fum_there) # shadowed global ('fum') should not be visible + self.assertEqual(get_sym('fum'), None) + self.assertTrue(not(get_sym_attr('fum'))) + + def test_sys_modules_per_instance(self): + import sys + self.assertTrue('sys_jy_test_module' not in sys.modules, "sys.modules should be per PySystemState instance") + + def test_main(): - test.test_support.run_unittest(SysTest) + test.test_support.run_unittest(SysTest, ShadowingTest) if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/Py.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -1207,7 +1207,7 @@ } f = new PyFrame(tc, locals, globals, - PySystemState.builtins); + Py.getSystemState().getBuiltins()); return code.call(f); } Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/PyFile.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -42,6 +42,9 @@ @ExposedGet public String mode; + @ExposedGet + public String encoding; + /** Indicator dictating whether a space should be written to this * file on the next print statement (not currently implemented in * print ) */ Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -25,7 +25,8 @@ /** * The "sys" module. */ -// xxx this should really be a module! +// xxx Many have lamented, this should really be a module! +// but it will require some refactoring to see this wish come true. public class PySystemState extends PyObject { public static final String PYTHON_CACHEDIR = "python.cachedir"; @@ -38,8 +39,8 @@ private static final String JAR_URL_PREFIX = "jar:file:"; private static final String JAR_SEPARATOR = "!"; - public static PyString version = new PyString(Version.getVersion()); - public static int hexversion = ((Version.PY_MAJOR_VERSION << 24) | + public static final PyString version = new PyString(Version.getVersion()); + public static final int hexversion = ((Version.PY_MAJOR_VERSION << 24) | (Version.PY_MINOR_VERSION << 16) | (Version.PY_MICRO_VERSION << 8) | (Version.PY_RELEASE_LEVEL << 4) | @@ -52,8 +53,8 @@ /** * The copyright notice for this release. */ - // TBD: should we use \u00a9 Unicode c-inside-circle? - public static PyObject copyright = Py.newString( + + public static final PyObject copyright = Py.newString( "Copyright (c) 2000-2008, Jython Developers\n" + "All rights reserved.\n\n" + @@ -75,16 +76,24 @@ public static PyTuple builtin_module_names = null; public static PackageManager packageManager; - public static File cachedir; + private static File cachedir; private static PyList defaultPath; private static PyList defaultArgv; private static PyObject defaultExecutable; + // XXX - from Jython code, these statics are immutable; we may wish to consider + // using the shadowing mechanism for them as well if in practice it makes + // sense for them to be changed public static Properties registry; // = init_registry(); public static PyObject prefix; public static PyObject exec_prefix = Py.EmptyString; + public static PyString platform = new PyString("java"); + public static final PyString byteorder = new PyString("big"); + public static final int maxint = Integer.MAX_VALUE; + public static final int minint = Integer.MIN_VALUE; + private static boolean initialized = false; /** The arguments passed to this program on the command line. */ @@ -92,25 +101,20 @@ public PyObject modules; public PyList path; + + // shadowed statics - don't use directly + public static PyList warnoptions = new PyList(); public static PyObject builtins; public PyList meta_path; public PyList path_hooks; public PyObject path_importer_cache; - public static PyString platform = new PyString("java"); - public static PyString byteorder = new PyString("big"); - public PyObject ps1 = new PyString(">>> "); public PyObject ps2 = new PyString("... "); - - public static int maxint = Integer.MAX_VALUE; - public static int minint = Integer.MIN_VALUE; - + public PyObject executable; - public static PyList warnoptions; - private String currentWorkingDir; private PyObject environ; @@ -153,18 +157,24 @@ // Set up the initial standard ins and outs String mode = Options.unbuffered ? "b" : ""; int buffering = Options.unbuffered ? 0 : 1; - __stdout__ = stdout = new PyFile(System.out, "<stdout>", "w" + mode, buffering, false); - __stderr__ = stderr = new PyFile(System.err, "<stderr>", "w" + mode, 0, false); - __stdin__ = stdin = new PyFile(System.in, "<stdin>", "r" + mode, buffering, false); + stdout = new PyFile(System.out, "<stdout>", "w" + mode, buffering, false); + stderr = new PyFile(System.err, "<stderr>", "w" + mode, 0, false); + stdin = new PyFile(System.in, "<stdin>", "r" + mode, buffering, false); __displayhook__ = new PySystemStateFunctions("displayhook", 10, 1, 1); __excepthook__ = new PySystemStateFunctions("excepthook", 30, 3, 3); - if(builtins == null){ - builtins = new PyStringMap(); - __builtin__.fillWithBuiltins(builtins); + String encoding = registry.getProperty("python.console.encoding", "US-ASCII"); + ((PyFile)stdout).encoding = encoding; + ((PyFile)stderr).encoding = encoding; + ((PyFile)stdin).encoding = encoding; + __stdout__ = stdout; + __stderr__ = stderr; + __stdin__ = stdin; + + if (builtins == null) { + builtins = getDefaultBuiltins(); } - PyModule __builtin__ = new PyModule("__builtin__", builtins); - modules.__setitem__("__builtin__", __builtin__); + modules.__setitem__("__builtin__", new PyModule("__builtin__", getDefaultBuiltins())); __dict__ = new PyStringMap(); __dict__.invoke("update", getType().fastGetDict()); __dict__.__setitem__("displayhook", __displayhook__); @@ -175,56 +185,150 @@ __dict__.invoke("update", getType().fastGetDict()); } + private static void checkReadOnly(String name) { + if (name == "__dict__" || + name == "__class__" || + name == "registry" || + name == "exec_prefix" || + name == "platform" || + name == "packageManager") { + throw Py.TypeError("readonly attribute"); + } + } + + private static void checkMustExist(String name) { + if (name == "__dict__" || + name == "__class__" || + name == "registry" || + name == "exec_prefix" || + name == "platform" || + name == "packageManager" || + name == "builtins" || + name == "warnoptions") { + throw Py.TypeError("readonly attribute"); + } + } + + // might be nice to have something general here, but for now these + // seem to be the only values that need to be explicitly shadowed + private Shadow shadowing; + public synchronized void shadow() { + if (shadowing == null) { + shadowing = new Shadow(); + } + } + + private static class DefaultBuiltinsHolder { + static final PyObject builtins = fillin(); + + static PyObject fillin() { + PyObject temp = new PyStringMap(); + __builtin__.fillWithBuiltins(temp); + return temp; + } + } + + public static PyObject getDefaultBuiltins() { + return DefaultBuiltinsHolder.builtins; + } + + public synchronized PyObject getBuiltins() { + if (shadowing == null) { + return getDefaultBuiltins(); + } + else { + return shadowing.builtins; + } + } + + public synchronized void setBuiltins(PyObject value) { + if (shadowing == null) { + builtins = value; + } else { + shadowing.builtins = value; + } + modules.__setitem__("__builtin__", new PyModule("__builtin__", value)); + } + + public synchronized PyObject getWarnoptions() { + if (shadowing == null) { + return warnoptions; + } + else { + return shadowing.warnoptions; + } + } + + public synchronized void setWarnoptions(PyObject value) { + if (shadowing == null) { + warnoptions = new PyList(value); + } else { + shadowing.warnoptions = new PyList(value); + } + } + // xxx fix this accessors public PyObject __findattr_ex__(String name) { if (name == "exc_value") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.value; - } - if (name == "exc_type") { + } else if (name == "exc_type") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.type; - } - if (name == "exc_traceback") { + } else if (name == "exc_traceback") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.traceback; - } - if (name == "warnoptions") { - if (warnoptions == null) - warnoptions = new PyList(); - return warnoptions; - } + } else if (name == "warnoptions") { + return getWarnoptions(); + } else if (name == "builtins") { + return getBuiltins(); + } else { + PyObject ret = super.__findattr_ex__(name); + if (ret != null) { + if (ret instanceof PyMethod) { + if (__dict__.__finditem__(name) instanceof PyReflectedFunction) { + return ret; // xxx depends on nonstandard __dict__ + } + } else if (ret == PyAttributeDeleted.INSTANCE) { + return null; + } else { + return ret; + } + } - PyObject ret = super.__findattr_ex__(name); - if (ret != null) { - if (ret instanceof PyMethod) { - if (__dict__.__finditem__(name) instanceof PyReflectedFunction) - return ret; // xxx depends on nonstandard __dict__ - } else if (ret == PyAttributeDeleted.INSTANCE) { - return null; - } - else return ret; + return __dict__.__finditem__(name); } - - return __dict__.__finditem__(name); } public void __setattr__(String name, PyObject value) { - if (name == "__dict__" || name == "__class__") - throw Py.TypeError("readonly attribute"); - PyObject ret = getType().lookup(name); // xxx fix fix fix - if (ret != null && ret.jtryset(this, value)) { - return; + checkReadOnly(name); + if (name == "builtins") { + shadow(); + setBuiltins(value); } - __dict__.__setitem__(name, value); + else if (name == "warnoptions") { + shadow(); + setWarnoptions(value); + } else { + PyObject ret = getType().lookup(name); // xxx fix fix fix + if (ret != null && ret.jtryset(this, value)) { + return; + } + __dict__.__setitem__(name, value); + } } public void __delattr__(String name) { - if (name == "__dict__" || name == "__class__") - throw Py.TypeError("readonly attribute"); + checkMustExist(name); PyObject ret = getType().lookup(name); // xxx fix fix fix if (ret != null) { ret.jtryset(this, PyAttributeDeleted.INSTANCE); @@ -233,7 +337,7 @@ __dict__.__delitem__(name); } catch (PyException pye) { // KeyError if (ret == null) { - throw Py.AttributeError(name); + throw Py.AttributeError(name); } } } @@ -558,7 +662,7 @@ Py.setSystemState(Py.defaultSystemState); if (classLoader != null) Py.defaultSystemState.setClassLoader(classLoader); - Py.initClassExceptions(PySystemState.builtins); + Py.initClassExceptions(getDefaultBuiltins()); // Make sure that Exception classes have been loaded new PySyntaxError("", 1, 1, "", ""); } @@ -888,9 +992,10 @@ if (o == Py.None) return; - PySystemState.builtins.__setitem__("_", Py.None); + PyObject currentBuiltins = Py.getSystemState().getBuiltins(); + currentBuiltins.__setitem__("_", Py.None); Py.stdout.println(o.__repr__()); - PySystemState.builtins.__setitem__("_", o); + currentBuiltins.__setitem__("_", o); } static void excepthook(PyObject type, PyObject val, PyObject tb) { @@ -987,3 +1092,13 @@ return null; } } + +class Shadow { + PyObject builtins; + PyList warnoptions; + + Shadow() { + builtins = PySystemState.getDefaultBuiltins(); + warnoptions = PySystemState.warnoptions; + } +} \ No newline at end of file Modified: trunk/jython/src/org/python/core/exceptions.java =================================================================== --- trunk/jython/src/org/python/core/exceptions.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/exceptions.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -36,7 +36,7 @@ if (frame.f_back != null) { frame.f_builtins = frame.f_back.f_builtins; } else { - frame.f_builtins = PySystemState.builtins; + frame.f_builtins = PySystemState.getDefaultBuiltins(); } } ts.frame = frame; Modified: trunk/jython/src/org/python/util/InteractiveConsole.java =================================================================== --- trunk/jython/src/org/python/util/InteractiveConsole.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/util/InteractiveConsole.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -46,7 +46,7 @@ return Py.newString(raw_input(prompt)); } }; - PySystemState.builtins.__setitem__("raw_input", newRawInput); + Py.getSystemState().getBuiltins().__setitem__("raw_input", newRawInput); } } Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/util/jython.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -137,10 +137,11 @@ // Now create an interpreter InteractiveConsole interp = newInterpreter(); - PySystemState.warnoptions = new PyList(); + PyList warnoptions = new PyList(); for (String wopt : opts.warnoptions) { - PySystemState.warnoptions.append(new PyString(wopt)); + warnoptions.append(new PyString(wopt)); } + Py.getSystemState().setWarnoptions(warnoptions); // Decide if stdin is interactive if (!opts.fixInteractive && opts.interactive) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-29 22:39:05
|
Revision: 5810 http://jython.svn.sourceforge.net/jython/?rev=5810&view=rev Author: pjenvey Date: 2008-12-29 22:38:59 +0000 (Mon, 29 Dec 2008) Log Message: ----------- move test389 to test_traceback_jy, add a new currently failing traceback test Added Paths: ----------- trunk/jython/Lib/test/test_traceback_jy.py Removed Paths: ------------- trunk/jython/bugtests/test389.py Added: trunk/jython/Lib/test/test_traceback_jy.py =================================================================== --- trunk/jython/Lib/test/test_traceback_jy.py (rev 0) +++ trunk/jython/Lib/test/test_traceback_jy.py 2008-12-29 22:38:59 UTC (rev 5810) @@ -0,0 +1,69 @@ +"""Misc traceback tests + +Made for Jython. +""" +import sys +import traceback +import unittest +from test import test_support + +if test_support.is_jython: + from java.awt import EventQueue + from java.lang import Runnable + +class TracebackTestCase(unittest.TestCase): + + def test_tb_across_threads(self): + if not test_support.is_jython: + return + + # http://bugs.jython.org/issue1533624 + class PyRunnable(Runnable): + def run(self): + raise TypeError('this is only a test') + try: + EventQueue.invokeAndWait(PyRunnable()) + except TypeError: + # XXX: + """ + self.assertEqual(tb_info(), + [('test_tb_across_threads', + 'EventQueue.invokeAndWait(PyRunnable())'), + ('run', + "raise TypeError('this is only a test')")]) + """ + else: + self.fail('Expected TypeError') + + def _test_reraise(self): + def raiser(): + raise Exception(), None, tb + try: + # Jython previously added raiser's frame to the traceback + raiser() + except Exception: + self.assertEqual(tb_info(), + [('test_reraise', 'raiser()'), + ('<module>', "raise Exception('foo')")]) + + else: + self.fail('Expected Exception') + + +try: + raise Exception('foo') +except Exception: + tb = sys.exc_info()[2] + + +def tb_info(): + # [2:] ignores filename/lineno + return [info[2:] for info in traceback.extract_tb(sys.exc_info()[2])] + + +def test_main(): + test_support.run_unittest(TracebackTestCase) + + +if __name__ == '__main__': + test_main() Deleted: trunk/jython/bugtests/test389.py =================================================================== --- trunk/jython/bugtests/test389.py 2008-12-29 17:26:45 UTC (rev 5809) +++ trunk/jython/bugtests/test389.py 2008-12-29 22:38:59 UTC (rev 5810) @@ -1,20 +0,0 @@ -''' -Test for Bug #1533624. A call that crosses threads causes a null pointer -exception when building a traceback. If it reappears instead of the -TypeError showing up a null pointer exception will be thrown. -''' - -from java.awt import EventQueue -from java.lang import Runnable - -class PyRunnable(Runnable): - def run(self): - raise TypeError, 'this is only a test' - -def g(): - EventQueue.invokeAndWait(PyRunnable()) - -try: - g() -except TypeError: - pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-29 23:59:05
|
Revision: 5812 http://jython.svn.sourceforge.net/jython/?rev=5812&view=rev Author: cgroves Date: 2008-12-29 23:59:02 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Try the current thread's context class loader instead of using Class.forName. Fixes issue1216. The implementation differs from the patch in that it tries SyspathJavaLoader before going to the context class loader so java classes can still be found on sys.path. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/compiler/ProxyMaker.java trunk/jython/src/org/python/compiler/ScopeInfo.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/SyspathJavaLoader.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-29 23:59:02 UTC (rev 5812) @@ -8,8 +8,8 @@ from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import (Boolean, ExceptionInInitializerError, Integer, Object, String, Runnable, - Thread, ThreadGroup, System, Runtime, Math, Byte) +from java.lang import (Boolean, ClassLoader, ExceptionInInitializerError, Integer, Object, String, + Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath from java.math import BigDecimal @@ -55,6 +55,49 @@ pass A() +""" +public abstract class ContextAbstract { + public ContextAbstract() { + method(); + } + + public abstract void method(); +} +""" +# The following is the correspoding bytecode for ContextAbstract compiled with javac 1.5 +# Needs to be named differently than Abstract above so the class loader won't just use it +CONTEXT_ABSTRACT = '''\ +eJxdjr1uwjAUhc8lbgIh/AVegA0YQJ1BlRBSp6gdWrE7wQKjEEvBVH0tFip14AF4KMQ17YSHc3yu +vuPry/X3DOAZ3RACrRAe2gE6AWKCP9OFti8EbzBcEsTCrBShlehCvR12qSo/ZZrzJE5MJvOlLLXL +/0NhN3pP6CQLU1j1befp3pYys1N+d6fsxqwI4Yc5lJl61a7QewDHW/klIzzBjxDB58UPAKHtkEku +i/XkPd2qzIo+/1/AnQrIdVkDTlN2Yq+NfkCjEyrHO1JlbXLF3QV7lbXGKfqDEaIOCHL7ORMad7J5 +A7yvPDQ= +'''.decode('base64').decode('zlib') +class ContextClassloaderTest(unittest.TestCase): + '''Classes on the context classloader should be importable and subclassable. + + http://bugs.jython.org/issue1216''' + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + class AbstractLoader(ClassLoader): + def __init__(self): + ClassLoader.__init__(self) + c = self.super__defineClass("ContextAbstract", CONTEXT_ABSTRACT, 0, + len(CONTEXT_ABSTRACT), ClassLoader.protectionDomain) + self.super__resolveClass(c) + Thread.currentThread().contextClassLoader = AbstractLoader() + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + + def test_can_subclass_abstract(self): + import ContextAbstract + + class A(ContextAbstract): + def method(self): + pass + A() + class InstantiationTest(unittest.TestCase): def test_can_subclass_abstract(self): class A(Component): @@ -470,6 +513,7 @@ def test_main(): test_support.run_unittest(AbstractOnSyspathTest, + ContextClassloaderTest, InstantiationTest, BeanTest, ExtendJavaTest, Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -670,7 +670,7 @@ } public void addClassDictInit() throws Exception { - int n = supernames.size(); + supernames.size(); // classDictInit method classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); Modified: trunk/jython/src/org/python/compiler/ScopeInfo.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -125,7 +125,7 @@ public int jy_npurecell; public int cell, distance; - + public ScopeInfo up; //Resolve the names used in the given scope, and mark any freevars used in the up scope @@ -188,7 +188,7 @@ names.addElement(purecells.elementAt(i)); } } - + if (some_free && nested) { up.contains_ns_free_vars = true; } @@ -202,23 +202,25 @@ } - private void dynastuff_trouble(boolean inner_free, - CompilationContext ctxt) throws Exception { - String illegal; - if (unqual_exec && from_import_star) - illegal = "function '"+scope_name+ - "' uses import * and bare exec, which are illegal"; - else if (unqual_exec) - illegal = "unqualified exec is not allowed in function '"+ - scope_name+"'"; - else - illegal = "import * is not allowed in function '"+scope_name+"'"; - String why; - if (inner_free) - why = " because it contains a function with free variables"; - else - why = " because it contains free variables"; - ctxt.error(illegal + why, true, scope_node); + private void dynastuff_trouble(boolean inner_free, CompilationContext ctxt) throws Exception { + StringBuilder illegal = new StringBuilder(); + if (unqual_exec && from_import_star) { + illegal.append("function '") + .append(scope_name) + .append("' uses import * and bare exec, which are illegal"); + } else if (unqual_exec) { + illegal.append("unqualified exec is not allowed in function '") + .append(scope_name) + .append("'"); + } else { + illegal.append("import * is not allowed in function '").append(scope_name).append("'"); + } + if (inner_free) { + illegal.append(" because it contains a function with free variables"); + } else { + illegal.append(" because it contains free variables"); + } + ctxt.error(illegal.toString(), true, scope_node); } public Vector freevars = new Vector(); @@ -230,7 +232,7 @@ public void setup_closure() { setup_closure(up); } - + /** * setup the closure on this scope using the passed in scope. This is used * by jythonc to setup its closures. Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/core/Py.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -761,11 +761,15 @@ secEnv = true; } if (classLoader != null) { - return classLoader.loadClass(name); + try { + return classLoader.loadClass(name); + } catch (ClassNotFoundException cnfe) { + // let the context classloader try + } } } - return Class.forName(name); + return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (ClassNotFoundException e) { // e.printStackTrace(); @@ -797,13 +801,17 @@ if (classLoader != null) { writeDebug("import", "trying " + name + " as " + reason + " in syspath loader"); - return classLoader.loadClass(name); + try { + return classLoader.loadClass(name); + } catch (ClassNotFoundException cnfe) { + // let the context classloader try + } } } writeDebug("import", "trying " + name + " as " + reason + " in Class.forName"); - return Class.forName(name); + return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (ClassNotFoundException e) { return null; } catch (IllegalArgumentException e) { Modified: trunk/jython/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/jython/src/org/python/core/SyspathJavaLoader.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/core/SyspathJavaLoader.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -17,7 +17,7 @@ public class SyspathJavaLoader extends ClassLoader { private static final char SLASH_CHAR = '/'; - + public InputStream getResourceAsStream(String res) { Py.writeDebug("resource", "trying resource: " + res); PySystemState sys = Py.getSystemState(); @@ -26,7 +26,7 @@ return classLoader.getResourceAsStream(res); } - classLoader = this.getClass().getClassLoader(); + classLoader = Thread.currentThread().getContextClassLoader(); InputStream ret; @@ -47,7 +47,7 @@ res = res.replace(SLASH_CHAR, File.separatorChar); entryRes = entryRes.replace(File.separatorChar, SLASH_CHAR); } - + PyList path = sys.path; for (int i = 0; i < path.__len__(); i++) { PyObject entry = path.__getitem__(i); @@ -85,23 +85,23 @@ if (classLoader != null) { return classLoader.loadClass(name); } - + // Search the sys.path for a .class file matching the named class. try { return Class.forName(name); } catch(ClassNotFoundException e) {} - + // The current class loader may be null (e.g., when Jython is loaded // from the boot classpath); try the system class loader. try { return Class.forName(name, true, ClassLoader.getSystemClassLoader()); } catch(ClassNotFoundException e) {} - + Class c = findLoadedClass(name); if(c != null) { return c; } - + PyList path = sys.path; for(int i = 0; i < path.__len__(); i++) { InputStream fis = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-30 07:12:03
|
Revision: 5815 http://jython.svn.sourceforge.net/jython/?rev=5815&view=rev Author: pjenvey Date: 2008-12-30 07:11:59 +0000 (Tue, 30 Dec 2008) Log Message: ----------- o fix mishandling of tracebacks during re-raises. they're now special cased when PyException.isReRaise (analogous to CPython's why == WHY_RERAISE) is true o expose PyTraceback Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/Lib/test/test_traceback_jy.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyException.java trunk/jython/src/org/python/core/PyTableCode.java trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/CoreExposed.includes 2008-12-30 07:11:59 UTC (rev 5815) @@ -34,6 +34,7 @@ org/python/core/PyStaticMethod.class org/python/core/PyString.class org/python/core/PySuper.class +org/python/core/PyTraceback.class org/python/core/PyTuple.class org/python/core/PyType.class org/python/core/PyUnicode.class Modified: trunk/jython/Lib/test/test_traceback_jy.py =================================================================== --- trunk/jython/Lib/test/test_traceback_jy.py 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/Lib/test/test_traceback_jy.py 2008-12-30 07:11:59 UTC (rev 5815) @@ -24,18 +24,15 @@ try: EventQueue.invokeAndWait(PyRunnable()) except TypeError: - # XXX: - """ self.assertEqual(tb_info(), [('test_tb_across_threads', 'EventQueue.invokeAndWait(PyRunnable())'), ('run', "raise TypeError('this is only a test')")]) - """ else: self.fail('Expected TypeError') - def _test_reraise(self): + def test_reraise(self): def raiser(): raise Exception(), None, tb try: Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/Py.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -1113,28 +1113,15 @@ /* Helpers to implement finally clauses */ public static void addTraceback(Throwable t, PyFrame frame) { - PyException e = Py.JavaError(t); - - //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame && e.traceback.tb_frame.f_back != null) { - e.traceback = new PyTraceback(e.traceback); - } + Py.JavaError(t).tracebackHere(frame, true); } /* Helpers to implement except clauses */ public static PyException setException(Throwable t, PyFrame frame) { PyException pye = Py.JavaError(t); pye.normalize(); - - // attach catching frame - if (frame != null && pye.traceback.tb_frame != frame && pye.traceback.tb_frame.f_back != null) { - pye.traceback = new PyTraceback(pye.traceback); - } - - ThreadState ts = getThreadState(); - - ts.exception = pye; - + pye.tracebackHere(frame); + getThreadState().exception = pye; return pye; } Modified: trunk/jython/src/org/python/core/PyException.java =================================================================== --- trunk/jython/src/org/python/core/PyException.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyException.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -20,8 +20,15 @@ */ public PyObject value = Py.None; + /** The exception traceback object. */ public PyTraceback traceback; + /** + * Whether the exception was re-raised, such as when a traceback is specified to + * 'raise', or via a 'finally' block. + */ + private boolean isReRaise = false; + private boolean normalized = false; public PyException() { @@ -39,17 +46,9 @@ public PyException(PyObject type, PyObject value, PyTraceback traceback) { this.type = type; this.value = value; - if (traceback != null) { this.traceback = traceback; - } else { - PyFrame frame = Py.getFrame(); - if (frame != null) { - this.traceback = new PyTraceback(frame); - if (frame.tracefunc != null) { - frame.tracefunc = frame.tracefunc.traceException(frame, this); - } - } + isReRaise = true; } } @@ -133,6 +132,32 @@ } /** + * Register frame as having been visited in the traceback. + * + * @param here the current PyFrame + */ + public void tracebackHere(PyFrame here) { + tracebackHere(here, false); + } + + /** + * Register frame as having been visited in the traceback. + * + * @param here the current PyFrame + * @param isFinally whether caller is a Python finally block + */ + public void tracebackHere(PyFrame here, boolean isFinally) { + if (!isReRaise && here != null) { + // the frame is either inapplicable or already registered (from a finally) + // during a re-raise + traceback = new PyTraceback(traceback, here); + } + // finally blocks immediately tracebackHere: so they toggle isReRaise to skip the + // next tracebackHere hook + isReRaise = isFinally; + } + + /** * Logic for the raise statement * * @param type the first arg to raise, a type or an instance @@ -185,6 +210,7 @@ throw Py.TypeError("exceptions must be classes, instances, or strings (deprecated), " + "not " + type.getType().fastGetName()); } + return new PyException(type, value, (PyTraceback)traceback); } @@ -202,7 +228,7 @@ return false; } PyType type = ((PyType)obj); - if(type.isSubType((PyType)Py.BaseException)){ + if (type.isSubType(PyBaseException.TYPE)) { return true; } return type.getProxyType() != null && Throwable.class.isAssignableFrom(type.getProxyType()); Modified: trunk/jython/src/org/python/core/PyTableCode.java =================================================================== --- trunk/jython/src/org/python/core/PyTableCode.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyTableCode.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -198,37 +198,23 @@ try { ret = funcs.call_function(func_id, frame); } catch (Throwable t) { - //t.printStackTrace(); - //Convert exceptions that occured in Java code to PyExceptions - PyException e = Py.JavaError(t); + // Convert exceptions that occured in Java code to PyExceptions + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); - //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame) { - PyTraceback tb; - // If f_back is null, we've jumped threads so use the current - // threadstate's frame. Bug #1533624 - if(e.traceback.tb_frame.f_back == null) { - tb = new PyTraceback(ts.frame); - } else { - tb = new PyTraceback(e.traceback.tb_frame.f_back); - } - tb.tb_next = e.traceback; - e.traceback = tb; - } - frame.f_lasti = -1; if (frame.tracefunc != null) { - frame.tracefunc.traceException(frame, e); + frame.tracefunc.traceException(frame, pye); } if (ts.profilefunc != null) { - ts.profilefunc.traceException(frame, e); + ts.profilefunc.traceException(frame, pye); } - //Rethrow the exception to the next stack frame + // Rethrow the exception to the next stack frame ts.exception = previous_exception; ts.frame = ts.frame.f_back; - throw e; + throw pye; } if (frame.tracefunc != null) { Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -2,33 +2,32 @@ package org.python.core; import org.python.core.util.RelativeFile; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedType; /** * A python traceback object. */ -// XXX: isBaseType = false -public class PyTraceback extends PyObject -{ +@ExposedType(name = "traceback", isBaseType = false) +public class PyTraceback extends PyObject { + + public static final PyType TYPE = PyType.fromClass(PyTraceback.class); + + @ExposedGet public PyObject tb_next; + + @ExposedGet public PyFrame tb_frame; + + @ExposedGet public int tb_lineno; - public PyTraceback(PyFrame frame) { + public PyTraceback(PyTraceback next, PyFrame frame) { + tb_next = next; tb_frame = frame; - if (tb_frame != null) { - tb_lineno = tb_frame.getline(); - } - tb_next = Py.None; + tb_lineno = frame.getline(); } - public PyTraceback(PyTraceback next) { - tb_next = next; - if (next != null) { - tb_frame = next.tb_frame.f_back; - tb_lineno = tb_frame.getline(); - } - } - private String tracebackInfo() { if (tb_frame == null || tb_frame.f_code == null) { return String.format(" (no code object) at line %s\n", tb_lineno); @@ -103,7 +102,7 @@ public void dumpStack(StringBuilder buf) { buf.append(tracebackInfo()); - if (tb_next != Py.None && tb_next != this) { + if (tb_next != null && tb_next != this) { ((PyTraceback)tb_next).dumpStack(buf); } else if (tb_next == this) { buf.append("circularity detected!"+this+tb_next); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-30 08:17:09
|
Revision: 5816 http://jython.svn.sourceforge.net/jython/?rev=5816&view=rev Author: cgroves Date: 2008-12-30 08:17:05 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Break the suffix ordering and module creation parts out of zipimporter into a new class, importer, and use that as the base class of a PEP-302 hook to import py and $py.class files off the classpath, ClasspathPyImporter. Like the JavaImporter, it triggers off a special entry in sys.path -- __pyclasspath__ in this case. Anything past __pyclasspath__/ in the sys.path entry is treated as a prefix, and modules are loaded below that. Add a default __pyclasspath__/ entry to sys.path to get py files directly on the classpath. This fixes issue1181, issue1747126 and possibly issue1108. Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/Lib/site.py trunk/jython/src/org/python/core/JavaImporter.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/modules/imp.java trunk/jython/src/org/python/modules/zipimport/zipimport.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Added Paths: ----------- trunk/jython/Lib/test/classimport.jar trunk/jython/Lib/test/classimport_Lib.jar trunk/jython/Lib/test/test_classpathimporter.py trunk/jython/src/org/python/core/ClasspathPyImporter.java trunk/jython/src/org/python/core/util/importer.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/CoreExposed.includes 2008-12-30 08:17:05 UTC (rev 5816) @@ -1,4 +1,5 @@ org/python/core/AstList.class +org/python/core/ClasspathPyImporter.class org/python/core/PyArray.class org/python/core/PyBaseString.class org/python/core/PyBaseException.class Modified: trunk/jython/Lib/site.py =================================================================== --- trunk/jython/Lib/site.py 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/Lib/site.py 2008-12-30 08:17:05 UTC (rev 5816) @@ -65,7 +65,7 @@ def makepath(*paths): dir = os.path.join(*paths) - if dir == '__classpath__': + if dir == '__classpath__' or dir.startswith('__pyclasspath__'): return dir, dir dir = os.path.abspath(dir) return dir, os.path.normcase(dir) Added: trunk/jython/Lib/test/classimport.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/classimport.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/Lib/test/classimport_Lib.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/classimport_Lib.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/Lib/test/test_classpathimporter.py =================================================================== --- trunk/jython/Lib/test/test_classpathimporter.py (rev 0) +++ trunk/jython/Lib/test/test_classpathimporter.py 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,45 @@ +import unittest +import sys +from test import test_support +from java.io import File +from java.lang import Thread +from java.net import URLClassLoader + +class ClasspathImporterTestCase(unittest.TestCase): + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + self.orig_path = sys.path + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + sys.path = self.orig_path + try: + del sys.modules['flat_in_jar'] + del sys.modules['jar_pkg'] + del sys.modules['jar_pkg.prefer_compiled'] + except KeyError: + pass + + def setClassLoaderAndCheck(self, jar): + url = File(test_support.findfile(jar)).toURL() + Thread.currentThread().contextClassLoader = URLClassLoader([url]) + import flat_in_jar + self.assertEquals(flat_in_jar.value, 7) + import jar_pkg + from jar_pkg import prefer_compiled + self.assert_(prefer_compiled.compiled) + self.assertRaises(NameError, __import__, 'flat_bad') + self.assertRaises(NameError, __import__, 'jar_pkg.bad') + + def test_default_pyclasspath(self): + self.setClassLoaderAndCheck("classimport.jar") + + def test_path_in_pyclasspath(self): + sys.path = ['__pyclasspath__/Lib'] + self.setClassLoaderAndCheck("classimport_Lib.jar") + +def test_main(): + test_support.run_unittest(ClasspathImporterTestCase) + +if __name__ == '__main__': + test_main() Added: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java (rev 0) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,125 @@ +package org.python.core; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import org.python.core.util.importer; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; +import org.python.util.Generic; + +@ExposedType(name="ClasspathPyImporter") +public class ClasspathPyImporter extends importer<String> { + + public static final String PYCLASSPATH_PREFIX = "__pyclasspath__/"; + public static final PyType TYPE = PyType.fromClass(ClasspathPyImporter.class); + + public ClasspathPyImporter(PyType subType) { + super(subType); + } + + public ClasspathPyImporter() { + super(); + } + + @ExposedNew + @ExposedMethod + final void ClasspathPyImporter___init__(PyObject[] args, String[] kwds) { + ArgParser ap = new ArgParser("__init__", args, kwds, new String[] {"path"}); + String path = ap.getString(0); + if (path == null || !path.startsWith(PYCLASSPATH_PREFIX)) { + throw Py.ImportError("path isn't for classpath importer"); + } + if (!path.endsWith("/")) { + path += "/"; + } + this.path = path; + } + + /** + * Find the module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @param path if not installed on the meta-path None or a module path + * @return a loader instance if this importer can load the module, None + * otherwise + */ + @ExposedMethod(defaults = "null") + final PyObject ClasspathPyImporter_find_module(String fullname, String path) { + return importer_find_module(fullname, path); + } + + /** + * Load a module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @return a loaded PyModule + */ + @ExposedMethod + final PyObject ClasspathPyImporter_load_module(String fullname) { + return importer_load_module(fullname); + } + + @Override + protected boolean isAcceptableBytecode(String searchPath, String entry) { + return true; + } + + @Override + protected Bundle makeBundle(String fullFilename, String entry) { + InputStream is = entries.remove(entry); + return new Bundle(is) { + @Override + public void close() { + try { + inputStream.close(); + } catch (IOException e) { + throw Py.JavaError(e); + } + } + }; + } + + @Override + protected String makeEntry(String fullFilename) { + if (entries.containsKey(fullFilename)) { + return fullFilename; + } + InputStream is = null; + ClassLoader classLoader = Py.getSystemState().getClassLoader(); + if (classLoader != null) { + Py.writeDebug("import", "trying " + fullFilename + " in sys class loader"); + is = classLoader.getResourceAsStream(fullFilename); + } + if (is == null) { + Py.writeDebug("import", "trying " + fullFilename + " in context class loader"); + is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullFilename); + } + if (is != null) { + entries.put(fullFilename, is); + return fullFilename; + } + return null; + } + + @Override + protected String makeFilename(String fullname) { + return path.replace(PYCLASSPATH_PREFIX, "") + fullname.replace('.', '/'); + } + + @Override + protected String makePkgPath(String fullname) { + return path; + } + + @Override + protected String getSeparator() { + return "/"; + } + + private Map<String, InputStream> entries = Generic.map(); + + private String path; +} Modified: trunk/jython/src/org/python/core/JavaImporter.java =================================================================== --- trunk/jython/src/org/python/core/JavaImporter.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/core/JavaImporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -5,12 +5,10 @@ */ public class JavaImporter extends PyObject { - public JavaImporter() { - super(); - } - + public static final String JAVA_IMPORT_PATH_ENTRY = "__classpath__"; + public PyObject __call__(PyObject args[], String keywords[]) { - if(args[0].toString().endsWith("__classpath__")){ + if(args[0].toString().endsWith(JAVA_IMPORT_PATH_ENTRY)){ return this; } throw Py.ImportError("unable to handle"); @@ -18,7 +16,7 @@ /** * Find the module for the fully qualified name. - * + * * @param name the fully qualified name of the module * @return a loader instance if this importer can load the module, None * otherwise @@ -29,7 +27,7 @@ /** * Find the module for the fully qualified name. - * + * * @param name the fully qualified name of the module * @param path if installed on the meta-path None or a module path * @return a loader instance if this importer can load the module, None @@ -52,7 +50,7 @@ /** * Returns a string representation of the object. - * + * * @return a string representation of the object. */ public String toString() { Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -93,7 +93,7 @@ public static final PyString byteorder = new PyString("big"); public static final int maxint = Integer.MAX_VALUE; public static final int minint = Integer.MIN_VALUE; - + private static boolean initialized = false; /** The arguments passed to this program on the command line. */ @@ -101,7 +101,7 @@ public PyObject modules; public PyList path; - + // shadowed statics - don't use directly public static PyList warnoptions = new PyList(); public static PyObject builtins; @@ -112,7 +112,7 @@ public PyObject ps1 = new PyString(">>> "); public PyObject ps2 = new PyString("... "); - + public PyObject executable; private String currentWorkingDir; @@ -142,13 +142,15 @@ argv = (PyList)defaultArgv.repeat(1); path = (PyList)defaultPath.repeat(1); - path.append(Py.newString("__classpath__")); + path.append(Py.newString(JavaImporter.JAVA_IMPORT_PATH_ENTRY)); + path.append(Py.newString(ClasspathPyImporter.PYCLASSPATH_PREFIX)); executable = defaultExecutable; meta_path = new PyList(); path_hooks = new PyList(); path_hooks.append(new JavaImporter()); path_hooks.append(zipimporter.TYPE); + path_hooks.append(ClasspathPyImporter.TYPE); path_importer_cache = new PyDictionary(); currentWorkingDir = new File("").getAbsolutePath(); @@ -240,7 +242,7 @@ return shadowing.builtins; } } - + public synchronized void setBuiltins(PyObject value) { if (shadowing == null) { builtins = value; Added: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java (rev 0) +++ trunk/jython/src/org/python/core/util/importer.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,230 @@ +package org.python.core.util; + +import java.io.InputStream; +import java.util.EnumSet; +import org.python.core.BytecodeLoader; +import org.python.core.Py; +import org.python.core.PyCode; +import org.python.core.PyList; +import org.python.core.PyModule; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.core.imp; + +/** + * A base class for PEP-302 path hooks. Handles looking through source, compiled, package and module + * items in the right order, and creating and filling in modules. + */ +public abstract class importer<T> extends PyObject { + + static enum EntryType { + IS_SOURCE, IS_BYTECODE, IS_PACKAGE + }; + /** SearchOrder defines how we search for a module. */ + final SearchOrderEntry[] searchOrder; + + /** Module information */ + protected static enum ModuleInfo { + ERROR, NOT_FOUND, MODULE, PACKAGE + }; + + public importer(PyType subType) { + super(subType); + searchOrder = makeSearchOrder(); + } + + public importer() { + searchOrder = makeSearchOrder(); + } + + /** + * Returns the separator between directories and files used by this type of importer. + */ + protected abstract String getSeparator(); + + /** + * Returns the value to fill in __path__ on a module with the given full module name created by + * this importer. + */ + protected abstract String makePkgPath(String fullname); + + /** + * Given a full module name, return the potential file path in the archive (without extension). + */ + protected abstract String makeFilename(String fullname); + + /** + * Returns an entry for a filename from makeFilename with a potential suffix such that this + * importer can make a bundle with it, or null if fullFilename doesn't exist in this importer. + */ + protected abstract T makeEntry(String filenameAndSuffix); + + /** + * Returns a Bundle for fullFilename and entry, the result from a makeEntry call for + * fullFilename. + */ + protected abstract Bundle makeBundle(String filenameAndSuffix, T entry); + + private SearchOrderEntry[] makeSearchOrder(){ + return new SearchOrderEntry[] { + new SearchOrderEntry(getSeparator() + "__init__$py.class", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), + new SearchOrderEntry(getSeparator() + "__init__.py", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), + new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), + new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)),}; + } + + protected final PyObject importer_find_module(String fullname, String path) { + ModuleInfo moduleInfo = getModuleInfo(fullname); + if (moduleInfo == ModuleInfo.ERROR || moduleInfo == ModuleInfo.NOT_FOUND) { + return Py.None; + } + return this; + } + + protected final PyObject importer_load_module(String fullname) { + ModuleCodeData moduleCodeData = getModuleCode(fullname); + if (moduleCodeData == null) { + return Py.None; + } + // the module *must* be in sys.modules before the loader executes the module code; the + // module code may (directly or indirectly) import itself + PyModule mod = imp.addModule(fullname); + mod.__dict__.__setitem__("__loader__", this); + if (moduleCodeData.ispackage) { + // add __path__ to the module *before* the code gets executed + PyList pkgpath = new PyList(); + pkgpath.add(makePkgPath(fullname)); + mod.__dict__.__setitem__("__path__", pkgpath); + } + imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); + Py.writeDebug("import", "import " + fullname + " # loaded from " + moduleCodeData.path); + return mod; + } + + /** + * Bundle is an InputStream, bundled together with a method that can close the input stream and + * whatever resources are associated with it when the resource is imported. + */ + protected abstract static class Bundle { + public InputStream inputStream; + + public Bundle(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Close the underlying resource if necessary. Raises an IOError if a problem occurs. + */ + public abstract void close(); + } + + protected abstract boolean isAcceptableBytecode(String searchPath, T entry); + + /** + * Return module information for the module with the fully qualified name. + * + * @param fullname + * the fully qualified name of the module + * @return the module's information + */ + protected final ModuleInfo getModuleInfo(String fullname) { + String path = makeFilename(fullname); + + for (SearchOrderEntry entry : searchOrder) { + T importEntry = makeEntry(path + entry.suffix); + if (importEntry == null) { + continue; + } + + if (entry.type.contains(EntryType.IS_PACKAGE)) { + return ModuleInfo.PACKAGE; + } + return ModuleInfo.MODULE; + } + return ModuleInfo.NOT_FOUND; + } + + /** + * Return the code object and its associated data for the module with the fully qualified name. + * + * @param fullname + * the fully qualified name of the module + * @return the module's ModuleCodeData object + */ + protected final ModuleCodeData getModuleCode(String fullname) { + String path = makeFilename(fullname); + String fullPath = makePkgPath(fullname); + + if (path.length() < 0) { + return null; + } + + for (SearchOrderEntry entry : searchOrder) { + String suffix = entry.suffix; + String searchPath = path + suffix; + String fullSearchPath = fullPath + suffix; + + Py.writeDebug("import", "# trying " + searchPath); + T tocEntry = makeEntry(searchPath); + if (tocEntry == null) { + continue; + } + + boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); + boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); + + if (isbytecode && !isAcceptableBytecode(searchPath, tocEntry)) { + continue; + } + + Bundle bundle = makeBundle(searchPath, tocEntry); + byte[] codeBytes; + if (isbytecode) { + codeBytes = imp.readCode(fullname, bundle.inputStream, true); + } else { + codeBytes = imp.compileSource(fullname, bundle.inputStream, fullSearchPath); + } + bundle.close(); + + if (codeBytes == null) { + // bad magic number or non-matching mtime in byte code, try next + continue; + } + + PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, fullSearchPath); + return new ModuleCodeData(code, ispackage, fullSearchPath); + } + return null; + } + + /** + * Container for PyModule code - whether or not it's a package - and its path. + */ + protected class ModuleCodeData { + public PyCode code; + public boolean ispackage; + public String path; + + public ModuleCodeData(PyCode code, boolean ispackage, String path) { + this.code = code; + this.ispackage = ispackage; + this.path = path; + } + } + + /** + * A step in the module search order: the file suffix and its entry type. + */ + protected static class SearchOrderEntry { + public String suffix; + public EnumSet<EntryType> type; + + public SearchOrderEntry(String suffix, EnumSet<EntryType> type) { + this.suffix = suffix; + this.type = type; + } + } + +} Modified: trunk/jython/src/org/python/modules/imp.java =================================================================== --- trunk/jython/src/org/python/modules/imp.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/imp.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -9,8 +9,6 @@ import org.python.core.PyString; import org.python.core.PySystemState; import org.python.core.PyTuple; -import org.python.core.PyInteger; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -144,8 +142,7 @@ public static PyObject load_source(String modname, String filename, PyObject file) { PyObject mod = Py.None; if (file == null) { - // XXX: This should load the accompanying byte code file - // instead, if it exists + // XXX: This should load the accompanying byte code file instead, if it exists file = new PyFile(filename, "r", 1024); } Object o = file.__tojava__(InputStream.class); @@ -202,8 +199,7 @@ String compiledName; switch (type) { case PY_SOURCE: - // XXX: This should load the accompanying byte - // code file instead, if it exists + // XXX: This should load the accompanying byte code file instead, if it exists String resolvedFilename = sys.getPath(filename.toString()); compiledName = org.python.core.imp.makeCompiledFilename(resolvedFilename); if (name.endsWith(".__init__")) { @@ -229,8 +225,7 @@ break; case PKG_DIRECTORY: PyModule m = org.python.core.imp.addModule(name); - m.__dict__.__setitem__("__path__", - new PyList(new PyObject[] { filename })); + m.__dict__.__setitem__("__path__", new PyList(new PyObject[] {filename})); m.__dict__.__setitem__("__file__", filename); ModuleInfo mi = findFromSource(name, filename.toString(), true, true); type = mi.type; Modified: trunk/jython/src/org/python/modules/zipimport/zipimport.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimport.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/zipimport/zipimport.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -8,8 +8,6 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyStringMap; -import org.python.core.PyType; -import org.python.core.exceptions; /** * This module adds the ability to import Python modules (*.py, Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -6,27 +6,22 @@ import java.io.InputStream; import java.util.Date; import java.util.Enumeration; -import java.util.EnumSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.python.core.ArgParser; -import org.python.core.BytecodeLoader; import org.python.core.Py; -import org.python.core.PyCode; import org.python.core.PyDictionary; import org.python.core.PyInteger; -import org.python.core.PyList; import org.python.core.PyLong; -import org.python.core.PyModule; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PySystemState; import org.python.core.PyTuple; import org.python.core.PyType; -import org.python.core.imp; import org.python.core.util.FileUtil; import org.python.core.util.StringUtil; +import org.python.core.util.importer; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -37,11 +32,11 @@ * * @author Philip Jenvey */ -@ExposedType(name = "zipimport.zipimporter") -public class zipimporter extends PyObject { - +@ExposedType(name = "zipimport.zipimporter", base = PyObject.class) +public class zipimporter extends importer<PyObject> { + public static final PyType TYPE = PyType.fromClass(zipimporter.class); - + @ExposedGet public static final PyString __doc__ = new PyString( "zipimporter(archivepath) -> zipimporter object\n" + @@ -50,25 +45,6 @@ "a zipfile. ZipImportError is raised if 'archivepath' doesn't point to\n" + "a valid Zip archive."); - /** zipSearchOrder defines how we search for a module in the Zip - * archive */ - static enum EntryType { - IS_SOURCE, IS_BYTECODE, IS_PACKAGE - }; - static final SearchOrderEntry[] zipSearchOrder = new SearchOrderEntry[] { - new SearchOrderEntry(File.separator + "__init__$py.class", - EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), - new SearchOrderEntry(File.separator + "__init__.py", - EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), - new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), - new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)), - }; - - /** Module information */ - static enum ModuleInfo { - ERROR, NOT_FOUND, MODULE, PACKAGE - }; - /** Pathname of the Zip archive */ @ExposedGet public String archive; @@ -131,15 +107,13 @@ prefix = pathFile.getName() + File.separator + prefix; pathFile = parentFile; } - if (archive != null) { files = zipimport._zip_directory_cache.__finditem__(archive); if (files == null) { files = readDirectory(archive); zipimport._zip_directory_cache.__setitem__(archive, files); } - } - else { + } else { throw zipimport.ZipImportError("not a Zip file"); } @@ -166,11 +140,7 @@ */ @ExposedMethod(defaults = "null") final PyObject zipimporter_find_module(String fullname, String path) { - ModuleInfo moduleInfo = getModuleInfo(fullname); - if (moduleInfo == ModuleInfo.ERROR || moduleInfo == ModuleInfo.NOT_FOUND) { - return Py.None; - } - return this; + return importer_find_module(fullname, path); } public PyObject load_module(String fullname) { @@ -185,30 +155,7 @@ */ @ExposedMethod final PyObject zipimporter_load_module(String fullname) { - ModuleCodeData moduleCodeData = getModuleCode(fullname); - if (moduleCodeData == null) { - return Py.None; - } - - // the module *must* be in sys.modules before the loader - // executes the module code; the module code may (directly or - // indirectly) import itself - PyModule mod = imp.addModule(fullname); - - mod.__dict__.__setitem__("__loader__", this); - if (moduleCodeData.ispackage) { - // add __path__ to the module *before* the code gets - // executed - String fullpath = archive + File.separator + prefix + getSubname(fullname); - PyList pkgpath = new PyList(); - pkgpath.add(fullpath); - mod.__dict__.__setitem__("__path__", pkgpath); - } - - imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); - Py.writeDebug("import", "import " + fullname + " # loaded from Zip " + - moduleCodeData.path); - return mod; + return importer_load_module(fullname); } public String get_data(String path) { @@ -234,7 +181,7 @@ throw Py.IOError(path); } - ZipBundle zipBundle = getDataStream(path); + Bundle zipBundle = makeBundle(path, tocEntry); byte[] data; try { data = FileUtil.readBytes(zipBundle.inputStream); @@ -309,7 +256,7 @@ throw zipimport.ZipImportError("can't find module '" + fullname + "'"); } - String path = makeFilename(prefix, getSubname(fullname)); + String path = makeFilename(fullname); if (moduleInfo == ModuleInfo.PACKAGE) { path += File.separator + "__init__.py"; } @@ -334,7 +281,7 @@ * @return a ZipBundle with an InputStream to the file's * uncompressed data */ - public ZipBundle getDataStream(String datapath) { + public ZipBundle makeBundle(String datapath, PyObject entry) { datapath = datapath.replace(File.separatorChar, '/'); ZipFile zipArchive; try { @@ -355,91 +302,16 @@ } /** - * Return module information for the module with the fully - * qualified name. + * Determine if the byte code at path with the specified toc entry has a modification time + * greater than its accompanying source code's. * - * @param fullname the fully qualified name of the module - * @return the module's information - */ - private ModuleInfo getModuleInfo(String fullname) { - String path = makeFilename(prefix, getSubname(fullname)); - - for (SearchOrderEntry entry : zipSearchOrder) { - PyObject tocEntry = files.__finditem__(path + entry.suffix); - if (tocEntry == null) - continue; - - if (entry.type.contains(EntryType.IS_PACKAGE)) { - return ModuleInfo.PACKAGE; - } - return ModuleInfo.MODULE; - } - return ModuleInfo.NOT_FOUND; - } - - /** - * Return the code object and its associated data for the module - * with the fully qualified name. - * - * @param fullname the fully qualified name of the module - * @return the module's ModuleCodeData object - */ - private ModuleCodeData getModuleCode(String fullname) { - String path = makeFilename(prefix, getSubname(fullname)); - - if (path.length() < 0) { - return null; - } - - for (SearchOrderEntry entry : zipSearchOrder) { - String suffix = entry.suffix; - String searchPath = path + suffix; - - Py.writeDebug("import", "# trying " + archive + File.separator + path); - PyObject tocEntry = files.__finditem__(searchPath); - if (tocEntry == null) { - continue; - } - - boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); - boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); - - if (isbytecode && isOutdatedBytecode(searchPath, tocEntry)) { - continue; - } - - String pathToEntry = archive + File.separator + searchPath; - ZipBundle zipBundle = getDataStream(searchPath); - byte[] codeBytes; - if (isbytecode) { - codeBytes = imp.readCode(fullname, zipBundle.inputStream, true); - } - else { - codeBytes = imp.compileSource(fullname, zipBundle.inputStream, pathToEntry); - } - zipBundle.close(); - - if (codeBytes == null) { - // bad magic number or non-matching mtime in byte code, try next - continue; - } - - PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); - return new ModuleCodeData(code, ispackage, pathToEntry); - } - return null; - } - - /** - * Determine if the byte code at path with the specified toc entry - * has a modification time greater than its accompanying source - * code's. - * - * @param path a String path to the byte code - * @param tocEntry the byte code's PyObject toc entry + * @param path + * a String path to the byte code + * @param tocEntry + * the byte code's PyObject toc entry * @return boolean whether or not the byte code is older */ - private boolean isOutdatedBytecode(String path, PyObject tocEntry) { + protected boolean isAcceptableBytecode(String path, PyObject tocEntry) { String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { @@ -528,13 +400,41 @@ return files; } + protected String getSeparator() { + return File.separator; + } + /** + * Given a full module name, return the potential file path in the archive (without extension). + * + * @param prefix + * a String value + * @param name + * a String modulename value + * @return the file path String value + */ + protected String makeFilename(String fullname) { + return prefix + getSubname(fullname).replace('.', File.separatorChar); + } + + @Override + protected String makePkgPath(String fullname) { + return archive + File.separator + prefix + getSubname(fullname); + } + + @Override + protected PyObject makeEntry(String fullFilename) { + return files.__finditem__(fullFilename); + } + + /** * Return fullname.split(".")[-1]. * - * @param fullname a String value + * @param fullname + * a String value * @return a split(".")[-1] String value */ - private String getSubname(String fullname) { + protected String getSubname(String fullname) { int i = fullname.lastIndexOf("."); if (i >= 0) { return fullname.substring(i + 1); @@ -543,18 +443,6 @@ } /** - * Given a (sub)modulename, return the potential file path in the - * archive (without extension). - * - * @param prefix a String value - * @param name a String modulename value - * @return the file path String value - */ - private String makeFilename(String prefix, String name) { - return prefix + name.replace('.', File.separatorChar); - } - - /** * Convert a time in milliseconds since epoch to DOS date format * * @param time in milliseconds, a long value @@ -613,43 +501,21 @@ } /** - * Container for PyModule code, whether or not it's a package and - * its path. - * + * ZipBundle is a ZipFile and one of its InputStreams, bundled together so the ZipFile can be + * closed when finished with its InputStream. */ - private class ModuleCodeData { - PyCode code; - boolean ispackage; - String path; - - public ModuleCodeData(PyCode code, boolean ispackage, String path) { - this.code = code; - this.ispackage = ispackage; - this.path = path; - } - } - - /** - * ZipBundle is a ZipFile and one of its InputStreams, bundled - * together so the ZipFile can be closed when finished with its - * InputStream. - * - */ - private class ZipBundle { + private class ZipBundle extends Bundle { ZipFile zipFile; - InputStream inputStream; public ZipBundle(ZipFile zipFile, InputStream inputStream) { + super(inputStream); this.zipFile = zipFile; - this.inputStream = inputStream; } /** - * Close the ZipFile; implicitly closes all of its - * InputStreams. + * Close the ZipFile; implicitly closes all of its InputStreams. * * Raises an IOError if a problem occurred. - * */ public void close() { try { @@ -660,19 +526,4 @@ } } } - - /** - * A step in the module search order: the file suffix and its file - * type. - * - */ - protected static class SearchOrderEntry { - public String suffix; - public EnumSet<EntryType> type; - - public SearchOrderEntry(String suffix, EnumSet<EntryType> type) { - this.suffix = suffix; - this.type = type; - } - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-31 21:57:40
|
Revision: 5823 http://jython.svn.sourceforge.net/jython/?rev=5823&view=rev Author: fwierzbicki Date: 2008-12-31 21:57:35 +0000 (Wed, 31 Dec 2008) Log Message: ----------- test259.py -> test_codeop_jy.py Modified Paths: -------------- trunk/jython/Lib/test/test_codeop_jy.py Removed Paths: ------------- trunk/jython/bugtests/test259.py trunk/jython/bugtests/test259s.py Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -171,6 +171,7 @@ ai("del (1,)") ai("del [1]") ai("del '1'") + ai("if (a == 1 and b = 2): pass") def test_filename(self): self.assertEquals(compile_("a = 1\n", "abc").co_filename, Deleted: trunk/jython/bugtests/test259.py =================================================================== --- trunk/jython/bugtests/test259.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/bugtests/test259.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -1,11 +0,0 @@ - -import support - - -try: - import test259s -except SyntaxError: - pass -else: - raise support.TestError, "Should raise a syntax error" - Deleted: trunk/jython/bugtests/test259s.py =================================================================== --- trunk/jython/bugtests/test259s.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/bugtests/test259s.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -1,9 +0,0 @@ - -var_a = 'blah' -var_b = 'halb' - -if (var_a == 'blah' and var_b = 'halb') : - print 'IT IS TRUE' -else : - print 'IT IS FALSE' - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-31 22:55:23
|
Revision: 5821 http://jython.svn.sourceforge.net/jython/?rev=5821&view=rev Author: cgroves Date: 2008-12-31 21:38:23 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Java class mros are static, so don't compute them and blow up when trying to make a Python resolution order out of them. An ant clean will be necessary after this commit to clear out the exposed version of PyJavaType. Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-31 21:37:59 UTC (rev 5820) +++ trunk/jython/CoreExposed.includes 2008-12-31 21:38:23 UTC (rev 5821) @@ -20,7 +20,6 @@ org/python/core/PyFunction.class org/python/core/PyGenerator.class org/python/core/PyInteger.class -org/python/core/PyJavaType.class org/python/core/PyList.class org/python/core/PyLong.class org/python/core/PyMethod.class Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-31 21:37:59 UTC (rev 5820) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-31 21:38:23 UTC (rev 5821) @@ -141,6 +141,7 @@ self.assertEquals('java.util', HashMap.__module__) self.assertEquals(Class, HashMap.__class__) self.assertEquals(None, HashMap.__doc__) + self.assertEquals(list(HashMap.__mro__), HashMap.mro()) def test_python_methods(self): s = SomePyMethods() Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-12-31 21:37:59 UTC (rev 5820) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-12-31 21:38:23 UTC (rev 5821) @@ -16,11 +16,9 @@ import org.python.core.util.StringUtil; import org.python.expose.ExposeAsSuperclass; -import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; import org.python.util.Generic; -@ExposedType(name = "javatype") public class PyJavaType extends PyType { private final static Class<?>[] OO = {PyObject.class, PyObject.class}; @@ -37,14 +35,6 @@ super(TYPE == null ? fromClass(PyType.class) : TYPE); } - @ExposedMethod(defaults = "null") - final PyList javatype_mro(PyObject o) { - if (o == null) { - return new PyList(mro); - } - return new PyList(((PyJavaType)o).mro); - } - @Override public Class<?> getProxyType() { return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; @@ -62,6 +52,10 @@ return !(attr instanceof PyReflectedField || attr instanceof PyReflectedFunction); } + PyObject[] compute_mro() { + return mro; + } + @Override protected void init() { name = underlying_class.getName(); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-12-31 21:37:59 UTC (rev 5820) +++ trunk/jython/src/org/python/core/PyType.java 2008-12-31 21:38:23 UTC (rev 5821) @@ -691,7 +691,7 @@ return new PyList(((PyType)o).compute_mro()); } - final PyObject[] compute_mro() { + PyObject[] compute_mro() { PyObject[] bases = this.bases; int n = bases.length; for (int i = 0; i < n; i++) { Modified: trunk/jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java =================================================================== --- trunk/jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java 2008-12-31 21:37:59 UTC (rev 5820) +++ trunk/jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java 2008-12-31 21:38:23 UTC (rev 5821) @@ -108,10 +108,10 @@ }); } - /** - * Always returns true as we just return new PyJavaInstance(o) if the - * adapters added to the superclass can't handle o. - */ + /** + * Always returns true as we just return new PyJavaInstance(o) if the adapters added to the + * superclass can't handle o. + */ public boolean canAdapt(Object o) { return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-31 22:55:28
|
Revision: 5820 http://jython.svn.sourceforge.net/jython/?rev=5820&view=rev Author: fwierzbicki Date: 2008-12-31 21:37:59 +0000 (Wed, 31 Dec 2008) Log Message: ----------- test216 -> test_codeop_jy.py (plus more like this test) Also cleaned up test_codeop.py so we are more like CPython, we are close to deleting our local version of test_codeop.py. Improved trailing \ support in grammar Added a number of checks for invalid del statements. Modified Paths: -------------- trunk/jython/Lib/test/test_codeop.py trunk/jython/Lib/test/test_codeop_jy.py trunk/jython/grammar/Python.g trunk/jython/grammar/PythonPartial.g trunk/jython/src/org/python/antlr/GrammarActions.java Removed Paths: ------------- trunk/jython/bugtests/test216.py trunk/jython/bugtests/test216s1.py Modified: trunk/jython/Lib/test/test_codeop.py =================================================================== --- trunk/jython/Lib/test/test_codeop.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/Lib/test/test_codeop.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -86,22 +86,12 @@ av("def x():\n\n pass\n") av("def x():\n pass\n \n") av("def x():\n pass\n \n") - ##next 4 added for Jython - av("\n\ndef x():\n pass\n") - av("def x():\n\n pass\n") # failed under Jython 2.1 - av("def x():\n pass\n \n") - av("def x():\n pass\n \n") - # this failed under 2.2.1 - av("def x():\n try: pass\n finally: [a for a in (1,2)]\n") - av("pass\n") av("3**3\n") av("if 9==3:\n pass\nelse:\n pass\n") av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") - #next 2 added for Jython - av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") av("#a\n#b\na = 3\n") av("#a\n\n \na=3\n") @@ -132,7 +122,6 @@ ai("if 9==3:\n pass\nelse:") ai("if 9==3:\n pass\nelse:\n") ai("if 9==3:\n pass\nelse:\n pass") - ai("if 1:") ai("if 1:\n") ai("if 1:\n pass\n if 1:\n pass\n else:") @@ -148,7 +137,7 @@ #ai("def x():\n pass\n ") ai("\n\ndef x():\n pass") - #ai("a = 9+ \\") + ai("a = 9+ \\") #ai("a = 'a\\") ai("a = '''xy") @@ -157,7 +146,7 @@ ai("(","eval") ai("(\n\n\n","eval") ai("(9+","eval") - #ai("9+ \\","eval") + ai("9+ \\","eval") #ai("lambda z: \\","eval") def test_invalid(self): @@ -175,21 +164,18 @@ ai("\n\n if 1: pass\n\npass") - ai("a = 9+ \\\n") + #ai("a = 9+ \\\n") ai("a = 'a\\ ") ai("a = 'a\\\n") - #XXX: eval is hopelessly permissive right now -- but the rest of this - # test_jy_compile is really important to me for flagging new bugs - - # so commenting out these for now. - #ai("a = 1","eval") + ai("a = 1","eval") #ai("a = (","eval") - #ai("]","eval") - #ai("())","eval") - #ai("[}","eval") - #ai("9+","eval") - #ai("lambda z:","eval") - #ai("a b","eval") + ai("]","eval") + ai("())","eval") + ai("[}","eval") + ai("9+","eval") + ai("lambda z:","eval") + ai("a b","eval") def test_filename(self): self.assertEquals(compile_command("a = 1\n", "abc").co_filename, Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -65,6 +65,12 @@ av("def x():\n pass\n \n") av("def x():\n pass\n \n") + # this failed under 2.2.1 + av("def x():\n try: pass\n finally: [a for a in (1,2)]\n") + + av("if 9==3:\n pass\nelse:\n pass\n") + av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") + av("pass\n") av("3**3\n") @@ -160,6 +166,11 @@ ai("lambda z:","eval") ai("a b","eval") ai("return 2.3") + ai("del 1") + ai("del ()") + ai("del (1,)") + ai("del [1]") + ai("del '1'") def test_filename(self): self.assertEquals(compile_("a = 1\n", "abc").co_filename, Deleted: trunk/jython/bugtests/test216.py =================================================================== --- trunk/jython/bugtests/test216.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/bugtests/test216.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -try: - import test216s1 -except SyntaxError: - pass -else: - raise support.TestError("Should raise SyntaxError") Deleted: trunk/jython/bugtests/test216s1.py =================================================================== --- trunk/jython/bugtests/test216s1.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/bugtests/test216s1.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -1,11 +0,0 @@ -class Foo: - pass - -f = Foo() -f.bar = {} - -#f.bar("A") -#del f.bar("A") - -#f.bar("A") = 1 -del [1] \ No newline at end of file Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/grammar/Python.g 2008-12-31 21:37:59 UTC (rev 5820) @@ -73,6 +73,7 @@ tokens { INDENT; DEDENT; + TRAILBACKSLASH; //For dangling backslashes when partial parsing. } @header { @@ -1779,9 +1780,21 @@ */ CONTINUED_LINE : '\\' ('\r')? '\n' (' '|'\t')* { $channel=HIDDEN; } - ( nl=NEWLINE {emit(new CommonToken(NEWLINE,nl.getText()));} + ( nl=NEWLINE { + if (!partial) { + emit(new CommonToken(NEWLINE,nl.getText())); + } + } | - ) + ) { + if (input.LA(1) == -1) { + if (partial) { + emit(new CommonToken(TRAILBACKSLASH,"\\")); + } else { + throw new ParseException("unexpected character after line continuation character"); + } + } + } ; /** Treat a sequence of blank lines as a single blank line. If Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/grammar/PythonPartial.g 2008-12-31 21:37:59 UTC (rev 5820) @@ -73,49 +73,24 @@ } @members { - boolean debugOn = false; + private ErrorHandler errorHandler = new FailFastHandler(); - private void debug(String message) { - if (debugOn) { - System.out.println(message); + protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { + if (errorHandler.mismatch(this, input, ttype, follow)) { + super.mismatch(input, ttype, follow); } } - /* - protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { - throw new MismatchedTokenException(ttype, input); - } - protected void mismatch(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException { - throw e; - } + protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) + throws RecognitionException { - protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) - throws RecognitionException - { - mismatch(input, ttype, follow); - return null; + Object o = errorHandler.recoverFromMismatchedToken(this, input, ttype, follow); + if (o != null) { + return o; + } + return super.recoverFromMismatchedToken(input, ttype, follow); } - */ - public void emitErrorMessage(String msg) { - //System.err.print("[EMITTING] "); - } - - public void reportError(RecognitionException e) { - //System.err.print("[REPORTING] "); - // if we've already reported an error and have not matched a token - // yet successfully, don't report any errors. - if ( state.errorRecovery ) { - System.err.print("[SPURIOUS] "); - return; - } - state.syntaxErrors++; // don't count spurious - state.errorRecovery = true; - - displayRecognitionError(this.getTokenNames(), e); - } - - } @rulecatch { @@ -187,7 +162,7 @@ | assert_stmt ; -expr_stmt : testlist {debug("matched expr_stmt");} +expr_stmt : testlist ( augassign yield_expr | augassign testlist | assigns @@ -338,12 +313,12 @@ ) ; -test: or_test {debug("matched test: or_test");} +test: or_test ( (IF or_test ELSE) => IF or_test ELSE test)? | lambdef ; -or_test : and_test (OR and_test)* {debug("matched or_test");} +or_test : and_test (OR and_test)* ; and_test : not_test (AND not_test)* @@ -369,7 +344,7 @@ | IS NOT ; -expr : xor_expr (VBAR xor_expr)* {debug("matched expr");} +expr : xor_expr (VBAR xor_expr)* ; xor_expr : and_expr (CIRCUMFLEX and_expr)* @@ -391,6 +366,7 @@ | MINUS factor | TILDE factor | power + | TRAILBACKSLASH ; power : atom (trailer)* (options {greedy=true;}:DOUBLESTAR factor)? @@ -409,7 +385,7 @@ | LONGINT | FLOAT | COMPLEX - | (STRING)+ {debug("matched STRING");} + | (STRING)+ | STRINGPART ; @@ -449,7 +425,7 @@ ; testlist - : test (options {k=2;}: COMMA test)* (COMMA)? {debug("matched testlist");} + : test (options {k=2;}: COMMA test)* (COMMA)? ; dictmaker : test COLON test (options {k=2;}:COMMA test COLON test)* (COMMA)? Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-12-31 21:37:59 UTC (rev 5820) @@ -637,16 +637,40 @@ } } - List<expr> makeDeleteList(List e) { - List<expr> exprs = castExprs(e); - for(expr expr : exprs) { - if (expr instanceof Call) { - errorHandler.error("can't delete function call", expr); - } + List<expr> makeDeleteList(List deletes) { + List<expr> exprs = castExprs(deletes); + for(expr e : exprs) { + checkDelete(e); } return exprs; } + void checkDelete(expr e) { + //System.out.println("trying to del " + e); + if (e instanceof Call) { + errorHandler.error("can't delete function call", e); + } else if (e instanceof Num) { + errorHandler.error("can't delete number", e); + } else if (e instanceof Str) { + errorHandler.error("can't delete string", e); + } else if (e instanceof Tuple) { + //XXX: performance problem? Any way to do this better? + List<expr> elts = ((Tuple)e).getInternalElts(); + if (elts.size() == 0) { + errorHandler.error("can't delete ()", e); + } + for (int i=0;i<elts.size();i++) { + checkDelete(elts.get(i)); + } + } else if (e instanceof org.python.antlr.ast.List) { + //XXX: performance problem? Any way to do this better? + List<expr> elts = ((org.python.antlr.ast.List)e).getInternalElts(); + for (int i=0;i<elts.size();i++) { + checkDelete(elts.get(i)); + } + } + } + slice makeSubscript(PythonTree lower, Token colon, PythonTree upper, PythonTree sliceop) { boolean isSlice = false; expr s = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-01 00:20:01
|
Revision: 5824 http://jython.svn.sourceforge.net/jython/?rev=5824&view=rev Author: cgroves Date: 2009-01-01 00:19:56 +0000 (Thu, 01 Jan 2009) Log Message: ----------- Welcome back, Options.respectJavaAcessibility Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/Lib/test/access_protected_class.py trunk/jython/Lib/test/access_protected_field.py trunk/jython/Lib/test/call_protected_method.py Added: trunk/jython/Lib/test/access_protected_class.py =================================================================== --- trunk/jython/Lib/test/access_protected_class.py (rev 0) +++ trunk/jython/Lib/test/access_protected_class.py 2009-01-01 00:19:56 UTC (rev 5824) @@ -0,0 +1,2 @@ +from java.awt.geom import Ellipse2D, EllipseIterator +EllipseIterator(Ellipse2D.Float(), None) Added: trunk/jython/Lib/test/access_protected_field.py =================================================================== --- trunk/jython/Lib/test/access_protected_field.py (rev 0) +++ trunk/jython/Lib/test/access_protected_field.py 2009-01-01 00:19:56 UTC (rev 5824) @@ -0,0 +1,4 @@ +from org.python.tests import Invisible +Invisible.protectedStaticField +Invisible().protectedField +Invisible.packageField Added: trunk/jython/Lib/test/call_protected_method.py =================================================================== --- trunk/jython/Lib/test/call_protected_method.py (rev 0) +++ trunk/jython/Lib/test/call_protected_method.py 2009-01-01 00:19:56 UTC (rev 5824) @@ -0,0 +1,5 @@ +from org.python.tests import Invisible +Invisible.protectedStaticMethod(7) +Invisible().protectedMethod(7) +Invisible.packageStaticMethod() +Invisible().packageMethod() Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-31 21:57:35 UTC (rev 5823) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-01 00:19:56 UTC (rev 5824) @@ -1,5 +1,7 @@ import array import unittest +import subprocess +import sys from test import test_support from java.lang import Class from java.util import HashMap, Observable, Observer @@ -165,10 +167,28 @@ self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) +class RespectJavaAccessibilityTest(unittest.TestCase): + def run_accessibility_script(self, script, error=AttributeError): + fn = test_support.findfile(script) + self.assertRaises(error, execfile, fn) + self.assertEquals(subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", + "-J-Dpython.security.respectJavaAccessibility=false", fn]), + 0) + + def test_method_access(self): + self.run_accessibility_script("call_protected_method.py") + + def test_field_access(self): + self.run_accessibility_script("access_protected_field.py") + + def test_protected_class(self): + self.run_accessibility_script("access_protected_class.py", TypeError) + def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, - CoercionTest) + CoercionTest, + RespectJavaAccessibilityTest) if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-12-31 21:57:35 UTC (rev 5823) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-01 00:19:56 UTC (rev 5824) @@ -102,7 +102,7 @@ // PyReflected* can't call or access anything from non-public classes that aren't in // org.python.core if (!Modifier.isPublic(underlying_class.getModifiers()) && - !name.startsWith("org.python.core")) { + !name.startsWith("org.python.core") && Options.respectJavaAccessibility) { handleSuperMethodArgCollisions(); return; } @@ -110,7 +110,17 @@ // Add methods and determine bean properties declared on this class Map<String, PyBeanProperty> props = Generic.map(); Map<String, PyBeanEvent> events = Generic.map(); - for (Method meth : underlying_class.getMethods()) { + Method[] methods; + if (Options.respectJavaAccessibility) { + // returns just the public methods + methods = underlying_class.getMethods(); + } else { + methods = underlying_class.getDeclaredMethods(); + for (Method method : methods) { + method.setAccessible(true); + } + } + for (Method meth : methods) { if (!declaredOnMember(baseClass, meth) || ignore(meth)) { continue; } @@ -174,7 +184,7 @@ } // Add superclass methods - for (Method meth : underlying_class.getMethods()) { + for (Method meth : methods) { String nmethname = normalize(meth.getName()); PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); if (reflfunc != null) { @@ -192,7 +202,17 @@ } // Add fields declared on this type - for (Field field : underlying_class.getFields()) { + Field[] fields; + if (Options.respectJavaAccessibility) { + // returns just the public fields + fields = underlying_class.getFields(); + } else { + fields = underlying_class.getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + } + } + for (Field field : fields) { if (!declaredOnMember(baseClass, field)) { continue; } @@ -258,7 +278,19 @@ } final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); - for (Constructor<?> ctr : underlying_class.getConstructors()) { + Constructor<?>[] constructors; + // No matter the security manager, trying to set the constructor on class to accessible + // blows up + if (Options.respectJavaAccessibility || Class.class == underlying_class) { + // returns just the public constructors + constructors = underlying_class.getConstructors(); + } else { + constructors = underlying_class.getDeclaredConstructors(); + for (Constructor<?> ctr : constructors) { + ctr.setAccessible(true); + } + } + for (Constructor<?> ctr : constructors) { reflctr.addConstructor(ctr); } if (PyObject.class.isAssignableFrom(underlying_class)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-01 22:32:08
|
Revision: 5830 http://jython.svn.sourceforge.net/jython/?rev=5830&view=rev Author: cgroves Date: 2009-01-01 22:32:02 +0000 (Thu, 01 Jan 2009) Log Message: ----------- test260,264 - Testing jythonc; deleted test261,262 - Tested by test_import test263 - Tested by test_cpickle test265 - Tested by test_java_integration test266 - Tested by test_socket test268,269,270 - Moved to test_java_visibility Modified Paths: -------------- trunk/jython/Lib/test/test_classpathimporter.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_support.py trunk/jython/bugtests/test275s.py trunk/jython/build.xml trunk/jython/src/org/python/antlr/ast/AssertDerived.java trunk/jython/src/org/python/antlr/ast/AssignDerived.java trunk/jython/src/org/python/antlr/ast/AttributeDerived.java trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java trunk/jython/src/org/python/antlr/ast/BinOpDerived.java trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java trunk/jython/src/org/python/antlr/ast/BreakDerived.java trunk/jython/src/org/python/antlr/ast/CallDerived.java trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java trunk/jython/src/org/python/antlr/ast/CompareDerived.java trunk/jython/src/org/python/antlr/ast/ContinueDerived.java trunk/jython/src/org/python/antlr/ast/DeleteDerived.java trunk/jython/src/org/python/antlr/ast/DictDerived.java trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java trunk/jython/src/org/python/antlr/ast/ExecDerived.java trunk/jython/src/org/python/antlr/ast/ExprDerived.java trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java trunk/jython/src/org/python/antlr/ast/ForDerived.java trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java trunk/jython/src/org/python/antlr/ast/GlobalDerived.java trunk/jython/src/org/python/antlr/ast/IfDerived.java trunk/jython/src/org/python/antlr/ast/IfExpDerived.java trunk/jython/src/org/python/antlr/ast/ImportDerived.java trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java trunk/jython/src/org/python/antlr/ast/IndexDerived.java trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java trunk/jython/src/org/python/antlr/ast/LambdaDerived.java trunk/jython/src/org/python/antlr/ast/ListCompDerived.java trunk/jython/src/org/python/antlr/ast/ListDerived.java trunk/jython/src/org/python/antlr/ast/ModuleDerived.java trunk/jython/src/org/python/antlr/ast/NameDerived.java trunk/jython/src/org/python/antlr/ast/NumDerived.java trunk/jython/src/org/python/antlr/ast/PassDerived.java trunk/jython/src/org/python/antlr/ast/PrintDerived.java trunk/jython/src/org/python/antlr/ast/RaiseDerived.java trunk/jython/src/org/python/antlr/ast/ReprDerived.java trunk/jython/src/org/python/antlr/ast/ReturnDerived.java trunk/jython/src/org/python/antlr/ast/SliceDerived.java trunk/jython/src/org/python/antlr/ast/StrDerived.java trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java trunk/jython/src/org/python/antlr/ast/SuiteDerived.java trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java trunk/jython/src/org/python/antlr/ast/TupleDerived.java trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java trunk/jython/src/org/python/antlr/ast/WhileDerived.java trunk/jython/src/org/python/antlr/ast/WithDerived.java trunk/jython/src/org/python/antlr/ast/YieldDerived.java trunk/jython/src/org/python/antlr/ast/aliasDerived.java trunk/jython/src/org/python/antlr/ast/argumentsDerived.java trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java trunk/jython/src/org/python/antlr/ast/keywordDerived.java trunk/jython/src/org/python/antlr/op/AddDerived.java trunk/jython/src/org/python/antlr/op/AndDerived.java trunk/jython/src/org/python/antlr/op/AugLoadDerived.java trunk/jython/src/org/python/antlr/op/AugStoreDerived.java trunk/jython/src/org/python/antlr/op/BitAndDerived.java trunk/jython/src/org/python/antlr/op/BitOrDerived.java trunk/jython/src/org/python/antlr/op/BitXorDerived.java trunk/jython/src/org/python/antlr/op/DelDerived.java trunk/jython/src/org/python/antlr/op/DivDerived.java trunk/jython/src/org/python/antlr/op/EqDerived.java trunk/jython/src/org/python/antlr/op/FloorDivDerived.java trunk/jython/src/org/python/antlr/op/GtDerived.java trunk/jython/src/org/python/antlr/op/GtEDerived.java trunk/jython/src/org/python/antlr/op/InDerived.java trunk/jython/src/org/python/antlr/op/InvertDerived.java trunk/jython/src/org/python/antlr/op/IsDerived.java trunk/jython/src/org/python/antlr/op/IsNotDerived.java trunk/jython/src/org/python/antlr/op/LShiftDerived.java trunk/jython/src/org/python/antlr/op/LoadDerived.java trunk/jython/src/org/python/antlr/op/LtDerived.java trunk/jython/src/org/python/antlr/op/LtEDerived.java trunk/jython/src/org/python/antlr/op/ModDerived.java trunk/jython/src/org/python/antlr/op/MultDerived.java trunk/jython/src/org/python/antlr/op/NotDerived.java trunk/jython/src/org/python/antlr/op/NotEqDerived.java trunk/jython/src/org/python/antlr/op/NotInDerived.java trunk/jython/src/org/python/antlr/op/OrDerived.java trunk/jython/src/org/python/antlr/op/ParamDerived.java trunk/jython/src/org/python/antlr/op/PowDerived.java trunk/jython/src/org/python/antlr/op/RShiftDerived.java trunk/jython/src/org/python/antlr/op/StoreDerived.java trunk/jython/src/org/python/antlr/op/SubDerived.java trunk/jython/src/org/python/antlr/op/UAddDerived.java trunk/jython/src/org/python/antlr/op/USubDerived.java trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBaseExceptionDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyEnumerateDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyFrozenSetDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySetDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/_collections/PyDefaultDictDerived.java trunk/jython/src/org/python/modules/_collections/PyDequeDerived.java trunk/jython/src/org/python/modules/_csv/PyDialectDerived.java trunk/jython/src/org/python/modules/_functools/PyPartialDerived.java trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java trunk/jython/src/org/python/modules/random/PyRandomDerived.java trunk/jython/src/org/python/modules/thread/PyLocalDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/gderived-defs trunk/jython/src/templates/gderived.py trunk/jython/src/templates/object.derived trunk/jython/tests/java/org/python/tests/Coercions.java Removed Paths: ------------- trunk/jython/bugtests/test260.py trunk/jython/bugtests/test261.py trunk/jython/bugtests/test261p/ trunk/jython/bugtests/test262.py trunk/jython/bugtests/test262m.py trunk/jython/bugtests/test262p/ trunk/jython/bugtests/test263.py trunk/jython/bugtests/test263m.py trunk/jython/bugtests/test264.py trunk/jython/bugtests/test264c.py trunk/jython/bugtests/test265.py trunk/jython/bugtests/test265j.java trunk/jython/bugtests/test266.py trunk/jython/bugtests/test268.py trunk/jython/bugtests/test268j1.java trunk/jython/bugtests/test268j2.java trunk/jython/bugtests/test269.py trunk/jython/bugtests/test269p/ trunk/jython/bugtests/test270.py trunk/jython/bugtests/test270p/ trunk/jython/bugtests/test271.py trunk/jython/bugtests/test272.py trunk/jython/bugtests/test272c.py trunk/jython/bugtests/test273.py trunk/jython/bugtests/test273p/ trunk/jython/bugtests/test274.py trunk/jython/bugtests/test276.py trunk/jython/bugtests/test276j.java Modified: trunk/jython/Lib/test/test_classpathimporter.py =================================================================== --- trunk/jython/Lib/test/test_classpathimporter.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/Lib/test/test_classpathimporter.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,9 +1,7 @@ import unittest import sys from test import test_support -from java.io import File from java.lang import Thread -from java.net import URLClassLoader class ClasspathImporterTestCase(unittest.TestCase): def setUp(self): @@ -21,8 +19,7 @@ pass def setClassLoaderAndCheck(self, jar): - url = File(test_support.findfile(jar)).toURL() - Thread.currentThread().contextClassLoader = URLClassLoader([url]) + Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) import flat_in_jar self.assertEquals(flat_in_jar.value, 7) import jar_pkg Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -8,7 +8,7 @@ from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import (Boolean, ClassLoader, ExceptionInInitializerError, Integer, Object, String, +from java.lang import (Boolean, Class, ClassLoader, ExceptionInInitializerError, Integer, Object, String, Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath @@ -93,10 +93,13 @@ def test_can_subclass_abstract(self): import ContextAbstract + called = [] class A(ContextAbstract): def method(self): - pass + called.append(True) A() + Class.newInstance(A) + self.assertEquals(len(called), 2) class InstantiationTest(unittest.TestCase): def test_can_subclass_abstract(self): @@ -151,16 +154,20 @@ pass class SysIntegrationTest(unittest.TestCase): + def setUp(self): + self.orig_stdout = sys.stdout + + def tearDown(self): + sys.stdout = self.orig_stdout + def test_stdout_outputstream(self): out = FileOutputStream(test_support.TESTFN) - oldstdout = sys.stdout sys.stdout = out print 'hello', out.close() f = open(test_support.TESTFN) self.assertEquals('hello', f.read()) f.close() - sys.stdout = out class AutoSuperTest(unittest.TestCase): def test_auto_super(self): Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -167,6 +167,18 @@ self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) + def test_class_coercion(self): + c = Coercions() + from java.util import Hashtable, HashMap + ht = Hashtable() + hm = HashMap() + ht['one'] = 'uno' + hm['zwei'] = 'two' + for obj, cls in ((ht, "java.util.Hashtable"), (hm, "java.util.HashMap"), ("abc", "java.lang.String"), + (1, "java.lang.Integer"), (1.2, "java.lang.Double"), (Hashtable, "java.lang.Class")): + self.assertEquals(c.tellClassNameSerializable(obj), "class " + cls) + self.assertEquals(c.tellClassNameObject(ht), "class java.util.Hashtable") + class RespectJavaAccessibilityTest(unittest.TestCase): def run_accessibility_script(self, script, error=AttributeError): fn = test_support.findfile(script) @@ -184,11 +196,23 @@ def test_protected_class(self): self.run_accessibility_script("access_protected_class.py", TypeError) +class ClassloaderTest(unittest.TestCase): + def test_loading_classes_without_import(self): + cl = test_support.make_jar_classloader("../callbacker_test.jar") + X = cl.loadClass("org.python.tests.Callbacker") + called = [] + class Blah(X.Callback): + def call(self, arg=None): + called.append(arg) + X().callNoArg(Blah()) + self.assertEquals(None, called[0]) + def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, CoercionTest, - RespectJavaAccessibilityTest) +# RespectJavaAccessibilityTest, + ClassloaderTest) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_support.py =================================================================== --- trunk/jython/Lib/test/test_support.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/Lib/test/test_support.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -145,6 +145,12 @@ have_unicode = 0 is_jython = sys.platform.startswith('java') +if is_jython: + def make_jar_classloader(jar): + from java.io import File + from java.net import URLClassLoader + url = File(findfile(jar)).toURL() + return URLClassLoader([url]) import os # Filename used for testing Deleted: trunk/jython/bugtests/test260.py =================================================================== --- trunk/jython/bugtests/test260.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test260.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,46 +0,0 @@ -""" - -""" - -import support - - -f = open("test260s1.py", "w") -f.write(""" - -import java -class test260s1(java.util.Vector): - def foo(self): - pass - -class P(java.awt.Panel): - pass - -class foo: - pass - -""") -f.close() - -support.compileJPythonc("test260s1.py", output="test260.err") - - - -import os -os.remove("test260s1.py") - -import sys, types -sys.path[:0] = ['jpywork'] - -import test260s1 - -#print dir(test260s1) -#print test260s1.P, type(test260s1.P) -#print test260s1.foo, type(test260s1.foo) - -del sys.path[0] - -if not hasattr(test260s1, "foo"): - raise support.TestWarning("the python class should also be visible as a module attribute"); - - Deleted: trunk/jython/bugtests/test261.py =================================================================== --- trunk/jython/bugtests/test261.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test261.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,2 +0,0 @@ -import test261p.ccs.util.Test - Deleted: trunk/jython/bugtests/test262.py =================================================================== --- trunk/jython/bugtests/test262.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test262.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,2 +0,0 @@ -import test262m - Deleted: trunk/jython/bugtests/test262m.py =================================================================== --- trunk/jython/bugtests/test262m.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test262m.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,4 +0,0 @@ -import test262p.x - -assert __name__ == "test262m" - Deleted: trunk/jython/bugtests/test263.py =================================================================== --- trunk/jython/bugtests/test263.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test263.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,14 +0,0 @@ - -import cPickle, sys -import test263m - -a = test263m.A() -b = test263m.B() - - -s = cPickle.dumps([a, b]) - -del sys.modules['test263m'] -del test263m - -cPickle.loads(s) Deleted: trunk/jython/bugtests/test263m.py =================================================================== --- trunk/jython/bugtests/test263m.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test263m.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,7 +0,0 @@ - -class A: - pass - -class B(A): - pass - Deleted: trunk/jython/bugtests/test264.py =================================================================== --- trunk/jython/bugtests/test264.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test264.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test264c.py", core=1, deep=1, jar="test264c.jar", output="test264.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test264c.py =================================================================== --- trunk/jython/bugtests/test264c.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test264c.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,8 +0,0 @@ - -import ucnhash -import encodings -import encodings.unicode_escape - - -s = unicode("\N{SPACE} \N{EURO SIGN}", "unicode-escape") - Deleted: trunk/jython/bugtests/test265.py =================================================================== --- trunk/jython/bugtests/test265.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test265.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test265j.java") - -import test265j - -try: - test265j() -except TypeError: - pass -else: - raise support.TestError("expected a TypeError (abstract java class)") - - - Deleted: trunk/jython/bugtests/test265j.java =================================================================== --- trunk/jython/bugtests/test265j.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test265j.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,7 +0,0 @@ - -public abstract class test265j { - - public test265j() { - System.out.println("test265j ctor"); - } -} Deleted: trunk/jython/bugtests/test266.py =================================================================== --- trunk/jython/bugtests/test266.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test266.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,43 +0,0 @@ - -import socket -import thread -import time - - -def server(): - HOST = '' # Symbolic name meaning the local host - PORT = 50007 # Arbitrary non-privileged port - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((HOST, PORT)) - #print "server listen", s - s.listen(1) - #print "server accept", s - conn, addr = s.accept() - #print 'Connected by', addr - while 1: - data = conn.recv(1024) - if not data: break - conn.send(data) - conn.close() - - -def client(): - HOST = '127.0.0.1' # The remote host - PORT = 50007 # The same port as used by the server - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - #print "client connect", s - s.connect((HOST, PORT)) - #print "client send" - s.send('Hello, world') - f = s.makefile() - s.close() - data = f.read(12) - f.close() - #print 'Received', `data` - - - -thread.start_new_thread(server, ()) -time.sleep(5) -client() - Deleted: trunk/jython/bugtests/test268.py =================================================================== --- trunk/jython/bugtests/test268.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test268.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,18 +0,0 @@ -import support - -support.compileJava("test268j2.java", classpath=".") - - -from java import net, lang -clu=net.URL(r'file:%s/' % lang.System.getProperty("user.dir")) -ld1=net.URLClassLoader([clu]) -X=ld1.loadClass("test268j1") -Y=ld1.loadClass("test268j2") -Y.printX(X()) - -import test268j1 -import test268j2 - -#import org -#print "First dump" -#org.python.core.PyJavaClass.dump() Deleted: trunk/jython/bugtests/test268j1.java =================================================================== --- trunk/jython/bugtests/test268j1.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test268j1.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,4 +0,0 @@ - -public class test268j1 { - public int value=6; -} \ No newline at end of file Deleted: trunk/jython/bugtests/test268j2.java =================================================================== --- trunk/jython/bugtests/test268j2.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test268j2.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +0,0 @@ - -public class test268j2 { - public static void printX(test268j1 x) { - ; - } -} Deleted: trunk/jython/bugtests/test269.py =================================================================== --- trunk/jython/bugtests/test269.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test269.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,18 +0,0 @@ - -import support - -support.compileJava("test269p/test269j2.java", classpath=".") - -from java import net, lang -clu=net.URL(r'file:%s/' % lang.System.getProperty("user.dir")) -ld1=net.URLClassLoader([clu]) -X=ld1.loadClass("test269p.test269j1") -Y=ld1.loadClass("test269p.test269j2") -Y.printX(X()) - -from test269p import * -test269j2.printX(test269j1()) - -#import org -#print "Second dump" -#org.python.core.PyJavaClass.dumpDebug() Deleted: trunk/jython/bugtests/test270.py =================================================================== --- trunk/jython/bugtests/test270.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test270.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,18 +0,0 @@ - -import support - -support.compileJava("test270p/test270j2.java", classpath=".") - -from test270p import * -test270j2.printX(test270j1()) - - -from java import net, lang -clu=net.URL(r'file:%s/' % lang.System.getProperty("user.dir")) -ld1=net.URLClassLoader([clu]) -X=ld1.loadClass("test270p.test270j1") -Y=ld1.loadClass("test270p.test270j2") -Y.printX(X()) - -#import org -#org.python.core.PyJavaClass.dumpDebug() Deleted: trunk/jython/bugtests/test271.py =================================================================== --- trunk/jython/bugtests/test271.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test271.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,14 +0,0 @@ - -def f1(): - l = [x for x in "abcdef"] - assert str(l) == "['a', 'b', 'c', 'd', 'e', 'f']" - -qs = "x.html&a=1&b=2;c=3" - -def f2(): - pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] - assert str(pairs) == "['x.html', 'a=1', 'b=2', 'c=3']" - -f1() -f2() - Deleted: trunk/jython/bugtests/test272.py =================================================================== --- trunk/jython/bugtests/test272.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test272.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test272c.py", core=1, jar="test27c.jar", output="test272.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test272c.py =================================================================== --- trunk/jython/bugtests/test272c.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test272c.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,7 +0,0 @@ - -from javax import swing - -class Doc(swing.text.PlainDocument): - def getEndPosition(self): - return None - Deleted: trunk/jython/bugtests/test273.py =================================================================== --- trunk/jython/bugtests/test273.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test273.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,37 +0,0 @@ -""" - -""" - -import support - -src = """ -package com; -public class Blob { - int value = %d; -} -""" - -def makeBlob(value): - f = open("test273p/com/Blob.java", "w") - f.write(src % value); - f.close(); - - support.compileJava(r"test273p/com/Blob.java") - support.compileJava(r"test273p/com/BlobWriter.java", classpath="test273p") - -makeBlob(1) - -import jreload -XLS = jreload.makeLoadSet("XLS",['test273p']) - -from XLS import com - -v = com.BlobWriter.write(com.Blob()) -support.compare(v, "1") - -makeBlob(2) - -jreload.reload(XLS) - -v = com.BlobWriter.write(com.Blob()) -support.compare(v, "2") Deleted: trunk/jython/bugtests/test274.py =================================================================== --- trunk/jython/bugtests/test274.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test274.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,25 +0,0 @@ -""" - -""" - -import support - -import shutil, os - -if os.path.isdir("test274d"): - shutil.rmtree("test274d", 1) -if os.path.isdir("test274d1"): - shutil.rmtree("test274d1", 1) - -os.mkdir("test274d") -open("test274d/file", "w").close() - -#os.utime = os.chmod = lambda f, t: None - -shutil.copytree("test274d", "test274d1") - -open("test274d1/file", "r").close() - -shutil.rmtree("test274d", 1) -shutil.rmtree("test274d1", 1) - Modified: trunk/jython/bugtests/test275s.py =================================================================== --- trunk/jython/bugtests/test275s.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test275s.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -2,9 +2,6 @@ """ -import support - - try: [i for i in range(10)] = (1, 2, 3) except SyntaxError: Deleted: trunk/jython/bugtests/test276.py =================================================================== --- trunk/jython/bugtests/test276.py 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test276.py 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,35 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test276j.java") - -from java.util import * -import test276j - -h = Hashtable() - -h.put("uno", "one") -h.put("zwei", "two") - -tmm = test276j() - -tmm.TellMeMoreO(h) -support.compare(tmm.getClassName(), "java.util.Hashtable") - -tmm.TellMeMoreS(h) -support.compare(tmm.getClassName(), "java.util.Hashtable") - -tmm.TellMeMoreS("abc") -support.compare(tmm.getClassName(), "java.lang.String") - -tmm.TellMeMoreS(1) -support.compare(tmm.getClassName(), "java.lang.Integer") - -tmm.TellMeMoreS(1.2) -support.compare(tmm.getClassName(), "java.lang.Double") - -tmm.TellMeMoreS(Hashtable) -support.compare(tmm.getClassName(), "java.lang.Class") Deleted: trunk/jython/bugtests/test276j.java =================================================================== --- trunk/jython/bugtests/test276j.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/bugtests/test276j.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,18 +0,0 @@ -import java.io.*; -import java.util.*; - -public class test276j { - Object o; - - public void TellMeMoreS(Serializable o) { - this.o = o; - } - - public void TellMeMoreO(Object o) { - this.o = o; - } - - public String getClassName() { - return o.getClass().getName(); - } -} Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/build.xml 2009-01-01 22:32:02 UTC (rev 5830) @@ -564,6 +564,9 @@ <pathelement path="${compile.dir}" /> </classpath> </typedef> + <jar destfile="${dist.dir}/callbacker_test.jar"> + <fileset dir="${compile.dir}" includes="org/python/tests/Callbacker*"/> + </jar> <jar destfile="${dist.dir}/jython.jar" duplicate="fail"> <nameunion> <fileset dir="${exposed.dir}"/> Modified: trunk/jython/src/org/python/antlr/ast/AssertDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class AssertDerived extends Assert implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/AssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class AssignDerived extends Assign implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/AttributeDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class AttributeDerived extends Attribute implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class AugAssignDerived extends AugAssign implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/BinOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class BinOpDerived extends BinOp implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class BoolOpDerived extends BoolOp implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/BreakDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class BreakDerived extends Break implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/CallDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CallDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/CallDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class CallDerived extends Call implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ClassDefDerived extends ClassDef implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/CompareDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class CompareDerived extends Compare implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ContinueDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ContinueDerived extends Continue implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/DeleteDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class DeleteDerived extends Delete implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/DictDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DictDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/DictDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class DictDerived extends Dict implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class EllipsisDerived extends Ellipsis implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ExceptHandlerDerived extends ExceptHandler implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ExecDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ExecDerived extends Exec implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ExprDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ExprDerived extends Expr implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ExpressionDerived extends Expression implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ExtSliceDerived extends ExtSlice implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ForDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ForDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ForDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ForDerived extends For implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class FunctionDefDerived extends FunctionDef implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class GeneratorExpDerived extends GeneratorExp implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/GlobalDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class GlobalDerived extends Global implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/IfDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/IfDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class IfDerived extends If implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/IfExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class IfExpDerived extends IfExp implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ImportDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ImportDerived extends Import implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class ImportFromDerived extends ImportFrom implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/IndexDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class IndexDerived extends Index implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class InteractiveDerived extends Interactive implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk/jython/src/org/python/antlr/ast/LambdaDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2009-01-01 21:52:35 UTC (rev 5829) +++ trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2009-01-01 22:32:02 UTC (rev 5830) @@ -1,6 +1,7 @@ /* Generated file, do not modify. See jython/src/templates/gderived.py. */ package org.python.antlr.ast; +import java.io.Serializable; import org.python.core.*; public class LambdaDerived extends Lambda implements Slotted { @@ -1122,7 +1123,7 @@ // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c.isInstance(this))) { + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: Modified: trunk... [truncated message content] |
From: <fwi...@us...> - 2009-01-03 04:37:44
|
Revision: 5836 http://jython.svn.sourceforge.net/jython/?rev=5836&view=rev Author: fwierzbicki Date: 2009-01-03 04:37:38 +0000 (Sat, 03 Jan 2009) Log Message: ----------- The code: [i for i in range(10)] = (1, 2, 3) now properly fails to parse. test275.py -> test_codeop_jy.py Modified Paths: -------------- trunk/jython/Lib/test/test_codeop_jy.py trunk/jython/src/org/python/antlr/GrammarActions.java Removed Paths: ------------- trunk/jython/bugtests/test275.py trunk/jython/bugtests/test275s.py Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2009-01-03 04:19:44 UTC (rev 5835) +++ trunk/jython/Lib/test/test_codeop_jy.py 2009-01-03 04:37:38 UTC (rev 5836) @@ -172,6 +172,7 @@ ai("del [1]") ai("del '1'") ai("if (a == 1 and b = 2): pass") + ai("[i for i in range(10)] = (1, 2, 3)") def test_filename(self): self.assertEquals(compile_("a = 1\n", "abc").co_filename, Deleted: trunk/jython/bugtests/test275.py =================================================================== --- trunk/jython/bugtests/test275.py 2009-01-03 04:19:44 UTC (rev 5835) +++ trunk/jython/bugtests/test275.py 2009-01-03 04:37:38 UTC (rev 5836) @@ -1,13 +0,0 @@ -""" - -""" - -import support - - -try: - import test275s -except SyntaxError: - pass -else: - raise support.TestError("Should raise a syntax error") Deleted: trunk/jython/bugtests/test275s.py =================================================================== --- trunk/jython/bugtests/test275s.py 2009-01-03 04:19:44 UTC (rev 5835) +++ trunk/jython/bugtests/test275s.py 2009-01-03 04:37:38 UTC (rev 5836) @@ -1,10 +0,0 @@ -""" - -""" - -try: - [i for i in range(10)] = (1, 2, 3) -except SyntaxError: - pass -else: - raise support.TestError("Should raise a syntax error") Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2009-01-03 04:19:44 UTC (rev 5835) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2009-01-03 04:37:38 UTC (rev 5836) @@ -619,6 +619,8 @@ errorHandler.error("can't assign to repr", e); } else if (e instanceof IfExp) { errorHandler.error("can't assign to conditional expression", e); + } else if (e instanceof ListComp) { + errorHandler.error("can't assign to list comprehension", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? List<expr> elts = ((Tuple)e).getInternalElts(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-04 05:42:55
|
Revision: 5837 http://jython.svn.sourceforge.net/jython/?rev=5837&view=rev Author: cgroves Date: 2009-01-04 05:42:44 +0000 (Sun, 04 Jan 2009) Log Message: ----------- Expose the underlying_class on proxy types as their Java proxy type such that they properly coerce into java.lang.Class. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/expose/BaseTypeBuilder.java trunk/jython/src/org/python/expose/generate/OverridableNewExposer.java Removed Paths: ------------- trunk/jython/bugtests/test277.py trunk/jython/bugtests/test277p/ Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-03 04:37:38 UTC (rev 5836) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-04 05:42:44 UTC (rev 5837) @@ -98,9 +98,12 @@ def method(self): called.append(True) A() - Class.newInstance(A) - self.assertEquals(len(called), 2) + self.assertEquals(len(called), 1) +# The no-arg constructor for proxies attempts to look up its Python class by the Python class' name, +# so the class needs to be visible at the module level or the import will fail +class ModuleVisibleJavaSubclass(Object): + pass class InstantiationTest(unittest.TestCase): def test_can_subclass_abstract(self): class A(Component): @@ -114,7 +117,10 @@ from java.util import Date self.assertRaises(TypeError, Date, '99-01-01', 1, 1) + def test_Class_newInstance_works_on_proxies(self): + Class.newInstance(ModuleVisibleJavaSubclass) + class BeanTest(unittest.TestCase): def test_shared_names(self): self.failUnless(callable(Vector.size), Deleted: trunk/jython/bugtests/test277.py =================================================================== --- trunk/jython/bugtests/test277.py 2009-01-03 04:37:38 UTC (rev 5836) +++ trunk/jython/bugtests/test277.py 2009-01-04 05:42:44 UTC (rev 5837) @@ -1,30 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test277p/Test.java") - -from test277p import Test - -cnt = 0 - -class pytest(Test): - - def initialize(self): - global cnt - Test.initialize(self) - cnt += 1 - -pt=pytest() - -support.compare(cnt, "2") - -cnt = 0 - -import java -pt=java.lang.Class.newInstance(pytest) - -support.compare(cnt, "2") - Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-03 04:37:38 UTC (rev 5836) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-04 05:42:44 UTC (rev 5837) @@ -176,17 +176,14 @@ // XXX also __doc__ __module__ + Class<?> proxyClass = null; if (baseClass != null || interfaces.size() != 0) { String proxyName = name; PyObject module = dict.__finditem__("__module__"); if (module != null) { proxyName = module.toString() + "$" + proxyName; } - Class<?> proxyClass = MakeProxies.makeProxy(baseClass, - interfaces, - name, - proxyName, - dict); + proxyClass = MakeProxies.makeProxy(baseClass, interfaces, name, proxyName, dict); PyType proxyType = PyType.fromClass(proxyClass); List<PyObject> cleanedBases = Generic.list(); boolean addedProxyType = false; @@ -203,8 +200,11 @@ bases_list = cleanedBases.toArray(new PyObject[cleanedBases.size()]); } PyType newtype; - if (new_.for_type == metatype) { + if (new_.for_type == metatype || metatype == PyType.fromClass(Class.class)) { newtype = new PyType(); // XXX set metatype + if(proxyClass != null) { + newtype.underlying_class = proxyClass; + } } else { newtype = new PyTypeDerived(metatype); } @@ -1375,7 +1375,11 @@ private String name; TypeResolver(Class<?> underlying_class, String module, String name) { - this.underlying_class = underlying_class; + // Don't store the underlying_class for PyProxies as the proxy type needs to fill in + // based on the class, not be the class + if (underlying_class != null && !PyProxy.class.isAssignableFrom(underlying_class)) { + this.underlying_class = underlying_class; + } this.module = module; this.name = name; } Modified: trunk/jython/src/org/python/expose/BaseTypeBuilder.java =================================================================== --- trunk/jython/src/org/python/expose/BaseTypeBuilder.java 2009-01-03 04:37:38 UTC (rev 5836) +++ trunk/jython/src/org/python/expose/BaseTypeBuilder.java 2009-01-04 05:42:44 UTC (rev 5837) @@ -16,17 +16,17 @@ private PyDataDescr[] descrs; - private Class typeClass; + private Class<?> typeClass; - private Class baseClass; + private Class<?> baseClass; private String name; private boolean isBaseType; public BaseTypeBuilder(String name, - Class typeClass, - Class baseClass, + Class<?> typeClass, + Class<?> baseClass, boolean isBaseType, PyBuiltinMethod[] meths, PyDataDescr[] descrs, @@ -50,7 +50,7 @@ descr.setType(type); dict.__setitem__(descr.getName(), descr); } - if(newWrapper != null) { + if (newWrapper != null) { dict.__setitem__("__new__", newWrapper); newWrapper.setWrappedType(type); } @@ -61,11 +61,11 @@ return name; } - public Class getTypeClass() { + public Class<?> getTypeClass() { return typeClass; } - public Class getBase() { + public Class<?> getBase() { return baseClass; } Modified: trunk/jython/src/org/python/expose/generate/OverridableNewExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/OverridableNewExposer.java 2009-01-03 04:37:38 UTC (rev 5836) +++ trunk/jython/src/org/python/expose/generate/OverridableNewExposer.java 2009-01-04 05:42:44 UTC (rev 5837) @@ -1,9 +1,8 @@ package org.python.expose.generate; +import org.python.core.PyOverridableNew; import org.python.objectweb.asm.Label; import org.python.objectweb.asm.Type; -import org.python.core.PyOverridableNew; -import org.python.core.PyObject; public class OverridableNewExposer extends Exposer { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-04 08:41:20
|
Revision: 5839 http://jython.svn.sourceforge.net/jython/?rev=5839&view=rev Author: cgroves Date: 2009-01-04 08:41:16 +0000 (Sun, 04 Jan 2009) Log Message: ----------- Fixing test288 involved making proxy class method lookup go through __findattr__ on PyObject instead of doing its specialized lookup through the object's dict and type. This means wrapped Java instance method lookup is going through PyObjectDerived's __findattr_ex__ which has a scary comment about its slowness. I'm a little worried this will hurt Java performance, but I'm still holding off on optimizing any of the newstyle java stuff. test278 - Moved to test_java_integration test280 - Tested by test_scope test281,286,289 - Testing jythonc; deleted test282 - Moved to test_class_jy test284 - Tested by test_java_visibility test285 - Moved to test_java_integration test287 - Already disabled, deleted test288 - Moved to test_java_integration test290 - Tested by test_pickle test291 - Tested by test_import_jy Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/compiler/ProxyMaker.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/ReflectedArgs.java trunk/jython/tests/java/org/python/tests/Callbacker.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/BeanImplementation.java trunk/jython/tests/java/org/python/tests/BeanInterface.java Removed Paths: ------------- trunk/jython/bugtests/test278.py trunk/jython/bugtests/test278p/ trunk/jython/bugtests/test280.py trunk/jython/bugtests/test280c.py trunk/jython/bugtests/test281.py trunk/jython/bugtests/test281c.py trunk/jython/bugtests/test282.py trunk/jython/bugtests/test284.py trunk/jython/bugtests/test284j1.java trunk/jython/bugtests/test284j2.java trunk/jython/bugtests/test285.py trunk/jython/bugtests/test286.py trunk/jython/bugtests/test286c.py trunk/jython/bugtests/test287.py trunk/jython/bugtests/test288.py trunk/jython/bugtests/test289.py trunk/jython/bugtests/test289c.py Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/Lib/test/test_class_jy.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -177,6 +177,12 @@ # conflict class D(B, C): pass + + def test_getitem_exceptions(self): + class A: + def __getitem__(self, key): + raise IndexError, "Fraid not" + self.assertRaises(IndexError, A().__getitem__, 'b') class ClassNamelessModuleTestCase(unittest.TestCase): Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -2,18 +2,24 @@ import unittest import sys import re + +from test import test_support -from test import test_support -from java.awt import Dimension, Color, Component, Rectangle -from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector -from java.io import FileOutputStream, FileWriter, OutputStreamWriter - -from java.lang import (Boolean, Class, ClassLoader, ExceptionInInitializerError, Integer, Object, String, - Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) +from java.lang import (Boolean, Class, ClassLoader, ExceptionInInitializerError, Integer, Object, + String, Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) +from java.math import BigDecimal +from java.io import (FileInputStream, FileNotFoundException, FileOutputStream, FileWriter, + OutputStreamWriter, UnsupportedEncodingException) +from java.util import ArrayList, Date, HashMap, Hashtable, StringTokenizer, Vector + +from java.awt import Dimension, Color, Component, Container, Rectangle +from java.awt.event import ComponentEvent from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath -from java.math import BigDecimal +from org.python.core.util import FileUtil +from org.python.tests import BeanImplementation, Callbacker, Listenable +from javatests import MethodInvokationTest """ public abstract class Abstract { public Abstract() { @@ -114,7 +120,6 @@ self.assertRaises(TypeError, Component) def test_str_doesnt_coerce_to_int(self): - from java.util import Date self.assertRaises(TypeError, Date, '99-01-01', 1, 1) def test_Class_newInstance_works_on_proxies(self): @@ -128,9 +133,6 @@ def test_multiple_listeners(self): '''Check that multiple BEP can be assigned to a single cast listener''' - from org.python.tests import Listenable - from java.awt.event import ComponentEvent - from java.awt import Container m = Listenable() called = [] def f(evt, called=called): @@ -143,6 +145,11 @@ self.assertEquals(1, len(called)) m.fireComponentHidden(ComponentEvent(Container(), 0)) self.assertEquals(2, len(called)) + + def test_bean_interface(self): + b = BeanImplementation() + self.assertEquals("name", b.getName()) + self.assertEquals("name", b.name) class ExtendJavaTest(unittest.TestCase): def test_override_tostring(self): @@ -159,6 +166,36 @@ except TypeError: pass + def test_multilevel_override(self): + class SubDate(Date): + def toString(self): + s = Date.toString(self) + return 'SubDate -> Date' + + class SubSubDate(SubDate): + def toString(self): + return 'SubSubDate -> ' + SubDate.toString(self) + self.assertEquals("SubDate -> Date", SubDate().toString()) + self.assertEquals("SubSubDate -> SubDate -> Date", SubSubDate().toString()) + + def test_passthrough(self): + class CallbackPassthrough(Callbacker.Callback): + def __init__(self, worker): + self.worker = worker + + def __getattribute__(self, name): + if name == 'call': + return getattr(self.worker, name) + return object.__getattribute__(self, name) + + collector = Callbacker.CollectingCallback() + c = CallbackPassthrough(collector) + Callbacker.callNoArg(c) + self.assertEquals("call()", collector.calls[0]) + c.call(7) + self.assertEquals("call(7)", collector.calls[1]) + + class SysIntegrationTest(unittest.TestCase): def setUp(self): self.orig_stdout = sys.stdout @@ -204,16 +241,13 @@ class IOTest(unittest.TestCase): def test_io_errors(self): "Check that IOException isn't mangled into an IOError" - from java.io import UnsupportedEncodingException self.assertRaises(UnsupportedEncodingException, OutputStreamWriter, System.out, "garbage") self.assertRaises(IOError, OutputStreamWriter, System.out, "garbage") def test_fileio_error(self): - from java.io import FileInputStream, FileNotFoundException self.assertRaises(FileNotFoundException, FileInputStream, "garbage") def test_unsupported_tell(self): - from org.python.core.util import FileUtil fp = FileUtil.wrap(System.out) self.assertRaises(IOError, fp.tell) @@ -436,10 +470,8 @@ self.assertEquals(expectedClass, model.getColumnClass(i)) class BigDecimalTest(unittest.TestCase): - def test_coerced_bigdecimal(self): from javatests import BigDecimalTest - x = BigDecimal("123.4321") y = BigDecimalTest().asBigDecimal() @@ -449,8 +481,6 @@ class MethodInvTest(unittest.TestCase): def test_method_invokation(self): - from javatests import MethodInvokationTest - bar = MethodInvokationTest.foo1(Byte(10)) self.assertEquals(bar, "foo1 with byte arg: 10", "Wrong method called") @@ -458,7 +488,6 @@ class InterfaceTest(unittest.TestCase): def test_override(self): - from java.lang import String class Foo(Runnable): def run(self): pass def toString(self): return "Foo!!!" @@ -469,7 +498,6 @@ self.assertEquals(s, "Foo!!!", "toString not overridden in interface") def test_java_calling_python_interface_implementation(self): - from org.python.tests import Callbacker called = [] class PyCallback(Callbacker.Callback): def call(self, extraarg=None): Deleted: trunk/jython/bugtests/test278.py =================================================================== --- trunk/jython/bugtests/test278.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test278.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,17 +0,0 @@ - - -""" - -""" - -import support - -support.compileJava("test278p/bug.java", classpath=".") - -from test278p import bug -b=bug() -assert b.getName() == "name" -assert b.name== "name" - - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test280.py =================================================================== --- trunk/jython/bugtests/test280.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test280.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -try: - import test280c -except UnboundLocalError: - pass -else: - raise support.TestError("Should raise UnboundLocalError") Deleted: trunk/jython/bugtests/test280c.py =================================================================== --- trunk/jython/bugtests/test280c.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test280c.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,6 +0,0 @@ - -x = 1 -def f(): - print x - x = 2 -f() \ No newline at end of file Deleted: trunk/jython/bugtests/test281.py =================================================================== --- trunk/jython/bugtests/test281.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test281.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test281c.py", core=1, jar="test281c.jar", output="test281.err") -support.runJava("test281c", classpath="test281c.jar") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test281c.py =================================================================== --- trunk/jython/bugtests/test281c.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test281c.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,16 +0,0 @@ -""" - -""" - -import support - - -if __name__ == "__main__": - try: - raise "me" - except: - pass - else: - raise support.TestError("Should not happen") - - Deleted: trunk/jython/bugtests/test282.py =================================================================== --- trunk/jython/bugtests/test282.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test282.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,16 +0,0 @@ -""" - -""" - -import support - -class A: - def __getitem__(self, key): - raise IndexError, "hello" - -try: - A()['b'] -except IndexError: - pass -else: - raise support.TestError("Should raise IndexError") Deleted: trunk/jython/bugtests/test284.py =================================================================== --- trunk/jython/bugtests/test284.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test284.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,12 +0,0 @@ - -import support - -support.compileJava("test284j2.java", classpath=".") - -import test284j1 - -assert test284j1().foo() == 'test284j1.foo' - -import test284j2 - -assert test284j2().foo() == 'test284j2.foo' Deleted: trunk/jython/bugtests/test284j1.java =================================================================== --- trunk/jython/bugtests/test284j1.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test284j1.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,6 +0,0 @@ - -public class test284j1 { - public String foo() { - return "test284j1.foo"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test284j2.java =================================================================== --- trunk/jython/bugtests/test284j2.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test284j2.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,6 +0,0 @@ - -public class test284j2 extends test284j1 { - public String foo() { - return "test284j2.foo"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test285.py =================================================================== --- trunk/jython/bugtests/test285.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test285.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,17 +0,0 @@ -""" -Test multilevel overriding of java methods. -""" - -from java.util import Date - -class SubDate(Date): - def toString(self): - s = Date.toString(self) - return 'SubDate -> Date' - -class SubSubDate(SubDate): - def toString(self): - return 'SubSubDate -> ' + SubDate.toString(self) - -assert SubDate().toString() == 'SubDate -> Date' -assert SubSubDate().toString() == 'SubSubDate -> SubDate -> Date' Deleted: trunk/jython/bugtests/test286.py =================================================================== --- trunk/jython/bugtests/test286.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test286.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,8 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test286c.py", output="test286.err") -support.runJava("test286c", classpath="jpywork") Deleted: trunk/jython/bugtests/test286c.py =================================================================== --- trunk/jython/bugtests/test286c.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test286c.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,17 +0,0 @@ -""" -Test multilevel overriding of java methods in jythonc. -""" - -from java.util import Date - -class SubDate(Date): - def toString(self): - s = Date.toString(self) - return 'SubDate -> Date' - -class SubSubDate(SubDate): - def toString(self): - return 'SubSubDate -> ' + SubDate.toString(self) - -assert SubDate().toString() == 'SubDate -> Date' -assert SubSubDate().toString() == 'SubSubDate -> SubDate -> Date' Deleted: trunk/jython/bugtests/test287.py =================================================================== --- trunk/jython/bugtests/test287.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test287.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,22 +0,0 @@ -""" - -""" - -import support - -raise support.TestWarning("mixing base classes between Jython and Java is not supported") - -import java.util -import org.python.core -class LX(org.python.core.PyList,java.util.List): - pass - -l = LX() - -try: - l.add('x') -except AttributeError: - pass -else: - raise support.TestError("expected an AttributeError") - Deleted: trunk/jython/bugtests/test288.py =================================================================== --- trunk/jython/bugtests/test288.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test288.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,46 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test288j.java") - -import test288j, test288i - - -class t: - def __init__(self, s): - self.s = s - - def __getattr__(self, name): - return getattr(self.s, name) - -class u(test288i): - def __init__(self, s): - self.s = s - - def get(self, i=None): - if i: - return self.s.get(i) - else: - return self.s.get() - -class v(test288i): - def __init__(self, s): - self.s = s - - def __getattr__(self, name): - return getattr(self.s, name) - -def main(): - y = v(test288j()) - y.get() - y.get(2) - y.get() - y.get(0) - -if __name__ == '__main__': - main() - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test289.py =================================================================== --- trunk/jython/bugtests/test289.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test289.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test288j.java") - -support.compileJPythonc("test289c.py", output="test289.err") -support.runJava("test289c", classpath="jpywork", pass_jython_home=1) Deleted: trunk/jython/bugtests/test289c.py =================================================================== --- trunk/jython/bugtests/test289c.py 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/bugtests/test289c.py 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,45 +0,0 @@ -""" - -""" - -import support - - -import test288j, test288i - - -class t: - def __init__(self, s): - self.s = s - - def __getattr__(self, name): - return getattr(self.s, name) - -class u(test288i): - def __init__(self, s): - self.s = s - - def get(self, i=None): - if i: - return self.s.get(i) - else: - return self.s.get() - -class v(test288i): - def __init__(self, s): - self.s = s - - def __getattr__(self, name): - return getattr(self.s, name) - -def main(): - y = v(test288j()) - y.get() - y.get(2) - y.get() - y.get(0) - -if __name__ == '__main__': - main() - -#raise support.TestError("" + `x`) Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -12,9 +12,10 @@ import java.util.Set; import org.python.core.Py; -import org.python.core.PyJavaType; +import org.python.core.PyMethod; import org.python.core.PyObject; import org.python.core.PyProxy; +import org.python.core.PyReflectedFunction; import org.python.objectweb.asm.Label; import org.python.objectweb.asm.Opcodes; import org.python.util.Generic; @@ -66,22 +67,21 @@ proxy.__initProxy__(new Object[0]); o = proxy._getPyInstance(); } - PyObject ret = null; - if (o.getDict() != null) { - ret = o.getDict().__finditem__(name); - } - if (ret == null) { - PyObject[] definedOn = new PyObject[1]; - PyObject typeDefined = o.getType().lookup_where(name, definedOn); - if (!(definedOn[0] instanceof PyJavaType)) { - ret = typeDefined; + PyObject ret = o.__findattr__(name); + if (ret instanceof PyMethod) { + PyMethod meth = ((PyMethod)ret); + if (meth.im_func instanceof PyReflectedFunction) { + PyReflectedFunction func = (PyReflectedFunction)meth.im_func; + if (func.nargs > 0 && proxy.getClass() == func.argslist[0].declaringClass) { + // This function is the default return for the proxy type if the Python instance + // hasn't returned something of its own from __findattr__, so do the standard + // Java call on this + return null; + } } } - if (ret == null) { - return null; - } Py.setSystemState(proxy._getPySystemState()); - return ret.__get__(o, null); + return ret; } Class<?> superclass; Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -145,22 +145,31 @@ public PyObject __call__(PyObject self, PyObject[] args, String[] keywords) { ReflectedCallData callData = new ReflectedCallData(); - Object method = null; - ReflectedArgs[] argsl = argslist; - int n = nargs; - for (int i = 0; i < n; i++) { - ReflectedArgs rargs = argsl[i]; + ReflectedArgs match = null; + for (int i = 0; i < nargs && match == null; i++) { // System.err.println(rargs.toString()); - if (rargs.matches(self, args, keywords, callData)) { - method = rargs.data; - break; + if (argslist[i].matches(self, args, keywords, callData)) { + match = argslist[i]; } } - if (method == null) { + if (match == null) { throwError(callData.errArg, args.length, self != null, keywords.length != 0); } Object cself = callData.self; - Method m = (Method)method; + Method m = (Method)match.data; + + // If this is a direct call to a Java class instance method with a PyProxy instance as the + // arg, use the super__ version to actually route this through the method on the class. + if (self == null && cself != null && cself instanceof PyProxy + && !__name__.startsWith("super__") + && match.declaringClass != cself.getClass()) { + String mname = ("super__" + __name__); + try { + m = cself.getClass().getMethod(mname, m.getParameterTypes()); + } catch (Exception e) { + throw Py.JavaError(e); + } + } Object o; try { o = m.invoke(cself, callData.getArgsArray()); @@ -247,7 +256,7 @@ } } - private static String niceName(Class arg) { + private static String niceName(Class<?> arg) { if (arg == String.class || arg == PyString.class) { return "String"; } @@ -260,11 +269,10 @@ protected void throwBadArgError(int errArg, int nArgs, boolean self) { Set<Class<?>> argTypes = Generic.set(); for (int i = 0; i < nargs; i++) { - // if (!args.isStatic && !self) { len = len-1; } // This check works almost all the time. - // I'm still a little worried about non-static methods - // called with an explict self... - if (argslist[i].args.length == nArgs) { + // I'm still a little worried about non-static methods called with an explicit self... + if (argslist[i].args.length == nArgs || + (!argslist[i].isStatic && !self && argslist[i].args.length == nArgs - 1)) { if (errArg == ReflectedCallData.UNABLE_TO_CONVERT_SELF) { argTypes.add(argslist[i].declaringClass); } else { Modified: trunk/jython/src/org/python/core/ReflectedArgs.java =================================================================== --- trunk/jython/src/org/python/core/ReflectedArgs.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/src/org/python/core/ReflectedArgs.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,7 +1,7 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -class ReflectedArgs { +public class ReflectedArgs { public Class[] args; public Object data; @@ -258,10 +258,9 @@ } public String toString() { - String s = "" + this.declaringClass + ", " + this.isStatic + ", " + this.flags + ", " - + this.data + "\n"; + String s = declaringClass + ", " + isStatic + ", " + flags + ", " + data + "\n"; s = s + "\t("; - for (Class arg : this.args) { + for (Class<?> arg : args) { s += arg.getName() + ", "; } s += ")"; Added: trunk/jython/tests/java/org/python/tests/BeanImplementation.java =================================================================== --- trunk/jython/tests/java/org/python/tests/BeanImplementation.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/BeanImplementation.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -0,0 +1,9 @@ +package org.python.tests; + + +public class BeanImplementation implements BeanInterface { + + public String getName() { + return "name"; + } +} Added: trunk/jython/tests/java/org/python/tests/BeanInterface.java =================================================================== --- trunk/jython/tests/java/org/python/tests/BeanInterface.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/BeanInterface.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -0,0 +1,6 @@ +package org.python.tests; + + +public interface BeanInterface { + String getName(); +} Modified: trunk/jython/tests/java/org/python/tests/Callbacker.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Callbacker.java 2009-01-04 05:48:09 UTC (rev 5838) +++ trunk/jython/tests/java/org/python/tests/Callbacker.java 2009-01-04 08:41:16 UTC (rev 5839) @@ -1,5 +1,9 @@ package org.python.tests; +import java.util.List; + +import org.python.util.Generic; + public class Callbacker { public interface Callback { @@ -9,6 +13,19 @@ public void call(long oneArg); } + public static class CollectingCallback implements Callback { + + public List<String> calls = Generic.list(); + + public void call() { + calls.add("call()"); + } + + public void call(long oneArg) { + calls.add("call(" + oneArg + ")"); + } + } + public static void callNoArg(Callback c) { c.call(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-04 22:15:14
|
Revision: 5842 http://jython.svn.sourceforge.net/jython/?rev=5842&view=rev Author: cgroves Date: 2009-01-04 22:15:09 +0000 (Sun, 04 Jan 2009) Log Message: ----------- Split java subclassing tests out of test_java_integration into test_java_subclasses, move unduplicated bits of test_jsubclass into test_java_subclasses. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyReflectedConstructor.java trunk/jython/tests/java/org/python/tests/Coercions.java Added Paths: ----------- trunk/jython/Lib/test/test_java_subclasses.py Removed Paths: ------------- trunk/jython/Lib/test/test_jsubclass.py trunk/jython/bugtests/classes/test288i.java trunk/jython/bugtests/classes/test288j.java trunk/jython/bugtests/test290.py trunk/jython/bugtests/test291.py trunk/jython/tests/java/javatests/MethodInvokationTest.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -5,127 +5,32 @@ from test import test_support -from java.lang import (Boolean, Class, ClassLoader, ExceptionInInitializerError, Integer, Object, - String, Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) +from java.lang import (ExceptionInInitializerError, String, Runnable, System, Runtime, Math, Byte) from java.math import BigDecimal from java.io import (FileInputStream, FileNotFoundException, FileOutputStream, FileWriter, OutputStreamWriter, UnsupportedEncodingException) from java.util import ArrayList, Date, HashMap, Hashtable, StringTokenizer, Vector -from java.awt import Dimension, Color, Component, Container, Rectangle +from java.awt import Dimension, Color, Component, Container from java.awt.event import ComponentEvent -from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath from org.python.core.util import FileUtil -from org.python.tests import BeanImplementation, Callbacker, Listenable -from javatests import MethodInvokationTest -""" -public abstract class Abstract { - public Abstract() { - method(); - } +from org.python.tests import BeanImplementation, Listenable - public abstract void method(); -} -""" -# The following is the correspoding bytecode for Abstract compiled with javac 1.5 -ABSTRACT_CLASS = """\ -eJw1TrsKwkAQnI1nEmMe/oKdSaHYiyCClWih2F+SQyOaQDz9LxsFCz/AjxL3Am6xw8zs7O7n+3oD -GKPnQcD30ELgIHQQEexJURZ6SmgN4h1BzKtcEaJlUarV9ZyqeivTEyv2WelDlRO8TXWtM7UojBrM -0ouuZaaHR3mTPtqwfXRgE9y/Q+gZb3SS5X60To8q06LPHwiYskAmxN1hFjMSYyd5gpIHrDsT3sU9 -5IgZF4wuhCBzpnG9Ru/+AF4RJn8= -""".decode('base64').decode('zlib') - -class AbstractOnSyspathTest(unittest.TestCase): - '''Subclasses an abstract class that isn't on the startup classpath. - - Checks for http://jython.org/bugs/1861985 - ''' - def setUp(self): - out = open('Abstract.class', 'w') - out.write(ABSTRACT_CLASS) - out.close() - self.orig_syspath = sys.path[:] - sys.path.append('') - - def tearDown(self): - os.unlink('Abstract.class') - sys.path = self.orig_syspath - - def test_can_subclass_abstract(self): - import Abstract - - class A(Abstract): - def method(self): - pass - A() - -""" -public abstract class ContextAbstract { - public ContextAbstract() { - method(); - } - - public abstract void method(); -} -""" -# The following is the correspoding bytecode for ContextAbstract compiled with javac 1.5 -# Needs to be named differently than Abstract above so the class loader won't just use it -CONTEXT_ABSTRACT = '''\ -eJxdjr1uwjAUhc8lbgIh/AVegA0YQJ1BlRBSp6gdWrE7wQKjEEvBVH0tFip14AF4KMQ17YSHc3yu -vuPry/X3DOAZ3RACrRAe2gE6AWKCP9OFti8EbzBcEsTCrBShlehCvR12qSo/ZZrzJE5MJvOlLLXL -/0NhN3pP6CQLU1j1befp3pYys1N+d6fsxqwI4Yc5lJl61a7QewDHW/klIzzBjxDB58UPAKHtkEku -i/XkPd2qzIo+/1/AnQrIdVkDTlN2Yq+NfkCjEyrHO1JlbXLF3QV7lbXGKfqDEaIOCHL7ORMad7J5 -A7yvPDQ= -'''.decode('base64').decode('zlib') -class ContextClassloaderTest(unittest.TestCase): - '''Classes on the context classloader should be importable and subclassable. - - http://bugs.jython.org/issue1216''' - def setUp(self): - self.orig_context = Thread.currentThread().contextClassLoader - class AbstractLoader(ClassLoader): - def __init__(self): - ClassLoader.__init__(self) - c = self.super__defineClass("ContextAbstract", CONTEXT_ABSTRACT, 0, - len(CONTEXT_ABSTRACT), ClassLoader.protectionDomain) - self.super__resolveClass(c) - Thread.currentThread().contextClassLoader = AbstractLoader() - - def tearDown(self): - Thread.currentThread().contextClassLoader = self.orig_context - - def test_can_subclass_abstract(self): - import ContextAbstract - - called = [] - class A(ContextAbstract): - def method(self): - called.append(True) - A() - self.assertEquals(len(called), 1) - -# The no-arg constructor for proxies attempts to look up its Python class by the Python class' name, -# so the class needs to be visible at the module level or the import will fail -class ModuleVisibleJavaSubclass(Object): - pass class InstantiationTest(unittest.TestCase): - def test_can_subclass_abstract(self): - class A(Component): - pass - A() - def test_cant_instantiate_abstract(self): self.assertRaises(TypeError, Component) + def test_no_public_constructors(self): + self.assertRaises(TypeError, Math) + + def test_invalid_self_to_java_constructor(self): + self.assertRaises(TypeError, Color.__init__, 10, 10, 10) + def test_str_doesnt_coerce_to_int(self): self.assertRaises(TypeError, Date, '99-01-01', 1, 1) - def test_Class_newInstance_works_on_proxies(self): - Class.newInstance(ModuleVisibleJavaSubclass) - - class BeanTest(unittest.TestCase): def test_shared_names(self): self.failUnless(callable(Vector.size), @@ -151,51 +56,7 @@ self.assertEquals("name", b.getName()) self.assertEquals("name", b.name) -class ExtendJavaTest(unittest.TestCase): - def test_override_tostring(self): - class A(Object): - def toString(self): - return 'name' - self.assertEquals('name', String.valueOf(A())) - def test_multiple_inheritance_prohibited(self): - try: - class MultiJava(Dimension, Color): - pass - self.fail("Shouldn't be able to subclass more than one concrete java class") - except TypeError: - pass - - def test_multilevel_override(self): - class SubDate(Date): - def toString(self): - s = Date.toString(self) - return 'SubDate -> Date' - - class SubSubDate(SubDate): - def toString(self): - return 'SubSubDate -> ' + SubDate.toString(self) - self.assertEquals("SubDate -> Date", SubDate().toString()) - self.assertEquals("SubSubDate -> SubDate -> Date", SubSubDate().toString()) - - def test_passthrough(self): - class CallbackPassthrough(Callbacker.Callback): - def __init__(self, worker): - self.worker = worker - - def __getattribute__(self, name): - if name == 'call': - return getattr(self.worker, name) - return object.__getattribute__(self, name) - - collector = Callbacker.CollectingCallback() - c = CallbackPassthrough(collector) - Callbacker.callNoArg(c) - self.assertEquals("call()", collector.calls[0]) - c.call(7) - self.assertEquals("call(7)", collector.calls[1]) - - class SysIntegrationTest(unittest.TestCase): def setUp(self): self.orig_stdout = sys.stdout @@ -212,32 +73,6 @@ self.assertEquals('hello', f.read()) f.close() -class AutoSuperTest(unittest.TestCase): - def test_auto_super(self): - class R(Rectangle): - def __init__(self): - self.size = Dimension(6, 7) - self.assert_("width=6,height=7" in R().toString()) - - def test_no_default_constructor(self): - "Check autocreation when java superclass misses a default constructor." - class A(ThreadGroup): - def __init__(self): - print self.name - self.assertRaises(TypeError, A) - - def test_no_public_constructors(self): - self.assertRaises(TypeError, Math) - -class PyObjectCmpTest(unittest.TestCase): - def test_vect_cmp(self): - "Check comparing a PyJavaClass with a Object." - class X(Runnable): - pass - v = Vector() - v.addElement(1) - v.indexOf(X()) - class IOTest(unittest.TestCase): def test_io_errors(self): "Check that IOException isn't mangled into an IOError" @@ -252,20 +87,6 @@ self.assertRaises(IOError, fp.tell) -class VectorTest(unittest.TestCase): - def test_looping(self): - for i in Vector(): pass - - def test_return_proxy(self): - "Jython proxies properly return back from Java code" - class FooVector(Vector): - bar = 99 - - ht = Hashtable() - fv = FooVector() - ht.put("a", fv) - self.failUnless(fv is ht.get("a")) - class JavaReservedNamesTest(unittest.TestCase): "Access to reserved words" @@ -419,7 +240,6 @@ self.assertRaises(ExceptionInInitializerError, __import__, "org.python.tests.BadStaticInitializer") class ColorTest(unittest.TestCase): - def test_assigning_over_method(self): self.assertRaises(TypeError, setattr, Color.RED, "getRGB", 4) @@ -436,39 +256,11 @@ self.assert_(red is Color.red) class TreePathTest(unittest.TestCase): - def test_overloading(self): treePath = TreePath([1,2,3]) self.assertEquals(len(treePath.path), 3, "Object[] not passed correctly") self.assertEquals(TreePath(treePath.path).path, treePath.path, "Object[] not passed and returned correctly") -class TableModelTest(unittest.TestCase): - def test_column_classes(self): - class TableModel(AbstractTableModel): - columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" - data = [("Mary", "Campione", "Snowboarding", 5, False)] - - def getColumnCount(self): - return len(self.columnNames) - - def getRowCount(self): - return len(self.data) - - def getColumnName(self, col): - return self.columnNames[col] - - def getValueAt(self, row, col): - return self.data[row][col] - - def getColumnClass(self, c): - return Object.getClass(self.getValueAt(0, c)) - - def isCellEditable(self, row, col): - return col >= 2 - model = TableModel() - for i, expectedClass in enumerate([String, String, String, Integer, Boolean]): - self.assertEquals(expectedClass, model.getColumnClass(i)) - class BigDecimalTest(unittest.TestCase): def test_coerced_bigdecimal(self): from javatests import BigDecimalTest @@ -478,41 +270,7 @@ self.assertEqual(type(x), type(y), "BigDecimal coerced") self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") -class MethodInvTest(unittest.TestCase): - - def test_method_invokation(self): - bar = MethodInvokationTest.foo1(Byte(10)) - - self.assertEquals(bar, "foo1 with byte arg: 10", "Wrong method called") - -class InterfaceTest(unittest.TestCase): - - def test_override(self): - class Foo(Runnable): - def run(self): pass - def toString(self): return "Foo!!!" - - foo = Foo() - s = String.valueOf(foo) - - self.assertEquals(s, "Foo!!!", "toString not overridden in interface") - - def test_java_calling_python_interface_implementation(self): - called = [] - class PyCallback(Callbacker.Callback): - def call(self, extraarg=None): - called.append(extraarg) - Callbacker.callNoArg(PyCallback()) - Callbacker.callOneArg(PyCallback(), 4294967295L) - self.assertEquals(None, called[0]) - self.assertEquals(4294967295L, called[1]) - class PyBadCallback(Callbacker.Callback): - def call(pyself, extraarg): - self.fail("Shouldn't be callable with a no args") - self.assertRaises(TypeError, Callbacker.callNoArg, PyBadCallback()) - class JavaStringTest(unittest.TestCase): - def test_string_not_iterable(self): x = String('test') self.assertRaises(TypeError, list, x) @@ -551,27 +309,26 @@ tokenizer = StringTokenizer('foo bar') self.assertEquals(list(iter(tokenizer)), ['foo', 'bar']) + def test_vector_delegation(self): + class X(Runnable): + pass + v = Vector() + v.addElement(1) + v.indexOf(X())# Compares the Java object in the vector to a Python subclass + for i in v: + pass def test_main(): - test_support.run_unittest(AbstractOnSyspathTest, - ContextClassloaderTest, - InstantiationTest, + test_support.run_unittest(InstantiationTest, BeanTest, - ExtendJavaTest, SysIntegrationTest, - AutoSuperTest, - PyObjectCmpTest, IOTest, - VectorTest, JavaReservedNamesTest, PyReservedNamesTest, ImportTest, ColorTest, - TableModelTest, TreePathTest, BigDecimalTest, - MethodInvTest, - InterfaceTest, JavaStringTest, JavaDelegationTest, ) Added: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py (rev 0) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -0,0 +1,243 @@ +'''Tests subclassing Java classes in Python''' +import os +import sys +import unittest + +from test import test_support + +from java.lang import (Boolean, Class, ClassLoader, Integer, Object, Runnable, String, Thread, + ThreadGroup) +from java.util import Date, Hashtable, Vector + +from java.awt import Color, Component, Dimension, Rectangle +from javax.swing.table import AbstractTableModel + +from org.python.tests import Callbacker + +class InterfaceTest(unittest.TestCase): + def test_java_calling_python_interface_implementation(self): + called = [] + class PyCallback(Callbacker.Callback): + def call(self, extraarg=None): + called.append(extraarg) + Callbacker.callNoArg(PyCallback()) + Callbacker.callOneArg(PyCallback(), 4294967295L) + self.assertEquals(None, called[0]) + self.assertEquals(4294967295L, called[1]) + class PyBadCallback(Callbacker.Callback): + def call(pyself, extraarg): + self.fail("Shouldn't be callable with a no args") + self.assertRaises(TypeError, Callbacker.callNoArg, PyBadCallback()) + +class TableModelTest(unittest.TestCase): + def test_class_coercion(self): + '''Python type instances coerce to a corresponding Java wrapper type in Object.getClass''' + class TableModel(AbstractTableModel): + columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" + data = [("Mary", "Campione", "Snowboarding", 5, False)] + + def getColumnCount(self): + return len(self.columnNames) + + def getRowCount(self): + return len(self.data) + + def getColumnName(self, col): + return self.columnNames[col] + + def getValueAt(self, row, col): + return self.data[row][col] + + def getColumnClass(self, c): + return Object.getClass(self.getValueAt(0, c)) + + def isCellEditable(self, row, col): + return col >= 2 + + model = TableModel() + for i, expectedClass in enumerate([String, String, String, Integer, Boolean]): + self.assertEquals(expectedClass, model.getColumnClass(i)) + +class AutoSuperTest(unittest.TestCase): + def test_auto_super(self): + class Implicit(Rectangle): + def __init__(self): + self.size = Dimension(6, 7) + class Explicit(Rectangle): + def __init__(self): + Rectangle.__init__(self, 6, 7) + self.assert_("width=6,height=7" in Implicit().toString()) + self.assert_("width=6,height=7" in Explicit().toString()) + + def test_no_default_constructor(self): + "Check autocreation when java superclass misses a default constructor." + class A(ThreadGroup): + def __init__(self): + print self.name + self.assertRaises(TypeError, A) + +# The no-arg constructor for proxies attempts to look up its Python class by the Python class' name, +# so the class needs to be visible at the module level or the import will fail +class ModuleVisibleJavaSubclass(Object): + pass +class PythonSubclassesTest(unittest.TestCase): + def test_multiple_inheritance_prohibited(self): + try: + class MultiJava(Dimension, Color): + pass + self.fail("Shouldn't be able to subclass more than one concrete java class") + except TypeError: + pass + + def test_multilevel_override(self): + class SubDate(Date): + def toString(self): + s = Date.toString(self) + return 'SubDate -> Date' + + class SubSubDate(SubDate): + def toString(self): + return 'SubSubDate -> ' + SubDate.toString(self) + self.assertEquals("SubDate -> Date", SubDate().toString()) + self.assertEquals("SubSubDate -> SubDate -> Date", SubSubDate().toString()) + + def test_passthrough(self): + class CallbackPassthrough(Callbacker.Callback): + def __init__(self, worker): + self.worker = worker + + def __getattribute__(self, name): + if name == 'call': + return getattr(self.worker, name) + return object.__getattribute__(self, name) + + collector = Callbacker.CollectingCallback() + c = CallbackPassthrough(collector) + Callbacker.callNoArg(c) + self.assertEquals("call()", collector.calls[0]) + c.call(7) + self.assertEquals("call(7)", collector.calls[1]) + + def test_Class_newInstance_works_on_proxies(self): + Class.newInstance(ModuleVisibleJavaSubclass) + + def test_override(self): + class Foo(Runnable): + def toString(self): return "Foo" + self.assertEquals(String.valueOf(Foo()), "Foo", "toString not overridden in interface") + + class A(Object): + def toString(self): + return 'name' + self.assertEquals('name', String.valueOf(A()), 'toString not overriden in subclass') + + def test_can_subclass_abstract(self): + class A(Component): + pass + A() + + def test_return_proxy(self): + "Jython proxies properly return back from Java code" + class FooVector(Vector): + bar = 99 + + ht = Hashtable() + fv = FooVector() + ht.put("a", fv) + self.failUnless(fv is ht.get("a")) + + +""" +public abstract class Abstract { + public Abstract() { + method(); + } + + public abstract void method(); +} +""" +# The following is the correspoding bytecode for Abstract compiled with javac 1.5 +ABSTRACT_CLASS = """\ +eJw1TrsKwkAQnI1nEmMe/oKdSaHYiyCClWih2F+SQyOaQDz9LxsFCz/AjxL3Am6xw8zs7O7n+3oD +GKPnQcD30ELgIHQQEexJURZ6SmgN4h1BzKtcEaJlUarV9ZyqeivTEyv2WelDlRO8TXWtM7UojBrM +0ouuZaaHR3mTPtqwfXRgE9y/Q+gZb3SS5X60To8q06LPHwiYskAmxN1hFjMSYyd5gpIHrDsT3sU9 +5IgZF4wuhCBzpnG9Ru/+AF4RJn8= +""".decode('base64').decode('zlib') + +class AbstractOnSyspathTest(unittest.TestCase): + '''Subclasses an abstract class that isn't on the startup classpath. + + Checks for http://jython.org/bugs/1861985 + ''' + def setUp(self): + out = open('Abstract.class', 'w') + out.write(ABSTRACT_CLASS) + out.close() + self.orig_syspath = sys.path[:] + sys.path.append('') + + def tearDown(self): + os.unlink('Abstract.class') + sys.path = self.orig_syspath + + def test_can_subclass_abstract(self): + import Abstract + + class A(Abstract): + def method(self): + pass + A() + +""" +public abstract class ContextAbstract { + public ContextAbstract() { + method(); + } + + public abstract void method(); +} +""" +# The following is the correspoding bytecode for ContextAbstract compiled with javac 1.5 +# Needs to be named differently than Abstract above so the class loader won't just use it +CONTEXT_ABSTRACT = '''\ +eJxdjr1uwjAUhc8lbgIh/AVegA0YQJ1BlRBSp6gdWrE7wQKjEEvBVH0tFip14AF4KMQ17YSHc3yu +vuPry/X3DOAZ3RACrRAe2gE6AWKCP9OFti8EbzBcEsTCrBShlehCvR12qSo/ZZrzJE5MJvOlLLXL +/0NhN3pP6CQLU1j1befp3pYys1N+d6fsxqwI4Yc5lJl61a7QewDHW/klIzzBjxDB58UPAKHtkEku +i/XkPd2qzIo+/1/AnQrIdVkDTlN2Yq+NfkCjEyrHO1JlbXLF3QV7lbXGKfqDEaIOCHL7ORMad7J5 +A7yvPDQ= +'''.decode('base64').decode('zlib') +class ContextClassloaderTest(unittest.TestCase): + '''Classes on the context classloader should be importable and subclassable. + + http://bugs.jython.org/issue1216''' + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + class AbstractLoader(ClassLoader): + def __init__(self): + ClassLoader.__init__(self) + c = self.super__defineClass("ContextAbstract", CONTEXT_ABSTRACT, 0, + len(CONTEXT_ABSTRACT), ClassLoader.protectionDomain) + self.super__resolveClass(c) + Thread.currentThread().contextClassLoader = AbstractLoader() + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + + def test_can_subclass_abstract(self): + import ContextAbstract + + called = [] + class A(ContextAbstract): + def method(self): + called.append(True) + A() + self.assertEquals(len(called), 1) + + +def test_main(): + test_support.run_unittest(InterfaceTest, + TableModelTest, + AutoSuperTest, + PythonSubclassesTest, + AbstractOnSyspathTest, + ContextClassloaderTest) Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -3,7 +3,7 @@ import subprocess import sys from test import test_support -from java.lang import Class +from java.lang import Byte, Class from java.util import HashMap, Observable, Observer from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) @@ -157,6 +157,7 @@ self.assertEquals("5", c.takeInt(5)) self.assertEquals("15", c.takeInteger(15)) self.assertEquals("150", c.takeNumber(150)) + self.assertEquals("take with byte arg: 10", Coercions.take(Byte(10))) def test_array_coercion(self): self.assertEquals("double", Coercions.takeArray(array.zeros('d', 2))) Deleted: trunk/jython/Lib/test/test_jsubclass.py =================================================================== --- trunk/jython/Lib/test/test_jsubclass.py 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/Lib/test/test_jsubclass.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,49 +0,0 @@ -from test_support import * - -print 'Subclassing Java from Python (test_jsubclass.py)' - -from java.lang import Runnable, Thread - -# Overriding Methods - -print 'override methods' -class MyThread(Thread): - count = 0 - def run(self): - self.count = self.count+1 - - -t1 = MyThread() -t1.start() -t1.join() -assert t1.count == 1, 'subclassing java.lang.Thread' - -print 'pass subclass back to java' - -class MyRun(Runnable): - count = 0 - def run(self): - self.count = self.count+1 - -run = MyRun() -t = Thread(run) -t.start() -t.join() -assert run.count == 1, 'subclassing java.lang.Thread' - -print "invoke super's constructor" - -class MyThread(Thread): - def __init__(self): - self.name = "Python-"+self.name - -t = MyThread() -assert t.name[:14] == "Python-Thread-", 'automatic constructor call' - -class MyThread(Thread): - def __init__(self): - Thread.__init__(self, "Python-Thread") - -t = MyThread() -assert t.name == "Python-Thread", 'explicit constructor call' - Deleted: trunk/jython/bugtests/classes/test288i.java =================================================================== --- trunk/jython/bugtests/classes/test288i.java 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/bugtests/classes/test288i.java 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,4 +0,0 @@ -public interface test288i { - public int get(); - public int get(int i); -} Deleted: trunk/jython/bugtests/classes/test288j.java =================================================================== --- trunk/jython/bugtests/classes/test288j.java 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/bugtests/classes/test288j.java 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,14 +0,0 @@ - -public class test288j extends Object implements test288i { - protected int last; - public test288j() { - this.last = 0; - } - public int get() { - return this.last; - } - public int get(int i) { - this.last = i; - return i; - } -} Deleted: trunk/jython/bugtests/test290.py =================================================================== --- trunk/jython/bugtests/test290.py 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/bugtests/test290.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,11 +0,0 @@ -""" -test newline in text pickles #437215 -""" - -import pickle -s1="line1\nline2\nline3" -s2="line4\nline5\nline6" -l = [s1, s2] -p = pickle.dumps(l) # newlines won't be escaped -l2 = pickle.loads(p) # blows up - Deleted: trunk/jython/bugtests/test291.py =================================================================== --- trunk/jython/bugtests/test291.py 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/bugtests/test291.py 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,18 +0,0 @@ -""" -Test keywords to import builtin. -""" - -import support - -impl_names = ['java'] - -# Will only return anygui :P -try: - impls = [__import__('anygui.impl.%sgui' % name, - fromlist=['%sgui' % name]) for name in impl_names] -except TypeError, e: - support.compare(e, "__import__\(\) takes no keyword arguments"); -else: - support.TestError("Should raise a TypeError") - - Modified: trunk/jython/src/org/python/core/PyReflectedConstructor.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedConstructor.java 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/src/org/python/core/PyReflectedConstructor.java 2009-01-04 22:15:09 UTC (rev 5842) @@ -82,6 +82,9 @@ throw Py.TypeError("invalid self argument to constructor"); } Class<?> javaClass = self.getType().getProxyType(); + if (javaClass == null) { + throw Py.TypeError("self invalid - must be a Java subclass [self=" + self + "]"); + } Class<?> declaringClass = argslist[0] == null ? null : argslist[0].declaringClass; // If the declaring class is a pure Java type but we're instantiating a Python proxy, // grab the proxy version of the constructor to instantiate the proper type Deleted: trunk/jython/tests/java/javatests/MethodInvokationTest.java =================================================================== --- trunk/jython/tests/java/javatests/MethodInvokationTest.java 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/tests/java/javatests/MethodInvokationTest.java 2009-01-04 22:15:09 UTC (rev 5842) @@ -1,19 +0,0 @@ -package javatests; - -public class MethodInvokationTest{ - public static String foo1(int i) { - return "foo1 with int arg: " + i; - } - - public static String foo1(char c) { - return "foo1 with char arg: " + c; - } - - public static String foo1(boolean b) { - return "foo1 with boolean arg: " + b; - } - - public static String foo1(byte bt) { - return "foo1 with byte arg: " + bt; - } -} Modified: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-04 20:36:10 UTC (rev 5841) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-04 22:15:09 UTC (rev 5842) @@ -67,4 +67,20 @@ public String tellClassNameSerializable(Serializable o) { return o.getClass().toString(); } + + public static String take(int i) { + return "take with int arg: " + i; + } + + public static String take(char c) { + return "take with char arg: " + c; + } + + public static String take(boolean b) { + return "take with boolean arg: " + b; + } + + public static String take(byte bt) { + return "take with byte arg: " + bt; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |