From: <fwi...@us...> - 2009-01-14 03:59:03
|
Revision: 5928 http://jython.svn.sourceforge.net/jython/?rev=5928&view=rev Author: fwierzbicki Date: 2009-01-14 03:58:51 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Merged revisions 5900-5901,5903-5906,5908,5912-5918,5920,5923,5925,5927 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5900 | fwierzbicki | 2009-01-09 10:16:08 -0500 (Fri, 09 Jan 2009) | 2 lines Fix for wrong error line number when file ends with open paren. ........ r5901 | otmarhumbel | 2009-01-09 12:31:07 -0500 (Fri, 09 Jan 2009) | 1 line reduce the size of the installer .jar by excluding external libraries we do not want to distribute ........ r5903 | fwierzbicki | 2009-01-09 15:40:11 -0500 (Fri, 09 Jan 2009) | 2 lines Change release numbers in build. ........ r5904 | fwierzbicki | 2009-01-09 15:43:55 -0500 (Fri, 09 Jan 2009) | 2 lines locked CPython to revision 68460. ........ r5905 | fwierzbicki | 2009-01-09 15:53:52 -0500 (Fri, 09 Jan 2009) | 2 lines Update README ........ r5906 | pjenvey | 2009-01-09 19:49:02 -0500 (Fri, 09 Jan 2009) | 2 lines fix broken import ........ r5908 | pedronis | 2009-01-10 07:39:15 -0500 (Sat, 10 Jan 2009) | 5 lines yet another try at binop rule, with more exhaustive tests (verified against cpython) that now pass see also PyPy issue 412 ........ r5912 | cgroves | 2009-01-10 19:53:55 -0500 (Sat, 10 Jan 2009) | 6 lines * Add xerces' version number to its file name for future explorers. * Add a skip-brand property to build.xml that allows version branding to be skipped, which keeps jython-dev.jar from being built even if no other files change and shaves a couple seconds off a dev build. ........ r5913 | cgroves | 2009-01-10 20:03:33 -0500 (Sat, 10 Jan 2009) | 1 line Compile Syspath.java for 1.5 instead of 1.6 ........ r5914 | cgroves | 2009-01-10 20:12:16 -0500 (Sat, 10 Jan 2009) | 5 lines Creating the empty.py file after the bytecode just meant that it had a more recent modtime and would be preferred for importing, so it wasn't testing anything. ........ r5915 | cgroves | 2009-01-10 22:21:25 -0500 (Sat, 10 Jan 2009) | 1 line Cleanup ........ r5916 | cgroves | 2009-01-11 01:04:11 -0500 (Sun, 11 Jan 2009) | 6 lines Convert to PyObject going into and Object coming out of java.util.Set methods on PySet like PyDictionary does for Map methods and PyList does for List methods. Without this, Java code can add non-PyObjects to the underlying set causing the Python access to it to throw ClassCastExceptions. ........ r5917 | cgroves | 2009-01-11 01:24:45 -0500 (Sun, 11 Jan 2009) | 3 lines Huh, I guess ECJ can handle inferring these generics, but javac sure can't. ........ r5918 | cgroves | 2009-01-11 05:35:10 -0500 (Sun, 11 Jan 2009) | 6 lines In String compilation contexts, we can assume the bytes have already been decoded and just pass them through when parsing instead of using ascii. This gets test_doctest back to passing as it was before and keeps the pep 263 checks. ........ r5920 | cgroves | 2009-01-11 17:26:38 -0500 (Sun, 11 Jan 2009) | 6 lines test320 - Moved to test_traceback_jy test366,373 - Moved to test_java_integration test391 - Moved to test_java_visibility test395 - Tested by test_java_visibility test396 - Tested by test_java_subclasses ........ r5923 | pjenvey | 2009-01-11 20:31:59 -0500 (Sun, 11 Jan 2009) | 1 line bump copyright year ........ r5925 | cgroves | 2009-01-13 17:10:24 -0500 (Tue, 13 Jan 2009) | 1 line Allow importation from bytecode in a zip file even if the source isn't present ........ r5927 | fwierzbicki | 2009-01-13 22:42:42 -0500 (Tue, 13 Jan 2009) | 4 lines Small fix to grammar -- a "print" by itself should have it's NL attribute set to true as CPython does. Because "false" doesn't make sense in this context (it would be a no-op), the compiler doesn't check, so it passed unnoticed. ........ Revision Links: -------------- http://jython.svn.sourceforge.net/jython/?rev=68460&view=rev Modified Paths: -------------- branches/jy3k/LICENSE.txt branches/jy3k/Lib/os.py branches/jy3k/Lib/test/syspath_import.jar branches/jy3k/Lib/test/test_descr_jy.py branches/jy3k/Lib/test/test_doctest.py branches/jy3k/Lib/test/test_eof_jy.py branches/jy3k/Lib/test/test_import_jy.py branches/jy3k/Lib/test/test_java_integration.py branches/jy3k/Lib/test/test_java_visibility.py branches/jy3k/Lib/test/test_traceback_jy.py branches/jy3k/README.txt branches/jy3k/build.xml branches/jy3k/src/org/python/antlr/PythonTokenSource.java branches/jy3k/src/org/python/compiler/ProxyMaker.java branches/jy3k/src/org/python/core/BaseSet.java branches/jy3k/src/org/python/core/CompilerFlags.java branches/jy3k/src/org/python/core/ParserFacade.java branches/jy3k/src/org/python/core/PyDictionary.java branches/jy3k/src/org/python/core/PyFrozenSet.java branches/jy3k/src/org/python/core/PyIterator.java branches/jy3k/src/org/python/core/PyLong.java branches/jy3k/src/org/python/core/PyObject.java branches/jy3k/src/org/python/core/PyObjectList.java branches/jy3k/src/org/python/core/PySequenceList.java branches/jy3k/src/org/python/core/PySet.java branches/jy3k/src/org/python/core/PySystemState.java branches/jy3k/src/org/python/core/PyType.java branches/jy3k/src/org/python/modules/zipimport/zipimporter.java branches/jy3k/src/org/python/util/Generic.java branches/jy3k/src/org/python/util/NameUnionAntType.java branches/jy3k/tests/java/javatests/ListTest.java branches/jy3k/tests/java/javatests/TestSupport.java Added Paths: ----------- branches/jy3k/Lib/test/eof_fodder7.py branches/jy3k/Lib/test/except_in_raising_code.py branches/jy3k/Lib/test/test_set_jy.py branches/jy3k/extlibs/xercesImpl-2.9.1.jar branches/jy3k/tests/java/javatests/PySetInJavaTest.java Removed Paths: ------------- branches/jy3k/bugtests/classes/test395j1.java branches/jy3k/bugtests/classes/test395j2.java branches/jy3k/bugtests/classes/test396j.java branches/jy3k/bugtests/test320.py branches/jy3k/bugtests/test366.py branches/jy3k/bugtests/test373.py branches/jy3k/bugtests/test391.py branches/jy3k/bugtests/test395.py branches/jy3k/bugtests/test396.py branches/jy3k/extlibs/xercesImpl.jar branches/jy3k/src/org/python/core/PySetIterator.java Modified: branches/jy3k/LICENSE.txt =================================================================== --- branches/jy3k/LICENSE.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/LICENSE.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -53,7 +53,7 @@ Jython 2.0, 2.1 License ================================ -Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Jython Developers +Copyright (c) 2000-2009 Jython Developers. All rights reserved. Redistribution and use in source and binary forms, with or without Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/os.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -569,7 +569,7 @@ if _time_t is None: from java.lang import Integer, Long try: - from org.python.posix import Platform + from org.python.posix.util import Platform except ImportError: from org.jruby.ext.posix.util import Platform _time_t = Integer if Platform.IS_32_BIT else Long Copied: branches/jy3k/Lib/test/eof_fodder7.py (from rev 5927, trunk/jython/Lib/test/eof_fodder7.py) =================================================================== --- branches/jy3k/Lib/test/eof_fodder7.py (rev 0) +++ branches/jy3k/Lib/test/eof_fodder7.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,5 @@ +def hi(): + pass + +def bye(): + hi( Copied: branches/jy3k/Lib/test/except_in_raising_code.py (from rev 5927, trunk/jython/Lib/test/except_in_raising_code.py) =================================================================== --- branches/jy3k/Lib/test/except_in_raising_code.py (rev 0) +++ branches/jy3k/Lib/test/except_in_raising_code.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,8 @@ +def test(): + print noname + +def foo(): + try: + test() + except ValueError: + raise RuntimeError("Accessing a undefined name should raise a NameError") Modified: branches/jy3k/Lib/test/syspath_import.jar =================================================================== (Binary files differ) Modified: branches/jy3k/Lib/test/test_descr_jy.py =================================================================== --- branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -368,13 +368,148 @@ except AttributeError, e: self.assertEquals("Custom message", str(e)) +# try to test more exhaustively binop overriding combination cases +class Base(object): + def __init__(self, name): + self.name = name + +def lookup_where(obj, name): + mro = type(obj).__mro__ + for t in mro: + if name in t.__dict__: + return t.__dict__[name], t + return None, None + +def refop(x, y, opname, ropname): + # this has been validated by running the tests on top of cpython + # so for the space of possibilities that the tests touch it is known + # to behave like cpython as long as the latter doesn't change its own + # algorithm + t1 = type(x) + t2 = type(y) + op, where1 = lookup_where(x, opname) + rop, where2 = lookup_where(y, ropname) + if op is None and rop is not None: + return rop(y, x) + if rop and where1 is not where2: + if (issubclass(t2, t1) and not issubclass(where1, where2) + and not issubclass(t1, where2) + ): + return rop(y, x) + if op is None: + return "TypeError" + return op(x,y) + +def do_test(X, Y, name, impl): + x = X('x') + y = Y('y') + opname = '__%s__' % name + ropname = '__r%s__' % name + + count = [0] + fail = [] + + def check(z1, z2): + ref = refop(z1, z2, opname, ropname) + try: + v = impl(z1, z2) + except TypeError: + v = "TypeError" + if v != ref: + fail.append(count[0]) + + def override_in_hier(n=6): + if n == 0: + count[0] += 1 + check(x, y) + check(y, x) + return + + f = lambda self, other: (n, self.name, other.name) + if n%2 == 0: + name = opname + else: + name = ropname + + for C in Y.__mro__: + if name in C.__dict__: + continue + if C is not object: + setattr(C, name, f) + override_in_hier(n-1) + if C is not object: + delattr(C, name) + + override_in_hier() + #print count[0] + return fail + +class BinopCombinationsTestCase(unittest.TestCase): + + def test_binop_combinations_mul(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'mul', lambda x,y: x*y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_sub(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_pow(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'pow', lambda x,y: x**y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_more_exhaustive(self): + class X(Base): + pass + + class B1(object): + pass + + class B2(object): + pass + + class X1(B1, X, B2): + pass + + class C1(object): + pass + + class C2(object): + pass + + class Y(C1, X1, C2): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, InPlaceTestCase, DescrExceptionsTestCase, - GetAttrTestCase) + GetAttrTestCase, + BinopCombinationsTestCase) if __name__ == '__main__': test_main() Modified: branches/jy3k/Lib/test/test_doctest.py =================================================================== --- branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -2265,18 +2265,17 @@ File "...", line 7, in test_doctest4.txt Failed example: u'...' - ... + Expected: + u'f\xf6\xf6' + Got: + u'f\xc3\xb6\xc3\xb6' ********************************************************************** ... ********************************************************************** - ... - ********************************************************************** - ... - ********************************************************************** 1 items had failures: - 4 of 4 in test_doctest4.txt - ***Test Failed*** 4 failures. - (4, 4) + 2 of 4 in test_doctest4.txt + ***Test Failed*** 2 failures. + (2, 4) >>> doctest.master = None # Reset master. >>> doctest.testfile('test_doctest4.txt', encoding='utf-8') Modified: branches/jy3k/Lib/test/test_eof_jy.py =================================================================== --- branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -45,6 +45,12 @@ except ImportError, cause: self.fail(cause) + def test_trailing_paren(self): + try: + import eof_fodder7 + except SyntaxError, cause: + self.assertEquals(cause.lineno, 5) + #============================================================================== def test_main(verbose=None): Modified: branches/jy3k/Lib/test/test_import_jy.py =================================================================== --- branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -89,13 +89,11 @@ # Again ensure we didn't recompile self.assertEquals(bytecode, read(init_compiled), 'bytecode was recompiled') + def test_corrupt_bytecode(self): f = open("empty$py.class", "w") f.close() self.assertRaises(ImportError, __import__, "empty") - f = open("empty.py", "w") - f.close() - self.assertRaises(ImportError, __import__, "empty") class OverrideBuiltinsImportTestCase(unittest.TestCase): def test_override(self): Modified: branches/jy3k/Lib/test/test_java_integration.py =================================================================== --- branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -7,7 +7,7 @@ from test import test_support from java.lang import (ExceptionInInitializerError, String, Runnable, System, Runtime, Math, Byte) -from java.math import BigDecimal +from java.math import BigDecimal, BigInteger from java.io import (FileInputStream, FileNotFoundException, FileOutputStream, FileWriter, OutputStreamWriter, UnsupportedEncodingException) from java.util import ArrayList, Date, HashMap, Hashtable, StringTokenizer, Vector @@ -56,6 +56,11 @@ b = BeanImplementation() self.assertEquals("name", b.getName()) self.assertEquals("name", b.name) + # Tests for #610576 + class SubBean(BeanImplementation): + def __init__(bself): + self.assertEquals("name", bself.getName()) + SubBean() class SysIntegrationTest(unittest.TestCase): @@ -262,7 +267,7 @@ 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 BigDecimalTest(unittest.TestCase): +class BigNumberTest(unittest.TestCase): def test_coerced_bigdecimal(self): from javatests import BigDecimalTest x = BigDecimal("123.4321") @@ -271,6 +276,11 @@ self.assertEqual(type(x), type(y), "BigDecimal coerced") self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") + def test_biginteger_in_long(self): + '''Checks for #608628, that long can take a BigInteger in its constructor''' + ns = '10000000000' + self.assertEquals(ns, str(long(BigInteger(ns)))) + class JavaStringTest(unittest.TestCase): def test_string_not_iterable(self): x = String('test') @@ -338,7 +348,7 @@ ImportTest, ColorTest, TreePathTest, - BigDecimalTest, + BigNumberTest, JavaStringTest, JavaDelegationTest, SecurityManagerTest) Modified: branches/jy3k/Lib/test/test_java_visibility.py =================================================================== --- branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,7 +4,7 @@ import sys from test import test_support from java.lang import Byte, Class -from java.util import HashMap, Observable, Observer +from java.util import ArrayList, Collections, HashMap, Observable, Observer from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, Matryoshka, OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results @@ -142,6 +142,14 @@ """Bug #452947 - Class of innerclass inst <> innerclass""" self.assertEquals(id(Matryoshka.Outermost), id(Matryoshka.makeOutermost().__class__)) + def test_super_methods_merged(self): + '''Checks that all signatures on a class' methods are found, not just the first for a name + + Bug #628315''' + synchList = Collections.synchronizedList(ArrayList()) + synchList.add("a string") + self.assertEquals("a string", synchList.remove(0)) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), Copied: branches/jy3k/Lib/test/test_set_jy.py (from rev 5927, trunk/jython/Lib/test/test_set_jy.py) =================================================================== --- branches/jy3k/Lib/test/test_set_jy.py (rev 0) +++ branches/jy3k/Lib/test/test_set_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,35 @@ +from test import test_support +import unittest + +from java.util import Random +from javatests import PySetInJavaTest + +class SetInJavaTest(unittest.TestCase): + "Tests for derived dict behaviour" + def test_using_PySet_as_Java_Set(self): + PySetInJavaTest.testPySetAsJavaSet() + + def test_accessing_items_added_in_java(self): + s = PySetInJavaTest.createPySetContainingJavaObjects() + for v in s: + self.assert_(v in s) + if isinstance(v, unicode): + self.assertEquals("value", v) + else: + v.nextInt()#Should be a java.util.Random; ensure we can call it + + def test_java_accessing_items_added_in_python(self): + # Test a type that should be coerced into a Java type, a Java instance + # that should be wrapped, and a Python instance that should pass + # through as itself with str, Random and tuple respectively. + s = set(["value", Random(), ("tuple", "of", "stuff")]) + PySetInJavaTest.accessAndRemovePySetItems(s) + self.assertEquals(0, len(s))# Check that the Java removal affected the underlying set + + + +def test_main(): + test_support.run_unittest(SetInJavaTest) + +if __name__ == '__main__': + test_main() Modified: branches/jy3k/Lib/test/test_traceback_jy.py =================================================================== --- branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -50,8 +50,17 @@ # http://bugs.jython.org/issue437809 traceback.extract_stack() + def test_except_around_raising_call(self): + """[ #452526 ] traceback lineno is the except line""" + from test import except_in_raising_code + try: + except_in_raising_code.foo() + except NameError: + tb = sys.exc_info()[2] + self.assertEquals(6, tb.tb_next.tb_lineno) + else: + self.fail("Should've raised a NameError") - try: raise Exception('foo') except Exception: Modified: branches/jy3k/README.txt =================================================================== --- branches/jy3k/README.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/README.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,7 +1,7 @@ -Welcome to Jython 2.5b0 +Welcome to Jython 2.5b1 ======================= -This is the first beta of the 2.5 version of Jython. It +This is the second beta of the 2.5 version of Jython. It contains most of the new features for the 2.5 release. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Deleted: branches/jy3k/bugtests/classes/test395j1.java =================================================================== --- branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,4 +0,0 @@ -public class test395j1 { - protected test395j1() { - } -} Deleted: branches/jy3k/bugtests/classes/test395j2.java =================================================================== --- branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,5 +0,0 @@ -public class test395j2 extends test395j1 { - private test395j2() { - super(); - } -} Deleted: branches/jy3k/bugtests/classes/test396j.java =================================================================== --- branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,8 +0,0 @@ -public abstract class test396j { - public test396j() { - abstractMethod(); - } - - public abstract void abstractMethod(); - -} Deleted: branches/jy3k/bugtests/test320.py =================================================================== --- branches/jy3k/bugtests/test320.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test320.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,28 +0,0 @@ -""" -[ #452526 ] traceback lineno is the except line -""" - -import support -import sys, traceback - -def test(): - print noname - -def foo(): - try: - - - test() - - - except ValueError: - print "shouldn't happen." - -try: - foo() -except: - tb = sys.exc_info()[2] - #print tb.tb_lineno - #traceback.print_tb(tb) - assert tb.tb_next.tb_lineno == 15 - Deleted: branches/jy3k/bugtests/test366.py =================================================================== --- branches/jy3k/bugtests/test366.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test366.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,17 +0,0 @@ -""" -[ 610576 ] Impl of abstract method not found -""" - -import support - -support.compileJava("test366i.java"); -support.compileJava("test366j.java"); - -import test366i, test366j - -class MyCls(test366j, test366i): - def __init__(self): - self.foo(); - -MyCls() - Deleted: branches/jy3k/bugtests/test373.py =================================================================== --- branches/jy3k/bugtests/test373.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test373.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -""" -Test for bug [608628] long(java.math.BigInteger) does not work. -""" - -import support - -# local name bugtests/test381.py -ns = '10000000000' -import java -ns2 = str(long(java.math.BigInteger(ns))) -assert ns == ns2, ns2 - - - Deleted: branches/jy3k/bugtests/test391.py =================================================================== --- branches/jy3k/bugtests/test391.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test391.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -''' -Checks that all methods on a class are found, not just the first interface that has a method of the same name. - -Reported in bug 628315. -''' -import support -import java - -synchList = java.util.Collections.synchronizedList(java.util.ArrayList()) -synchList.add("a string") - -if not synchList.remove(0) == 'a string': - raise support.TestError, "'a string' should've been returned by the call to remove. The object version of remove was probably called instead of the int version" - Deleted: branches/jy3k/bugtests/test395.py =================================================================== --- branches/jy3k/bugtests/test395.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test395.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,20 +0,0 @@ -""" -Classes with greater a protected constructor can be subclassed and instantiated -Tests bug #649582 -""" - -import support - -support.compileJava("classes/test395j1.java") -support.compileJava("classes/test395j2.java") - -import test395j2 - -class Subclass(test395j2): - def __init__(self): - test395j2.__init__(self) - -try: - Subclass() -except AttributeError: - raise support.TestWarning('Unable to access protected superclass constructor') Deleted: branches/jy3k/bugtests/test396.py =================================================================== --- branches/jy3k/bugtests/test396.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test396.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,19 +0,0 @@ -''' -Checks for bug 663592. Used to be that if an abstract Java class called an -abstract method implemented by a Python subclass in its constructor, an -AttributeError would be thrown. -''' -import support - -support.compileJava("classes/test396j.java") - -import test396j - -class Subclass(test396j): - def __init__(self): - test396j.__init__(self) - - def abstractMethod(self): - pass - -x = Subclass() Modified: branches/jy3k/build.xml =================================================================== --- branches/jy3k/build.xml 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/build.xml 2009-01-14 03:58:51 UTC (rev 5928) @@ -362,7 +362,9 @@ <exec executable="svnversion" failifexecutionfails="false" outputproperty="build.svn.revision"/> </target> - <target name="brand-version" depends="version-init, svnversion"> + <!-- skip-brand can be set in ant.properties or as a system property to keep from updating the + version.properties file and making the jar on every developer build. --> + <target name="brand-version" depends="version-init, svnversion" unless="skip-brand"> <condition property="build.svn.revision" value=""> <not> <isset property="build.svn.revision"/> @@ -520,7 +522,7 @@ <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine-0.4.jar"/> <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> - <zipfileset src="extlibs/xercesImpl.jar"/> + <zipfileset src="extlibs/xercesImpl-2.9.1.jar"/> <rule pattern="org.apache.**" result="org.python.apache.@1"/> <manifest> <attribute name="Main-Class" value="org.python.util.jython" /> @@ -720,6 +722,15 @@ <fileset dir="${dist.dir}"> <exclude name="${jython.dev.jar}"/> <exclude name="callbacker_test.jar"/> + <exclude name="extlibs/svnant-jars/**" /> + <exclude name="extlibs/antlr*.jar" /> + <exclude name="extlibs/asm*.jar" /> + <exclude name="extlibs/constantine*.jar" /> + <exclude name="extlibs/jarjar*.jar" /> + <exclude name="extlibs/junit*.jar" /> + <exclude name="extlibs/servlet-api*.jar" /> + <exclude name="extlibs/stringtemplate*.jar" /> + <exclude name="extlibs/xerces*.jar" /> </fileset> <manifest> <attribute name="Main-Class" value="org.python.util.install.Installation" /> Copied: branches/jy3k/extlibs/xercesImpl-2.9.1.jar (from rev 5927, trunk/jython/extlibs/xercesImpl-2.9.1.jar) =================================================================== (Binary files differ) Deleted: branches/jy3k/extlibs/xercesImpl.jar =================================================================== (Binary files differ) Modified: branches/jy3k/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -146,6 +146,7 @@ } private void generateNewline(Token t) { + //System.out.println("generating newline from token: " + t); CommonToken newline = new CommonToken(PythonLexer.NEWLINE, "\n"); newline.setLine(t.getLine()); newline.setCharPositionInLine(t.getCharPositionInLine()); @@ -153,9 +154,12 @@ } private void handleEOF(CommonToken eof, CommonToken prev) { + //System.out.println("processing eof with token: " + prev); if (prev != null) { eof.setStartIndex(prev.getStopIndex()); eof.setStopIndex(prev.getStopIndex()); + eof.setLine(prev.getLine()); + eof.setCharPositionInLine(prev.getCharPositionInLine()); } } Modified: branches/jy3k/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -703,9 +703,7 @@ addMethods(superclass, seenmethods); for (Class<?> iface : interfaces) { if (iface.isAssignableFrom(superclass)) { - Py.writeWarning("compiler", - "discarding redundant interface: "+ - iface.getName()); + Py.writeWarning("compiler", "discarding redundant interface: " + iface.getName()); continue; } classfile.addInterface(mapClass(iface)); Modified: branches/jy3k/src/org/python/core/BaseSet.java =================================================================== --- branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,41 +1,35 @@ package org.python.core; +import java.lang.reflect.Array; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.Set; public abstract class BaseSet extends PyObject implements Set { /** The underlying Set. */ - protected Set _set; + protected Set<PyObject> _set; /** * Create a new Python set instance from the specified Set object. - * - * @param set An Set object. */ - protected BaseSet(Set set) { + protected BaseSet(Set<PyObject> set) { _set = set; } - protected BaseSet(PyType type, Set set) { + protected BaseSet(PyType type, Set<PyObject> set) { super(type); _set = set; } - protected void _update(PyObject data) throws PyIgnoreMethodTag { + protected void _update(PyObject data) { _update(_set, data); } /** * Update the underlying set with the contents of the iterable. - * - * @param data An iterable instance. - * @throws PyIgnoreMethodTag Ignore. */ - protected static Set _update(Set set, PyObject data) throws PyIgnoreMethodTag { + protected static Set<PyObject> _update(Set<PyObject> set, PyObject data) { if (data == null) { return set; } @@ -53,7 +47,7 @@ /** * The union of <code>this</code> with <code>other</code>. <p/> <br/> (I.e. all elements * that are in either set) - * + * * @param other * A <code>BaseSet</code> instance. * @return The union of the two sets as a new set. @@ -115,9 +109,9 @@ final PyObject baseset_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); - Set set = bs._set; + Set<PyObject> set = bs._set; BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!set.contains(p)) { o._set.add(p); } @@ -153,12 +147,12 @@ final PyObject baseset_symmetric_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!bs._set.contains(p)) { o._set.add(p); } } - for (Object p : bs._set) { + for (PyObject p : bs._set) { if (!_set.contains(p)) { o._set.add(p); } @@ -206,7 +200,22 @@ } final PyObject baseset___iter__() { - return new PySetIterator(_set); + return new PyIterator() { + private int size = _set.size(); + + private Iterator<PyObject> iterator = _set.iterator(); + + @Override + public PyObject __iternext__() { + if (_set.size() != size) { + throw Py.RuntimeError("set changed size during iteration"); + } + if (iterator.hasNext()) { + return iterator.next(); + } + return null; + } + }; } public boolean __contains__(PyObject other) { @@ -257,7 +266,7 @@ } final PyObject baseset___le__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issubset(other); } @@ -266,7 +275,7 @@ } final PyObject baseset___ge__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issuperset(other); } @@ -299,7 +308,7 @@ public PyObject __reduce__() { return baseset___reduce__(); } - + final PyObject baseset___reduce__(){ PyObject args = new PyTuple(new PyList((PyObject)this)); PyObject dict = __findattr__("__dict__"); @@ -309,19 +318,6 @@ return new PyTuple(getType(), args, dict); } - /** - * Return this instance as a Java object. Only coerces to Collection and subinterfaces. - * - * @param c The Class to coerce to. - * @return the underlying HashSet (not a copy) - */ - public Object __tojava__(Class c) { - if (Collection.class.isAssignableFrom(c)) { - return Collections.unmodifiableSet(_set); - } - return super.__tojava__(c); - } - final PyObject baseset_union(PyObject other) { BaseSet result = BaseSet.makeNewSet(getType(), this); result._update(other); @@ -388,8 +384,8 @@ return name + "(...)"; } StringBuilder buf = new StringBuilder(name).append("(["); - for (Iterator i = _set.iterator(); i.hasNext();) { - buf.append(((PyObject)i.next()).__repr__().toString()); + for (Iterator<PyObject> i = _set.iterator(); i.hasNext();) { + buf.append((i.next()).__repr__().toString()); if (i.hasNext()) { buf.append(", "); } @@ -408,20 +404,20 @@ } /** - * Return a PyFrozenSet whose contents are shared with value when - * value is a BaseSet and pye is a TypeError. + * Return a PyFrozenSet whose contents are shared with value when value is a BaseSet and pye is + * a TypeError. * - * WARNING: The PyFrozenSet returned is only intended to be used - * temporarily (and internally); since its contents are shared - * with value, it could be mutated! - * - * This is better than special-casing behavior based on - * isinstance, because a Python subclass can override, say, - * __hash__ and all of a sudden you can't assume that a - * non-PyFrozenSet is unhashable anymore. + * WARNING: The PyFrozenSet returned is only intended to be used temporarily (and internally); + * since its contents are shared with value, it could be mutated! * - * @param pye The exception thrown from a hashable operation. - * @param value The object which was unhashable. + * This is better than special-casing behavior based on isinstance, because a Python subclass + * can override, say, __hash__ and all of a sudden you can't assume that a non-PyFrozenSet is + * unhashable anymore. + * + * @param pye + * The exception thrown from a hashable operation. + * @param value + * The object which was unhashable. * @return A PyFrozenSet if appropriate, otherwise the pye is rethrown */ protected final PyFrozenSet asFrozen(PyException pye, PyObject value) { @@ -442,7 +438,7 @@ protected static BaseSet makeNewSet(PyType type) { return makeNewSet(type, null); } - + /** * Create a new <et of type from iterable. * @@ -477,43 +473,89 @@ return _set.isEmpty(); } - public Object[] toArray() { - return _set.toArray(); - } - public boolean add(Object o) { - return _set.add(o); + return _set.add(Py.java2py(o)); } public boolean contains(Object o) { - return _set.contains(o); + return _set.contains(Py.java2py(o)); } public boolean remove(Object o) { - return _set.remove(o); + return _set.remove(Py.java2py(o)); } public boolean addAll(Collection c) { - return _set.addAll(c); + boolean added = false; + for (Object object : c) { + added |= add(object); + } + return added; } public boolean containsAll(Collection c) { - return _set.containsAll(c); + for (Object object : c) { + if (!_set.contains(Py.java2py(object))) { + return false; + } + } + return true; } public boolean removeAll(Collection c) { - return _set.removeAll(c); + boolean removed = false; + for (Object object : c) { + removed |= _set.remove(Py.java2py(object)); + } + return removed; } public boolean retainAll(Collection c) { - return _set.retainAll(c); + boolean modified = false; + Iterator e = iterator(); + while (e.hasNext()) { + if (!c.contains(e.next())) { + e.remove(); + modified = true; + } + } + return modified; } public Iterator iterator() { - return _set.iterator(); + return new Iterator() { + Iterator<PyObject> real = _set.iterator(); + + public boolean hasNext() { + return real.hasNext(); + } + + public Object next() { + return Py.tojava(real.next(), Object.class); + } + + public void remove() { + real.remove(); + } + }; } + public Object[] toArray() { + return toArray(new Object[size()]); + } + public Object[] toArray(Object a[]) { - return _set.toArray(a); + int size = size(); + if (a.length < size) { + a = (Object[])Array.newInstance(a.getClass().getComponentType(), size); + } + Iterator<PyObject> it = iterator(); + for (int i = 0; i < size; i++) { + a[i] = it.next(); + } + if (a.length > size) { + a[size] = null; + } + return a; } } Modified: branches/jy3k/src/org/python/core/CompilerFlags.java =================================================================== --- branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -3,54 +3,44 @@ public class CompilerFlags { + private int co_flags; + public boolean nested_scopes = true; public boolean division; public boolean generator_allowed = true; - public boolean with_statement = false; - public boolean absolute_import = false; + public boolean with_statement; + public boolean absolute_import; - public boolean only_ast = false; - public boolean dont_imply_dedent = false; - public boolean source_is_utf8 = false; + public boolean only_ast; + public boolean dont_imply_dedent; + public boolean source_is_utf8; public String encoding; - - public CompilerFlags(){} + public CompilerFlags() {} + public CompilerFlags(int co_flags) { - if ((co_flags & org.python.core.PyTableCode.CO_NESTED) != 0) { - this.nested_scopes = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTUREDIVISION) != 0) { - this.division = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_GENERATOR_ALLOWED) != 0) { - this.generator_allowed = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT) != 0) { - this.absolute_import = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_WITH_STATEMENT) != 0) { - this.with_statement = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_ONLY_AST) != 0) { - this.only_ast = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_DONT_IMPLY_DEDENT) != 0) { - this.dont_imply_dedent = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_SOURCE_IS_UTF8) != 0) { - this.source_is_utf8 = true; - } - + this.co_flags = co_flags; + nested_scopes = isEnabled(PyTableCode.CO_NESTED); + division = isEnabled(PyTableCode.CO_FUTUREDIVISION); + generator_allowed = isEnabled(PyTableCode.CO_GENERATOR_ALLOWED); + absolute_import = isEnabled(PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT); + with_statement = isEnabled(PyTableCode.CO_WITH_STATEMENT); + only_ast = isEnabled(PyTableCode.PyCF_ONLY_AST); + dont_imply_dedent = isEnabled(PyTableCode.PyCF_DONT_IMPLY_DEDENT); + source_is_utf8 = isEnabled(PyTableCode.PyCF_SOURCE_IS_UTF8); } + private boolean isEnabled(int codeConstant) { + return (co_flags & codeConstant) != 0; + } + public String toString() { return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " + "with_statement=%s absolute_import=%s only_ast=%s " + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, - generator_allowed, with_statement, absolute_import, only_ast, + generator_allowed, with_statement, absolute_import, only_ast, dont_imply_dedent, source_is_utf8); } - + } Modified: branches/jy3k/src/org/python/core/ParserFacade.java =================================================================== --- branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,10 +4,13 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.Writer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; @@ -138,7 +141,7 @@ try { // prepBufReader takes care of encoding detection and universal // newlines: - bufReader = prepBufReader(stream, cflags, filename); + bufReader = prepBufReader(stream, cflags, filename, false); return parse(bufReader, kind, filename, cflags ); } catch (Throwable t) { throw fixParseError(bufReader, t, filename); @@ -223,7 +226,9 @@ private static ExpectedEncodingBufferedReader prepBufReader(InputStream input, CompilerFlags cflags, - String filename) throws IOException { + String filename, + boolean fromString) + throws IOException { input = new BufferedInputStream(input); boolean bom = adjustForBOM(input); String encoding = readEncoding(input); @@ -250,29 +255,45 @@ UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); input = new TextIOInputStream(textIO); - CharsetDecoder dec; + Charset cs; try { // Use ascii for the raw bytes when no encoding was specified - dec = Charset.forName(encoding == null ? "ascii" : encoding).newDecoder(); + if (encoding == null) { + if (fromString) { + cs = Charset.forName("ISO-8859-1"); + } else { + cs = Charset.forName("ascii"); + } + } else { + cs = Charset.forName(encoding); + } } catch (UnsupportedCharsetException exc) { throw new PySyntaxError("Unknown encoding: " + encoding, 1, 0, "", filename); } + CharsetDecoder dec = cs.newDecoder(); dec.onMalformedInput(CodingErrorAction.REPORT); dec.onUnmappableCharacter(CodingErrorAction.REPORT); return new ExpectedEncodingBufferedReader(new InputStreamReader(input, dec), encoding); } - private static ExpectedEncodingBufferedReader prepBufReader(String string, CompilerFlags cflags, - String filename) throws IOException { + private static ExpectedEncodingBufferedReader prepBufReader(String string, + CompilerFlags cflags, + String filename) throws IOException { + byte[] stringBytes; if (cflags.source_is_utf8) { // Passed unicode, re-encode the String to raw bytes // NOTE: This could be more efficient if we duplicate // prepBufReader/adjustForBOM/readEncoding to work on Readers, instead of // encoding - string = new PyUnicode(string).encode("utf-8"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Writer w = new OutputStreamWriter(out, "utf-8"); + w.write(string); + w.close(); + stringBytes = out.toByteArray(); + } else { + stringBytes = StringUtil.toBytes(string); } - InputStream input = new ByteArrayInputStream(StringUtil.toBytes(string)); - return prepBufReader(input, cflags, filename); + return prepBufReader(new ByteArrayInputStream(stringBytes), cflags, filename, true); } /** Modified: branches/jy3k/src/org/python/core/PyDictionary.java =================================================================== --- branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -12,7 +12,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.python.core.PyMapSet.PySetIter; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -27,7 +26,7 @@ public class PyDictionary extends PyObject implements ConcurrentMap { public static final PyType TYPE = PyType.fromClass(PyDictionary.class); - + protected final ConcurrentMap<PyObject, PyObject> table; /** @@ -39,7 +38,6 @@ /** * For derived types - * @param subtype */ public PyDictionary(PyType subtype) { super(subtype); @@ -47,31 +45,27 @@ } /** - * Create an new dictionary which is based on the hashtable. - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + * Create a new dictionary which is based on given map. */ public PyDictionary(Map<PyObject, PyObject> t) { table = new ConcurrentHashMap<PyObject, PyObject>(t); } - /** - * Create an new dictionary which is based on the map and for derived types. - * @param subtype - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + /** + * Create a new derived dictionary which is based on the given map. */ public PyDictionary(PyType subtype, Map<PyObject, PyObject> t) { super(subtype); table = new ConcurrentHashMap<PyObject, PyObject>(t); } - + /** * Create a new dictionary with the element as content. - * @param elements The initial elements that is inserted in the - * dictionary. Even numbered elements are keys, - * odd numbered elements are values. + * + * @param elements + * The initial elements that is inserted in the dictionary. Even numbered elements + * are keys, odd numbered elements are values. */ public PyDictionary(PyObject elements[]) { this(); @@ -85,7 +79,7 @@ protected final void dict___init__(PyObject[] args, String[] keywords) { updateCommon(args, keywords, "dict"); } - + public static PyObject fromkeys(PyObject keys) { return fromkeys(keys, Py.None); } @@ -210,10 +204,10 @@ } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) - final PyObject dict___eq__(PyObject ob_other) { + final PyObject dict___eq__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return null; } @@ -291,7 +285,7 @@ final int dict___cmp__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return -2; } @@ -435,7 +429,7 @@ } for (int i = 0; i < keywords.length; i++) { dict___setitem__(Py.newString(keywords[i]), args[nargs + i]); - } + } } /** @@ -539,7 +533,7 @@ } } - + /** * Return a value based on key * from the dictionary. @@ -578,18 +572,17 @@ @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { - Iterator it = table.entrySet().iterator(); + Iterator<Entry<PyObject, PyObject>> it = table.entrySet().iterator(); if (!it.hasNext()) throw Py.KeyError("popitem(): dictionary is empty"); - Entry entry = (Entry)it.next(); - PyTuple tuple = new PyTuple( - (PyObject)entry.getKey(), (PyObject)entry.getValue()); + Entry<PyObject, PyObject> entry = it.next(); + PyTuple tuple = new PyTuple(entry.getKey(), entry.getValue()); it.remove(); return tuple; } /** - * Return a copy of the dictionarys list of (key, value) tuple + * Return a copy of the dictionary's list of (key, value) tuple * pairs. */ public PyList items() { @@ -606,7 +599,7 @@ } /** - * Return a copy of the dictionarys list of keys. + * Return a copy of the dictionary's list of keys. */ public PyList keys() { return dict_keys(); @@ -623,7 +616,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over (key, value) pairs. */ public PyObject iteritems() { return dict_iteritems(); @@ -635,7 +628,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's keys. */ public PyObject iterkeys() { return dict_iterkeys(); @@ -647,7 +640,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's values. */ public PyObject itervalues() { return dict_itervalues(); @@ -703,7 +696,7 @@ iterator = items.iterator(); size = items.size(); } - + public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -716,13 +709,12 @@ } } - /* The following methods implement the java.util.Map interface - which allows PyDictionary to be passed to java methods that take - java.util.Map as a parameter. Basically, the Map methods are a - wrapper around the PyDictionary's Map container stored in member - variable 'table'. These methods simply convert java Object to - PyObjects on insertion, and PyObject to Objects on retrieval. */ - + /* + * The following methods implement the java.util.Map interface which allows PyDictionary to be + * passed to java methods that take java.util.Map as a parameter. Basically, the Map methods are + * a wrapper around the PyDictionary's Map container stored in member variable 'table'. These + * methods convert java Object to PyObjects on insertion, and PyObject to Objects on retrieval. + */ /** @see java.util.Map#entrySet() */ public Set entrySet() { return new PyMapEntrySet(table.entrySet()); @@ -733,17 +725,15 @@ return new PyMapKeyValSet(table.keySet()); } - /** Return a copy of the dictionarys list of values. */ + /** @see java.util.Map#values() */ public Collection values() { return new PyMapKeyValSet(table.values()); } - /** @see java.util.Map#putAll(Map map) */ public void putAll(Map map) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Entry entry = (Entry)i.next(); + for (Object o : map.entrySet()) { + Entry entry = (Entry)o; table.put(Py.java2py(entry.getKey()), Py.java2py(entry.getValue())); } } @@ -772,19 +762,19 @@ public boolean containsKey(Object key) { return table.containsKey(Py.java2py(key)); } - - /** @see java.util.Map#isEmpty(Object key) */ + + /** @see java.util.Map#isEmpty() */ public boolean isEmpty() { return table.isEmpty(); } - - /** @see java.util.Map#size(Object key) */ + + /** @see java.util.Map#size() */ public int size() { return table.size(); } /** Convert return values to java objects */ - static final Object tojava(Object val) { + final static Object tojava(Object val) { return val == null ? null : ((PyObject)val).__tojava__(Object.class); } @@ -805,19 +795,20 @@ } } + /** Basic implementation of Entry that just holds onto a key and value and returns them. */ -class SimpleEntry<K, V> implements Entry<K, V> { - - public SimpleEntry(K key, V value){ +class SimpleEntry implements Entry { + + public SimpleEntry(Object key, Object value){ this.key = key; this.value = value; } - - public K getKey() { + + public Object getKey() { return key; } - public V getValue() { + public Object getValue() { return value; } @@ -841,31 +832,29 @@ return key + "=" + value; } - public V setValue(V val) { + public Object setValue(Object val) { throw new UnsupportedOperationException("Not supported by this view"); } - protected K key; + protected Object key; - protected V value; + protected Object value; } /** - * Wrapper for a Entry object returned from the java.util.Set - * object which in turn is returned by the entrySet method of - * java.util.Map. This is needed to correctly convert from PyObjects - * to java Objects. Note that we take care in the equals and hashCode - * methods to make sure these methods are consistent with Entry - * objects that contain java Objects for a value so that on the java - * side they can be reliable compared. + * Wrapper for a Entry object returned from the java.util.Set object which in turn is returned by + * the entrySet method of java.util.Map. This is needed to correctly convert from PyObjects to java + * Objects. Note that we take care in the equals and hashCode methods to make sure these methods are + * consistent with Entry objects that contain java Objects for a value so that on the java side they + * can be reliable compared. */ class PyToJavaMapEntry extends SimpleEntry { - /** Create a copy of the Entry with Py.None coverted to null */ + /** Create a copy of the Entry with Py.None converted to null */ PyToJavaMapEntry(Entry entry) { super(entry.getKey(), entry.getValue()); } - + public boolean equals(Object o) { if (o == null || !(o instanceof Entry)) return false; Entry me = new JavaToPyMapEntry((Entry)o); @@ -877,7 +866,7 @@ public Object getKey() { return PyDictionary.tojava(key); } - + public Object getValue() { return PyDictionary.tojava(value); } @@ -892,24 +881,22 @@ } /** - * MapEntry Object for java MapEntry objects passed to the java.util.Set - * interface which is returned by the entrySet method of PyDictionary. - * Essentially like PyTojavaMapEntry, but going t... [truncated message content] |