From: <cg...@us...> - 2008-12-12 03:57:45
|
Revision: 5739 http://jython.svn.sourceforge.net/jython/?rev=5739&view=rev Author: cgroves Date: 2008-12-12 03:57:33 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Merged revisions 5564,5566-5567,5605,5607,5622-5623,5625,5631-5632,5650-5654,5656-5659,5662-5663,5666-5669,5673-5676,5688-5689,5692-5694,5698-5701,5705,5707-5711,5727-5729 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/branches/newstyle-java-types ........ r5564 | cgroves | 2008-11-09 19:31:53 -0800 (Sun, 09 Nov 2008) | 1 line Checkpoint of replacing PyJavaClass with PyJavaType. Works well enough that ProxyMaker creates PyObjects instead of PyJavaInstances and the interpreter starts up, but that's about it ........ r5566 | cgroves | 2008-11-09 19:56:44 -0800 (Sun, 09 Nov 2008) | 1 line Fill in Java inner classes ........ r5567 | cgroves | 2008-11-09 21:15:10 -0800 (Sun, 09 Nov 2008) | 1 line Implement the collection proxies as methods on PyJavaTypes ........ r5605 | cgroves | 2008-11-22 16:46:06 -0800 (Sat, 22 Nov 2008) | 1 line Use PyJavaType to initialize array, not PyJavaClass ........ r5607 | cgroves | 2008-11-22 18:36:05 -0800 (Sat, 22 Nov 2008) | 4 lines Rip out PyJavaClass and friends. This isn't even close to passing regrtest, but it runs well enough to start the interpreter and get through the first few. ........ r5622 | cgroves | 2008-11-23 15:12:46 -0800 (Sun, 23 Nov 2008) | 8 lines PyInstance ignored __tojava__ methods on its classes, so Java classes in the old world with a __tojava__ would be ignored as well. This differed from most other dunder methods, so the new PyJavaType exposes __tojava__ through PyObjectDerived. IOBase was using __tojava__ to mean something different than what PyObject was doing with it, so change the name to keep regular jython object conversion from picking up on it. ........ r5623 | cgroves | 2008-11-23 15:46:11 -0800 (Sun, 23 Nov 2008) | 1 line Create the java proxy object after __init__ runs if it wasn't created by __init__ ........ r5625 | cgroves | 2008-11-23 17:57:05 -0800 (Sun, 23 Nov 2008) | 1 line Don't strip the package out of wrapped Java types ........ r5631 | cgroves | 2008-11-23 21:37:21 -0800 (Sun, 23 Nov 2008) | 1 line Don't hork when exposing fields on an interface as it won't have a base class ........ r5632 | cgroves | 2008-11-23 21:52:36 -0800 (Sun, 23 Nov 2008) | 5 lines Reinstate the code from PyReflectedConstructor that redirectes to the proxy constructor whenever a Python subclass of a Java class attempts to call its Java-superclass constructor. PyJavaType can finally handle it. ........ r5650 | cgroves | 2008-11-28 00:12:30 -0800 (Fri, 28 Nov 2008) | 1 line Check for abstract classes and interfaces before attempting to auto-create a proxy ........ r5651 | cgroves | 2008-11-28 00:56:38 -0800 (Fri, 28 Nov 2008) | 8 lines Add an EQ_PROXY to PyJavaType to pass equals through to wrapped Java instances like PyJavaInstance did. Make PyBuiltinMethod Cloneable and use clone to implement a default bind implementation. This eliminates 75% of the crud that came with creating a builtin method in Java. ........ r5652 | cgroves | 2008-11-28 00:59:49 -0800 (Fri, 28 Nov 2008) | 1 line Whoops, didn't mean to remove Finn's copyright ........ r5653 | cgroves | 2008-11-28 01:13:19 -0800 (Fri, 28 Nov 2008) | 1 line PyObject needs to handle primitive conversion in the new world ........ r5654 | cgroves | 2008-11-28 02:06:54 -0800 (Fri, 28 Nov 2008) | 4 lines Expose static fields through PyBeanProperty if they share a name with the property. Instance fields supercede the propery. ........ r5656 | cgroves | 2008-11-28 13:29:14 -0800 (Fri, 28 Nov 2008) | 1 line Simplify PyBeanProperty construction ........ r5657 | cgroves | 2008-11-28 13:53:04 -0800 (Fri, 28 Nov 2008) | 1 line More cleanup ........ r5658 | cgroves | 2008-11-28 16:17:40 -0800 (Fri, 28 Nov 2008) | 12 lines Only attempt proxyInitting if __init__ has been found and worked, and only actually init instances of PyProxy. Add an __init__ for all Java classes, even interfaces and abstract classes. Handle throwing type errors for uninstantiable classes in PyReflectedConstructor. Pass _is and _isnot through to the javaproxy == if javaproxy is around. This assumes a constant mapping between a given Java type and the PyType wrapping it, but I think that's safe. ........ r5659 | cgroves | 2008-11-28 16:48:32 -0800 (Fri, 28 Nov 2008) | 9 lines Assign the type on PyBeanProperty to the type returned by its getter and only use a setter if its parameter's type matches that. Push accesses to PyObject.javaProxy that query information from the proxy through getJavaProxy. This calls proxyInit if the proxy doesn't already exist which keeps things from blowing up if something accesses the javaProxy in an __init__. ........ r5662 | cgroves | 2008-11-29 16:40:22 -0800 (Sat, 29 Nov 2008) | 6 lines Make java.lang.Object and Java interfaces descend from the Python object type. This changed the class initialization order, so put static constants in PyJavaType in a static method so they're actually initialized at time of use. ........ r5663 | cgroves | 2008-11-29 18:30:42 -0800 (Sat, 29 Nov 2008) | 1 line Hook bean events up in PyJavaType. All of test_java_integration passes again. ........ r5666 | cgroves | 2008-11-30 17:00:37 -0800 (Sun, 30 Nov 2008) | 7 lines Replace fillDict with init which encapsulates all the differences between PyType and PyJavaType initialization. Have bootstrap types use init as well to remove the duplication of type builder initialization. Include interfaces and superclasses in the mro of wrapped Java types. ........ r5667 | cgroves | 2008-11-30 17:06:33 -0800 (Sun, 30 Nov 2008) | 1 line PyReflectedFunction no longer exposes a String constructor ........ r5668 | cgroves | 2008-11-30 17:08:51 -0800 (Sun, 30 Nov 2008) | 1 line Go ahead and take multiple methods in PyReflectedFunction's constructor ........ r5669 | cgroves | 2008-11-30 17:14:21 -0800 (Sun, 30 Nov 2008) | 1 line Reset a PyJavaType's state when reload is called on it. This was just ignored on PyJavaClasses, so this is a little step up ........ r5673 | cgroves | 2008-12-01 21:23:26 -0800 (Mon, 01 Dec 2008) | 5 lines Changing the items in the dicts of loaded classes seemed to be confusing the exceptions module at least, so let's leave reloading Java classes a no-op until a later date. ........ r5674 | cgroves | 2008-12-01 23:46:14 -0800 (Mon, 01 Dec 2008) | 1 line Better error message for a bad version string, use the actual banner for checking ........ r5675 | cgroves | 2008-12-01 23:47:23 -0800 (Mon, 01 Dec 2008) | 3 lines Hook up container methods for Map separately as it isn't actually a Collection. ........ r5676 | cgroves | 2008-12-02 02:54:26 -0800 (Tue, 02 Dec 2008) | 4 lines Patch #1148 from Geoffrey French. Adds slice and negative index support to get, set and del methods on wrapped instances of java.util.List. ........ r5688 | cgroves | 2008-12-03 17:10:43 -0800 (Wed, 03 Dec 2008) | 8 lines Switch to using getJavaProxy() != null from getType() instanceof PyJavaType to detect if a PyObject is wrapping a Java object or a subclass of a Java object. This keeps PyObject subclasses from appearing to be proxy types. The old way was breaking copy as instances of classic classes - which have a type of PyJavaType by virtue of PyClass being a non-type subclass of PyObject - didn't have a Java proxy and were getting a different id with each call. ........ r5689 | cgroves | 2008-12-03 17:27:28 -0800 (Wed, 03 Dec 2008) | 1 line Only add inner classes to the dict of a Java type if there isn't already something with that name. Fixes test_cpickle ........ r5692 | cgroves | 2008-12-03 18:30:34 -0800 (Wed, 03 Dec 2008) | 7 lines Leave ExposedType annotations on processed types so they'll be visible at runtime. Use that to detect exposed inner classes in classes being loaded. Inner classes being loaded won't have set their builder in PyType yet, so they need to be added to BOOTSTRAP_TYPES so they're created as PyType instead of PyJavaType. ........ r5693 | cgroves | 2008-12-04 15:52:01 -0800 (Thu, 04 Dec 2008) | 1 line Expose __iter__ on Iterator in addition to Iterable and Map ........ r5694 | cgroves | 2008-12-04 16:26:54 -0800 (Thu, 04 Dec 2008) | 1 line Expose __hash__ on Object. I'm amazed at the number of things that passed without this ........ r5698 | cgroves | 2008-12-04 20:06:23 -0800 (Thu, 04 Dec 2008) | 1 line Get test_jy_internals passing again ........ r5699 | cgroves | 2008-12-05 01:06:12 -0800 (Fri, 05 Dec 2008) | 1 line Don't worry about the count, just assert the things that should and shouldn't be visible ........ r5700 | cgroves | 2008-12-05 03:21:55 -0800 (Fri, 05 Dec 2008) | 5 lines Make methods from superclasses and superinterfaces of private, protected or package protected classes call through their parent versions. Fixes blowups with a package protected implementation of attributes in sax. ........ r5701 | cgroves | 2008-12-05 03:38:02 -0800 (Fri, 05 Dec 2008) | 1 line Avoid non-public interface methods similarly to non-public class methods ........ r5705 | cgroves | 2008-12-05 18:35:31 -0800 (Fri, 05 Dec 2008) | 1 line Needs to be serializable for PySequence to be serializable ........ r5707 | cgroves | 2008-12-05 19:01:16 -0800 (Fri, 05 Dec 2008) | 1 line Tidying ........ r5708 | cgroves | 2008-12-05 19:23:28 -0800 (Fri, 05 Dec 2008) | 1 line Pull the proxy class directly out of the type. Fixes test_jser2 ........ r5709 | cgroves | 2008-12-05 20:19:46 -0800 (Fri, 05 Dec 2008) | 5 lines Add a target to run a single junit test from the tests directory. ant -Dtest=InterpreterTest singlejavatest will run just org.python.util.InterpreterTest and report to the console. ........ r5710 | cgroves | 2008-12-05 20:23:45 -0800 (Fri, 05 Dec 2008) | 6 lines Fix deserializing Jython objects while not in Python code. __builtin__.__import__ was changed to bail if Py.getFrame was null, but it can be called from Java code as in PyObjectInputStream, so it should just use PySystemState.builtins if it doesn't have a set of builtins from the frame. ........ r5711 | cgroves | 2008-12-05 21:18:08 -0800 (Fri, 05 Dec 2008) | 1 line Identify Java exceptions as exceptions ........ r5727 | cgroves | 2008-12-09 22:30:28 -0800 (Tue, 09 Dec 2008) | 1 line exceptions needs to extend PyObject to keep from being exposed as a descendent of Object ........ r5728 | cgroves | 2008-12-09 22:47:19 -0800 (Tue, 09 Dec 2008) | 4 lines Like exceptions, operator needs to extend PyObject to keep from picking up Object methods. Fixes test_richcmp. ........ r5729 | cgroves | 2008-12-09 23:09:49 -0800 (Tue, 09 Dec 2008) | 4 lines Allow setattr and delattr to access the dicts of PyJavaTypes. Fixes test_strptime as Time was expected to allow modification to its dict. ........ Modified Paths: -------------- trunk/jython/Lib/test/jser2_classes.py trunk/jython/Lib/test/test_array_jy.py trunk/jython/Lib/test/test_cmd_line.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_joverload.py trunk/jython/Lib/test/test_jser2.py trunk/jython/Lib/test/test_jy_internals.py trunk/jython/build.xml trunk/jython/src/org/python/antlr/adapter/AliasAdapter.java trunk/jython/src/org/python/antlr/adapter/CmpopAdapter.java trunk/jython/src/org/python/antlr/adapter/ComprehensionAdapter.java trunk/jython/src/org/python/antlr/adapter/ExcepthandlerAdapter.java trunk/jython/src/org/python/antlr/adapter/ExprAdapter.java trunk/jython/src/org/python/antlr/adapter/IdentifierAdapter.java trunk/jython/src/org/python/antlr/adapter/KeywordAdapter.java trunk/jython/src/org/python/antlr/adapter/SliceAdapter.java trunk/jython/src/org/python/antlr/adapter/StmtAdapter.java trunk/jython/src/org/python/compiler/ProxyMaker.java trunk/jython/src/org/python/core/AstList.java trunk/jython/src/org/python/core/IdImpl.java trunk/jython/src/org/python/core/Options.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBaseExceptionDerived.java trunk/jython/src/org/python/core/PyBeanEvent.java trunk/jython/src/org/python/core/PyBeanEventProperty.java trunk/jython/src/org/python/core/PyBeanProperty.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyBuiltinCallable.java trunk/jython/src/org/python/core/PyBuiltinMethod.java trunk/jython/src/org/python/core/PyClass.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyCompoundCallable.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyEnumerateDerived.java trunk/jython/src/org/python/core/PyException.java trunk/jython/src/org/python/core/PyFile.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/PyInstance.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyJavaPackage.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyList.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/PyObject.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PyProxy.java trunk/jython/src/org/python/core/PyReflectedConstructor.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/PySequence.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/PyType.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/core/StdoutWrapper.java trunk/jython/src/org/python/core/ThreadState.java trunk/jython/src/org/python/core/__builtin__.java trunk/jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java trunk/jython/src/org/python/core/adapter/PyObjectAdapter.java trunk/jython/src/org/python/core/exceptions.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/io/BufferedIOMixin.java trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/IOBase.java trunk/jython/src/org/python/core/io/StreamIO.java trunk/jython/src/org/python/core/io/TextIOBase.java trunk/jython/src/org/python/expose/generate/ExposedTypeProcessor.java trunk/jython/src/org/python/expose/generate/ExposedTypeVisitor.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/_hashlib.java trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java trunk/jython/src/org/python/modules/cPickle.java trunk/jython/src/org/python/modules/cStringIO.java trunk/jython/src/org/python/modules/math.java trunk/jython/src/org/python/modules/operator.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/org/python/util/PythonObjectInputStream.java trunk/jython/src/templates/object.derived trunk/jython/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java trunk/jython/tests/java/org/python/util/InterpreterTest.java Added Paths: ----------- trunk/jython/Lib/test/test_java_list_delegate.py trunk/jython/src/org/python/core/SequenceIndexDelegate.java trunk/jython/tests/java/org/python/tests/InterfaceCombination.java trunk/jython/tests/java/org/python/tests/SerializationTest.java Removed Paths: ------------- trunk/jython/Lib/jreload.py trunk/jython/Lib/jxxload_help/ trunk/jython/Lib/test/test_jreload.py trunk/jython/src/org/python/core/AutoInternalTables.java trunk/jython/src/org/python/core/CollectionIter.java trunk/jython/src/org/python/core/CollectionProxy.java trunk/jython/src/org/python/core/InternalTables.java trunk/jython/src/org/python/core/PyJavaClass.java trunk/jython/src/org/python/core/PyJavaInnerClass.java trunk/jython/src/org/python/core/PyJavaInstance.java trunk/jython/src/org/python/core/SoftIInternalTables.java trunk/jython/src/org/python/core/WeakInternalTables.java trunk/jython/src/org/python/modules/_jython.java Property Changed: ---------------- trunk/jython/ trunk/jython/Lib/test/jser2_classes.py trunk/jython/Lib/test/test_jser2.py Property changes on: trunk/jython ___________________________________________________________________ Modified: svnmerge-integrated - /branches/astwrite:1-5692 /branches/newstyle-java-types:1-5563 + /branches/astwrite:1-5692 /branches/newstyle-java-types:1-5738 Added: svn:mergeinfo + /branches/newstyle-java-types:5564-5663,5666-5729 Deleted: trunk/jython/Lib/jreload.py =================================================================== --- trunk/jython/Lib/jreload.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/jreload.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,119 +0,0 @@ -# java classes reload support (experimental) -# Copyright 2000 Samuele Pedroni - -# ?? could have problem with import pkg.jclass.inner (this should not be used in any case) -# ?? using import * with a load-set together with reloading can be confusing -# cannot be fixed => anyway import * is not for production code - -__version__ = "0.3" - -import sys -from org.python.core import imp,PyJavaPackage,PyJavaClass -from _jython import is_lazy as _is_lazy - -import jxxload_help - - -class _LoaderFactory(jxxload_help.JavaLoaderFactory): - def __init__(self,path): - vfs = jxxload_help.PathVFS() - for fname in path: - vfs.addVFS(fname) - self.vfs = vfs - - def makeLoader(self): - return jxxload_help.PathVFSJavaLoader(self.vfs,imp.getSyspathJavaLoader()) - -class _Unload: - - def __init__(self,ls): - self.ls = ls - self.ls_name = ls._name - self.loader = ls._mgr.loader - - def do_unload(self,pkg): - for n in pkg.__dict__.keys(): - e = pkg.__dict__[n] - if isinstance(e,PyJavaClass): - if _is_lazy(e): continue - if e.classLoader is self.loader: - del pkg.__dict__[n] - if pkg.__name__: - n = self.ls_name + '.' + pkg.__name__ + '.' +n - else: - n = self.ls_name + '.' + n - if sys.modules.has_key(n): del sys.modules[n] - - elif isinstance(e,PyJavaPackage): - self.do_unload(e) - - def __call__(self): - if self.loader: - if self.ls._mgr.checkLoader() is self.loader: - self.do_unload(self.ls._top) - self.ls._mgr.resetLoader() - loader = self.loader - jxxload_help.DiscardHelp.discard(loader,loader.interfaces) - self.loader = None - -class LoadSet: -# ?? for the moment from import * and dir do not work for LoadSet, but work for -# contained pkgs -# need java impl as PyObject - - def __init__(self,name,path): - mgr = jxxload_help.PackageManager(path,_LoaderFactory(path)) - self._name = name - self._mgr = mgr - self._top = mgr.topLevelPackage - - def __getattr__(self,name): - try: - return getattr(self._top,name) - except: - if name == 'unload': return _Unload(self) - raise - - - def __repr__(self): - return "<java load-set %s>" % self._name - -def unloadf(ls): - if not isinstance(ls,LoadSet): raise TypeError,"unloadf(): arg is not a load-set" - return _Unload(ls) - -def makeLoadSet(name,path): - if sys.modules.has_key(name): return sys.modules[name] - sys.modules[name] = ls = LoadSet(name,path) - return ls - -_reload = reload - -def _do_reload(ls_name,mgr,pkg): - pkg_name = pkg.__name__ - for n in pkg.__dict__.keys(): - e = pkg.__dict__[n] - if isinstance(e,PyJavaClass): - if _is_lazy(e): continue - del pkg.__dict__[n] - try : - c = mgr.findClass(pkg_name,n); - if c: - pkg.__dict__[n] = c - if pkg_name: - n = ls_name + '.' + pkg_name + '.' + n - else: - n = ls_name + '.' + n - if sys.modules.has_key(n): sys.modules[n] = c - except: - pass - elif isinstance(e,PyJavaPackage): - _do_reload(ls_name,mgr,e) - -def reload(ls): - if isinstance(ls,LoadSet): - ls._mgr.resetLoader() - _do_reload(ls._name,ls._mgr,ls._top) - return ls - else: - return _reload(ls) Modified: trunk/jython/Lib/test/jser2_classes.py =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/jser2_classes.py ___________________________________________________________________ Deleted: svn:mime-type - application/octet-stream Modified: trunk/jython/Lib/test/test_array_jy.py =================================================================== --- trunk/jython/Lib/test/test_array_jy.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_array_jy.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -12,7 +12,7 @@ def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initilaizers. + # While jarray is still being phased out, just flex the initializers. # The rest of the test for array will catch all the big problems. import jarray jarray.array(range(5), 'i') @@ -23,7 +23,7 @@ def test_java_object_arrays(self): jStringArr = array(String, [String("a"), String("b"), String("c")]) self.assert_( - Arrays.equals(jStringArr.typecode, str(String)), + Arrays.equals(jStringArr.typecode, 'java.lang.String'), "String array typecode of wrong type, expected %s, found %s" % (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) Modified: trunk/jython/Lib/test/test_cmd_line.py =================================================================== --- trunk/jython/Lib/test/test_cmd_line.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_cmd_line.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -45,8 +45,11 @@ self.assertTrue('usage' in self.start_python('-h')) def test_version(self): - version = 'Jython %d.%d' % sys.version_info[:2] - self.assertTrue(self.start_python('-V').startswith(version)) + from org.python.util import InteractiveConsole + expected = InteractiveConsole.getDefaultBanner() + reported = self.start_python('-V') + self.assertTrue(reported.startswith(expected), + "-V should start with '%s' but it printed '%s'" % (expected, reported)) def test_main(): test.test_support.run_unittest(CmdLineTest) Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -6,7 +6,7 @@ from test import test_support from java.awt import (Dimension, Component, Rectangle, Button, Color, HeadlessException) -from java.util import Vector, Hashtable +from java.util import ArrayList, Vector, HashMap, Hashtable from java.io import FileOutputStream, FileWriter, OutputStreamWriter from java.lang import Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte @@ -55,9 +55,6 @@ A() class InstantiationTest(unittest.TestCase): - def test_cant_create_abstract(self): - self.assertRaises(TypeError, Component) - def test_can_subclass_abstract(self): class A(Component): pass @@ -339,8 +336,11 @@ class ColorTest(unittest.TestCase): def test_static_fields(self): - Color.red - Color.blue + self.assertEquals(Color(255, 0, 0), Color.RED) + # The bean accessor for getRed should be active on instances, but the static field red + # should be visible on the class + self.assertEquals(255, Color.red.red) + self.assertEquals(Color(0, 0, 255), Color.blue) def test_is_operator(self): red = Color.red @@ -363,7 +363,7 @@ y = BigDecimalTest().asBigDecimal() self.assertEqual(type(x), type(y), "BigDecimal coerced") - self.assertEqual(x, y, "BigDecimal coerced") + self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") class MethodInvTest(unittest.TestCase): @@ -394,6 +394,37 @@ x = lang.String('test') self.assertRaises(TypeError, list, x) +class JavaDelegationTest(unittest.TestCase): + def test_list_delegation(self): + for c in ArrayList, Vector: + a = c() + a.add("blah") + self.assertTrue("blah" in a) + self.assertEquals(1, len(a)) + n = 0 + for i in a: + n += 1 + self.assertEquals("blah", i) + self.assertEquals(1, n) + self.assertEquals("blah", a[0]) + a[0] = "bleh" + del a[0] + self.assertEquals(0, len(a)) + + def test_map_delegation(self): + m = HashMap() + m["a"] = "b" + self.assertTrue("a" in m) + self.assertEquals("b", m["a"]) + n = 0 + for k in m: + n += 1 + self.assertEquals("a", k) + self.assertEquals(1, n) + del m["a"] + self.assertEquals(0, len(m)) + + def test_main(): test_support.run_unittest(AbstractOnSyspathTest, InstantiationTest, @@ -414,6 +445,7 @@ MethodInvTest, InterfaceTest, JavaStringTest, + JavaDelegationTest, ) if __name__ == "__main__": Copied: trunk/jython/Lib/test/test_java_list_delegate.py (from rev 5729, branches/newstyle-java-types/Lib/test/test_java_list_delegate.py) =================================================================== --- trunk/jython/Lib/test/test_java_list_delegate.py (rev 0) +++ trunk/jython/Lib/test/test_java_list_delegate.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -0,0 +1,181 @@ +from java.util import ArrayList, List, Vector + +from copy import copy + +import unittest +import test.test_support + +class CollectionProxyTest(unittest.TestCase): + def _perform_op(self, value, op_func): + """ + Perform an operation + + value - the value to operate on + op_func - the function that applies the operation to value + + Returns: + the result of calling op_func, OR the exception that was raised in op_func + """ + try: + return op_func(value) + except Exception, e: + return type(e) + + def check_list(self, control, results, initial): + for result in results: + try: + len(result) + except: + print result + self.assertEquals(len(control), len(result), "%s is wrong for %s" % (type(result), initial)) + for pvalue, jvalue in zip(control, result): + self.assertEquals(pvalue, jvalue) + + def _list_op_test(self, initial_value, op_func, check_value): + """ + Tests a list operation + + Ensures that performing an operation on: + - a python list + - a java.util.List instance + + givens the same result in both cases + """ + lists = [list(initial_value), ArrayList(initial_value), Vector(initial_value)] + + results = [self._perform_op(l, op_func) for l in lists] + self.check_list(lists[0], lists[1:], initial_value) + if check_value or not isinstance(results[0], list): + for r in results[1:]: + self.assertEquals(results[0], r) + else: + self.check_list(results[0], results[1:], initial_value) + + def test_get_integer(self): + initial_value = range(0, 5) + + for i in xrange(-7, 7): + self._list_op_test(initial_value, lambda xs: xs[i], True) + + def test_set_integer(self): + initial_value = range(0, 5) + + def make_op_func(index): + def _f(xs): + xs[index] = 100 + return _f + + for i in xrange(-7, 7): + self._list_op_test(initial_value, make_op_func(i), True) + + def test_set_slice(self): + initial_value = range(0, 10) + + def make_op_func(i, j, k, v): + def _f(xs): + xs[i:j:k] = v + return _f + + for i in xrange(-12, 12): + for j in xrange(-12, 12): + for k in xrange(-12, 12): + self._list_op_test(initial_value, make_op_func(i, j, k, []), True) + self._list_op_test(initial_value, make_op_func(i, j, k, range(0,2)), True) + self._list_op_test(initial_value, make_op_func(i, j, k, range(0,4)), True) + self._list_op_test(initial_value, make_op_func(i, j, k, xrange(0,2)), True) + + def test_del_integer(self): + initial_value = range(0,5) + + def make_op_func(index): + def _f(xs): + del xs[index] + return _f + + for i in xrange(-7, 7): + self._list_op_test(initial_value, make_op_func(i), True) + + def test_del_slice(self): + initial_value = range(0,10) + + def make_op_func(i, j, k): + def _f(xs): + del xs[i:j:k] + return _f + + for i in xrange(-12, 12): + for j in xrange(-12, 12): + for k in xrange(-12, 12): + self._list_op_test(initial_value, make_op_func(i, j, k), True) + + def test_len(self): + jlist = ArrayList() + jlist.addAll(range(0, 10)) + + self.assert_(len(jlist) == 10) + + def test_iter(self): + jlist = ArrayList() + jlist.addAll(range(0, 10)) + + i = iter(jlist) + + x = list(i) + + self.assert_(x == range(0, 10)) + + def test_override_len(self): + class MyList (ArrayList): + def __len__(self): + return self.size() + 1; + + m = MyList() + m.addAll(range(0,10)) + + self.assert_(len(m) == 11) + + def test_override_iter(self): + class MyList (ArrayList): + def __iter__(self): + return iter(self.subList(0, self.size() - 1)); + + + m = MyList() + m.addAll(range(0,10)) + i = iter(m) + x = list(i) + + self.assert_(x == range(0, 9)) + + def test_override_getsetdelitem(self): + # Create an ArrayList subclass that provides some silly overrides for get/set/del item + class MyList (ArrayList): + def __getitem__(self, key): + return self.get(key) * 2; + + def __setitem__(self, key, value): + return self.set(key, value * 2); + + def __delitem__(self, key): + self.add(84) + + + m = MyList() + m.addAll(range(0,10)) + + self.assert_(m[1] == 2) + self.assert_(m.get(1) == 1) + + m[0] = 3 + self.assert_(m.get(0) == 6) + self.assert_(m[0] == 12) + + del m[0] + self.assert_(m.size() == 11) + self.assert_(m.get(10) == 84) + +def test_main(): + test.test_support.run_unittest(CollectionProxyTest) + +if __name__ == "__main__": + test_main() Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,11 +1,14 @@ import unittest from test import test_support -from org.python.tests import Invisible, SubVisible, Visible, VisibleOverride +from org.python.tests import InterfaceCombination, Invisible, SubVisible, Visible, VisibleOverride from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): def test_invisible(self): - self.assertEquals([], dir(Invisible)) + for item in dir(Invisible): + self.assert_(not item.startswith("package")) + self.assert_(not item.startswith("private")) + self.assert_(not item.startswith("protected")) def test_protected_from_python_subclass(self): class SubVisible(Visible): @@ -22,8 +25,6 @@ self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) def test_visible(self): - self.assertEquals(5, len(dir(Visible))) - v = Visible() self.assertEquals(Results.PUBLIC_FIELD, v.visibleField) self.assertEquals(Results.PUBLIC_STATIC_FIELD, Visible.visibleStaticField) @@ -66,8 +67,21 @@ self.failUnless('visibleInstance' in c.__dict__, 'visibleInstance expected in %s __dict__' % c) + def test_interface_combination(self): + '''Checks that a private class that extends a public class and public interfaces has only the items + from the public bases visible''' + i = InterfaceCombination.newImplementation() + self.assertEquals(InterfaceCombination.NO_ARG_RESULT, i.getValue(), + "methods from IFace should be visible on Implementation") + self.assertEquals(InterfaceCombination.ONE_ARG_RESULT, i.getValue("one arg"), + "methods from IIFace should be visible on Implementation") + self.assertEquals(InterfaceCombination.TWO_ARG_RESULT, i.getValue("one arg", "two arg"), + "methods from Base should be visible on Implementation") + self.assertRaises(TypeError, i.getValue, "one arg", "two arg", "three arg", + "methods defined solely on Implementation shouldn't be visible") + self.assertFalse(hasattr(i, "internalMethod"), + "methods from private interfaces shouldn't be visible on a private class") - def test_main(): test_support.run_unittest(VisibilityTest) Modified: trunk/jython/Lib/test/test_joverload.py =================================================================== --- trunk/jython/Lib/test/test_joverload.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_joverload.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -6,14 +6,12 @@ import unittest import java -import org.python.core +from org.python.core import PyReflectedFunction class PyReflFuncEnvl: def __init__(self,name,meths): - self.reflfunc = org.python.core.PyReflectedFunction(name) - for meth in meths: - self.reflfunc.addMethod(meth) + self.reflfunc = PyReflectedFunction(meths) def __call__(self,inst,args): return self.reflfunc(inst,*args) Deleted: trunk/jython/Lib/test/test_jreload.py =================================================================== --- trunk/jython/Lib/test/test_jreload.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_jreload.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,33 +0,0 @@ -"""This test validates the fix for 511493 (jreload truncates large class files). - -We do this by loading a large class file Blob.class from blob.jar (source inside the jar). If the load failes with ClassFormatError, -the bug is present, if the load succeeds, the bug is fixed, if something else occurs, we don't know. -""" - -import unittest -from test import test_support - -from jreload import makeLoadSet -from java.lang import System, ClassFormatError - -import os - -class JreloadTestCase(unittest.TestCase): - - blobjar = test_support.findfile('blob.jar') - - def test( self ): - myls = makeLoadSet('myls', [self.blobjar]) - - try: - from myls import Blob - except ClassFormatError: - print "Reload Error is present" - raise - -def test_main(): - test_support.run_unittest(JreloadTestCase) - -if __name__ == "__main__": - test_main() - Modified: trunk/jython/Lib/test/test_jser2.py =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/test_jser2.py ___________________________________________________________________ Deleted: svn:mime-type - application/octet-stream Modified: trunk/jython/Lib/test/test_jy_internals.py =================================================================== --- trunk/jython/Lib/test/test_jy_internals.py 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/Lib/test/test_jy_internals.py 2008-12-12 03:57:33 UTC (rev 5739) @@ -60,7 +60,7 @@ iarr = java.lang.Object.getClass(self.e) sdv = java.lang.Class.getMethod(long, 'scaledDoubleValue', [iarr]) import org.python.core.PyReflectedFunction as ReflFunc - self.sdv = ReflFunc(sdv) + self.sdv = ReflFunc([sdv]) def test_basic_roundtrip(self): e = self.e Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/build.xml 2008-12-12 03:57:33 UTC (rev 5739) @@ -757,6 +757,16 @@ </target> <target name="test" depends="prepare-test,javatest,launchertest,regrtest"/> + <target name="singlejavatest" depends="compile,expose"> + <junit haltonfailure="true" fork="true"> + <formatter type="brief" usefile="false"/> + <sysproperty key="python.cachedir.skip" value="true"/> + <classpath refid="test.classpath"/> + <batchtest> + <fileset dir="${test.source.dir}" includes="**/${test}.java"/> + </batchtest> + </junit> + </target> <target name="prepare-test" depends="init"> <!-- Clean any old test output --> <delete dir="${junit.reports}"/> Modified: trunk/jython/src/org/python/antlr/adapter/AliasAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/AliasAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/AliasAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,14 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyJavaInstance; - -import org.python.antlr.ast.alias; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.ast.alias; +import org.python.core.Py; +import org.python.core.PyObject; + public class AliasAdapter implements AstAdapter { public Object py2ast(PyObject o) { @@ -29,7 +27,7 @@ public List iter2ast(PyObject iter) { List<alias> aliases = new ArrayList<alias>(); for(Object o : (Iterable)iter) { - aliases.add((alias)py2ast((PyObject)(PyObject)o)); + aliases.add((alias)py2ast((PyObject)o)); } return aliases; } Modified: trunk/jython/src/org/python/antlr/adapter/CmpopAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/CmpopAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/CmpopAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,28 +1,26 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyJavaInstance; +import java.util.ArrayList; +import java.util.List; import org.python.antlr.ast.cmpopType; import org.python.antlr.op.Eq; -import org.python.antlr.op.NotEq; -import org.python.antlr.op.Lt; -import org.python.antlr.op.LtE; import org.python.antlr.op.Gt; import org.python.antlr.op.GtE; +import org.python.antlr.op.In; import org.python.antlr.op.Is; import org.python.antlr.op.IsNot; -import org.python.antlr.op.In; +import org.python.antlr.op.Lt; +import org.python.antlr.op.LtE; +import org.python.antlr.op.NotEq; import org.python.antlr.op.NotIn; +import org.python.core.Py; +import org.python.core.PyObject; -import java.util.ArrayList; -import java.util.List; - public class CmpopAdapter implements AstAdapter { public Object py2ast(PyObject o) { - switch (((PyObject)o).asInt()) { + switch ((o).asInt()) { case 1: return cmpopType.Eq; case 2: @@ -53,23 +51,23 @@ switch ((cmpopType)o) { case Eq: return new Eq(); - case NotEq: + case NotEq: return new NotEq(); - case Lt: + case Lt: return new Lt(); - case LtE: + case LtE: return new LtE(); - case Gt: + case Gt: return new Gt(); - case GtE: + case GtE: return new GtE(); - case Is: + case Is: return new Is(); - case IsNot: + case IsNot: return new IsNot(); - case In: + case In: return new In(); - case NotIn: + case NotIn: return new NotIn(); } return Py.None; Modified: trunk/jython/src/org/python/antlr/adapter/ComprehensionAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/ComprehensionAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/ComprehensionAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,14 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyJavaInstance; - -import org.python.antlr.ast.comprehension; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.ast.comprehension; +import org.python.core.Py; +import org.python.core.PyObject; + public class ComprehensionAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/antlr/adapter/ExcepthandlerAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,15 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyJavaInstance; - -import org.python.antlr.ast.ExceptHandler; -import org.python.antlr.ast.Num; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.ast.ExceptHandler; +import org.python.core.Py; +import org.python.core.PyObject; + public class ExcepthandlerAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/antlr/adapter/ExprAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/ExprAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/ExprAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,24 +1,22 @@ package org.python.antlr.adapter; +import java.util.ArrayList; +import java.util.List; + +import org.python.antlr.ast.Num; +import org.python.antlr.ast.Str; +import org.python.antlr.base.expr; import org.python.core.Py; import org.python.core.PyComplex; import org.python.core.PyFloat; import org.python.core.PyInteger; import org.python.core.PyLong; -import org.python.core.PyJavaInstance; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyUnicode; -import org.python.antlr.base.expr; -import org.python.antlr.ast.Num; -import org.python.antlr.ast.Str; - -import java.util.ArrayList; -import java.util.List; - public class ExprAdapter implements AstAdapter { - + public Object py2ast(PyObject o) { if (o == null || o instanceof expr) { return o; Modified: trunk/jython/src/org/python/antlr/adapter/IdentifierAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/IdentifierAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/IdentifierAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,15 +1,11 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyJavaInstance; -import org.python.core.PyObject; -import org.python.core.PyString; - -import org.python.antlr.ast.Num; - import java.util.ArrayList; import java.util.List; +import org.python.core.PyObject; +import org.python.core.PyString; + public class IdentifierAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/antlr/adapter/KeywordAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/KeywordAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/KeywordAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,14 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyJavaInstance; -import org.python.core.PyObject; - -import org.python.antlr.ast.keyword; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.ast.keyword; +import org.python.core.Py; +import org.python.core.PyObject; + public class KeywordAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/antlr/adapter/SliceAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/SliceAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/SliceAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,15 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyJavaInstance; -import org.python.core.PyObject; - -import org.python.antlr.ast.Num; -import org.python.antlr.base.slice; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.base.slice; +import org.python.core.Py; +import org.python.core.PyObject; + public class SliceAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/antlr/adapter/StmtAdapter.java =================================================================== --- trunk/jython/src/org/python/antlr/adapter/StmtAdapter.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/antlr/adapter/StmtAdapter.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,14 +1,12 @@ package org.python.antlr.adapter; -import org.python.core.Py; -import org.python.core.PyJavaInstance; -import org.python.core.PyObject; - -import org.python.antlr.base.stmt; - import java.util.ArrayList; import java.util.List; +import org.python.antlr.base.stmt; +import org.python.core.Py; +import org.python.core.PyObject; + public class StmtAdapter implements AstAdapter { public Object py2ast(PyObject o) { Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -12,6 +12,9 @@ import java.util.Set; import org.python.core.Py; +import org.python.core.PyJavaType; +import org.python.core.PyObject; +import org.python.core.PyProxy; import org.python.objectweb.asm.Label; import org.python.objectweb.asm.Opcodes; import org.python.util.Generic; @@ -53,13 +56,40 @@ else return ((Integer)i).intValue(); } + /** + * Retrieves <code>name</code> from the PyObject in <code>proxy</code> if it's defined in + * Python. This is a specialized helper function for internal PyProxy use. + */ + public static PyObject findPython(PyProxy proxy, String name) { + PyObject o = proxy._getPyInstance(); + if (o == null) { + 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; + } + } + if (ret == null) { + return null; + } + Py.setSystemState(proxy._getPySystemState()); + return ret.__get__(o, null); + } + Class<?> superclass; Class<?>[] interfaces; Set<String> names; Set<String> supernames = Generic.set(); public ClassFile classfile; public String myClass; - public boolean isAdapter=false; public ProxyMaker(String classname, Class<?> superclass) { this.myClass = "org.python.proxies."+classname; @@ -432,7 +462,8 @@ if (!isAbstract) { int tmp = code.getLocal("org/python/core/PyObject"); - code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); + code.invokestatic("org/python/compiler/ProxyMaker", "findPython", "(" + $pyProxy + $str + + ")" + $pyObj); code.astore(tmp); code.aload(tmp); @@ -449,20 +480,15 @@ addSuperMethod("super__"+name, name, superClass, parameters, ret, sig, access); } else { - if (!isAdapter) { - code.invokestatic("org/python/core/Py", "jgetattr", "(" + $pyProxy + $str + ")" + $pyObj); - callMethod(code, name, parameters, ret, method.getExceptionTypes()); - } else { - code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); - code.dup(); - Label returnNull = new Label(); - code.ifnull(returnNull); - - callMethod(code, name, parameters, ret, method.getExceptionTypes()); - code.label(returnNull); - code.pop(); - doNullReturn(code, ret); - } + code.invokestatic("org/python/compiler/ProxyMaker", "findPython", "(" + $pyProxy + $str + + ")" + $pyObj); + code.dup(); + Label returnNull = new Label(); + code.ifnull(returnNull); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); + code.label(returnNull); + code.pop(); + doNullReturn(code, ret); } } @@ -600,23 +626,23 @@ public void addProxy() throws Exception { // implement PyProxy interface - classfile.addField("__proxy", "Lorg/python/core/PyInstance;", + classfile.addField("__proxy", "Lorg/python/core/PyObject;", Modifier.PROTECTED); // setProxy methods Code code = classfile.addMethod("_setPyInstance", - "(Lorg/python/core/PyInstance;)V", + "(Lorg/python/core/PyObject;)V", Modifier.PUBLIC); code.aload(0); code.aload(1); - code.putfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.putfield(classfile.name, "__proxy", "Lorg/python/core/PyObject;"); code.return_(); // getProxy method code = classfile.addMethod("_getPyInstance", - "()Lorg/python/core/PyInstance;", + "()Lorg/python/core/PyObject;", Modifier.PUBLIC); code.aload(0); - code.getfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.getfield(classfile.name, "__proxy", "Lorg/python/core/PyObject;"); code.areturn(); // implement PyProxy interface Modified: trunk/jython/src/org/python/core/AstList.java =================================================================== --- trunk/jython/src/org/python/core/AstList.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/core/AstList.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -6,13 +6,6 @@ */ package org.python.core; -import org.python.antlr.adapter.AstAdapter; -import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; -import org.python.expose.ExposedNew; -import org.python.expose.ExposedType; -import org.python.expose.MethodType; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -20,6 +13,12 @@ import java.util.List; import java.util.ListIterator; +import org.python.antlr.adapter.AstAdapter; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedType; +import org.python.expose.MethodType; + @ExposedType(name = "_ast.astlist", base = PyList.class) public class AstList extends PySequence implements Cloneable, List { @@ -269,7 +268,7 @@ final String astlist_toString() { return data.toString(); } - + public void append(PyObject o) { astlist_append(o); } @@ -331,8 +330,8 @@ private int _index(PyObject o, String message, int start, int stop) { // Follow Python 2.3+ behavior - int validStop = calculateIndex(stop); - int validStart = calculateIndex(start); + int validStop = boundToSequence(stop); + int validStart = boundToSequence(start); for(int i = validStart; i < validStop && i < size(); i++) { if(data.get(i).equals(o)) { return i; @@ -358,7 +357,7 @@ } } } - + @ExposedMethod final void astlist_extend(PyObject iterable){ int length = size(); @@ -401,7 +400,7 @@ } data.add(index, o); } - + @ExposedMethod final void astlist_remove(PyObject value){ del(_index(value, "astlist.remove(x): x not in list", 0, size())); @@ -434,7 +433,7 @@ return (PyObject)data.remove(n); } Object element = data.remove(n); - return (PyObject)adapter.ast2py(element); + return adapter.ast2py(element); } @@ -454,7 +453,7 @@ } return new AstList(newList); } - + protected void set(int i, PyObject value) { data.set(i, value); } Deleted: trunk/jython/src/org/python/core/AutoInternalTables.java =================================================================== --- trunk/jython/src/org/python/core/AutoInternalTables.java 2008-12-12 03:31:52 UTC (rev 5738) +++ trunk/jython/src/org/python/core/AutoInternalTables.java 2008-12-12 03:57:33 UTC (rev 5739) @@ -1,155 +0,0 @@ -// Copyright 2000 Samuele Pedroni - -package org.python.core; - -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.util.Map; - -public abstract class AutoInternalTables extends InternalTables { - - protected transient ReferenceQueue queue = new ReferenceQueue(); - - protected abstract Reference newAutoRef(short type, Object key, - Object obj); - protected abstract short getAutoRefType(Reference ref); - protected abstract Object getAutoRefKey(Reference ref); - - private synchronized void cleanup() { - if (this.keepstable >= this.GSTABLE) - return; - this.adapters.remove(null); // trick - Reference ref; - while ((ref = this.queue.poll()) != null) { - Object key = getAutoRefKey(ref); - switch(getAutoRefType(ref)) { - case JCLASS: - Class cl = (Class)key; - this.classes.remove(cl); - classesDec(cl.getName()); - break; - case LAZY_JCLASS: - this.lazyClasses.remove(key); - break; - case ADAPTER_CLASS: - this.adapterClasses.remove(key); - } - } - } - - - protected boolean queryCanonical(String name) { - cleanup(); - return super.queryCanonical(name); - } - - protected PyJavaClass getCanonical(Class c) { - cleanup(); - Reference ref = (Reference)classesGet(c); - if (ref == null) return null; - return (PyJavaClass)ref.get(); - } - - protected PyJavaClass getLazyCanonical(String name) { - cleanup(); - Reference ref = (Reference)this.lazyClasses.get(name); - if (ref == null) return null; - return (PyJavaClass)ref.get(); - } - - protected void putCanonical(Class c,PyJavaClass canonical) { - cleanup(); - classesPut(c,newAutoRef(JCLASS,c,canonical)); - } - - protected void putLazyCanonical(String name,PyJavaClass canonical) { - cleanup(); - this.lazyClasses.put(name,newAutoRef(LAZY_JCLASS,name,canonical)); - } - - protected Class getAdapterClass(Class c) { - cleanup(); - Reference ref = (Reference)this.adapterClasses.get(c); - if (ref == null) return null; - return (Class)ref.get(); - } - - protected void putAdapterClass(Class c,Class ac) { - cleanup(); - this.adapterClasses.put(c,newAutoRef(ADAPTER_CLASS,c,ac)); - } - - protected Object getAdapter(Object o,String evc) { - cleanup(); - return super.getAdapter(o,evc); - } - - protected void putAdapter(Object o,String evc,Object ad) { - cleanup(); - super.putAdapter(o,evc,ad); - } - - - public boolean _doesSomeAutoUnload() { return ... [truncated message content] |