From: <cg...@us...> - 2007-04-26 07:40:46
|
Revision: 3190 http://svn.sourceforge.net/jython/?rev=3190&view=rev Author: cgroves Date: 2007-04-26 00:40:44 -0700 (Thu, 26 Apr 2007) Log Message: ----------- Apply patch #1707681 from crotwell. Attempt to use anything that has an iterate method returning an Iterator int __iter__. Modified Paths: -------------- trunk/jython/src/org/python/core/CollectionIter.java trunk/jython/src/org/python/core/CollectionIter2.java Modified: trunk/jython/src/org/python/core/CollectionIter.java =================================================================== --- trunk/jython/src/org/python/core/CollectionIter.java 2007-04-25 06:02:10 UTC (rev 3189) +++ trunk/jython/src/org/python/core/CollectionIter.java 2007-04-26 07:40:44 UTC (rev 3190) @@ -2,7 +2,9 @@ package org.python.core; -import java.util.*; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Vector; class CollectionIter extends PyObject { PyObject findCollection(Object object) { Modified: trunk/jython/src/org/python/core/CollectionIter2.java =================================================================== --- trunk/jython/src/org/python/core/CollectionIter2.java 2007-04-25 06:02:10 UTC (rev 3189) +++ trunk/jython/src/org/python/core/CollectionIter2.java 2007-04-26 07:40:44 UTC (rev 3190) @@ -2,7 +2,10 @@ package org.python.core; -import java.util.*; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; class CollectionIter2 extends CollectionIter { CollectionIter2() throws Exception { @@ -19,7 +22,18 @@ if (object instanceof Iterator) { return new IteratorIter(((Iterator) object)); } - + try { + // TODO - Once we depend on Java 5 we can replace this with a check + // for the Iterable interface + Method m = object.getClass().getMethod("iterator", new Class[0]); + if (Iterator.class.isAssignableFrom(m.getReturnType())) { + return new IteratorIter((Iterator) m.invoke(object, + new Object[0])); + } + } catch (Exception e) { + // Looks like one of the many reflection based exceptions ocurred so + // we won't get an Iterator this way + } return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |