Update of /cvsroot/jython/jython/org/python/core
In directory usw-pr-cvs1:/tmp/cvs-serv9354
Modified Files:
__builtin__.java
Log Message:
Made zip() use the __iter__ protocol.
Index: __builtin__.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/__builtin__.java,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -d -r2.44 -r2.45
*** __builtin__.java 26 May 2002 20:47:20 -0000 2.44
--- __builtin__.java 26 May 2002 20:51:46 -0000 2.45
***************
*** 921,937 ****
// Type check the arguments; they must be sequences. Might as well
! // cache the __getitem__() methods.
! PyObject[] getitems = new PyObject[itemsize];
for (int j=0; j < itemsize; j++) {
! PyObject getitem = argstar[j].__findattr__("__getitem__");
! if (getitem == null) {
! // Get the same error as CPython for instances. This
! // should throw an AttributeError.
! if (argstar[j] instanceof PyInstance)
! argstar[j].__getattr__("__getitem__");
! throw Py.TypeError("unindexable object");
}
! getitems[j] = getitem;
}
--- 921,934 ----
// Type check the arguments; they must be sequences. Might as well
! // cache the __iter__() methods.
! PyObject[] iters = new PyObject[itemsize];
for (int j=0; j < itemsize; j++) {
! PyObject iter = argstar[j].__iter__();
! if (iter == null) {
! throw Py.TypeError("zip argument #" + (j + 1) +
! " must support iteration");
}
! iters[j] = iter;
}
***************
*** 945,955 ****
for (int j=0; j < itemsize; j++) {
try {
! item = getitems[j].__call__(index);
}
catch (PyException e) {
! if (Py.matchException(e, Py.IndexError))
return ret;
throw e;
}
next[j] = item;
}
--- 942,954 ----
for (int j=0; j < itemsize; j++) {
try {
! item = iters[j].__iternext__();
}
catch (PyException e) {
! if (Py.matchException(e, Py.StopIteration))
return ret;
throw e;
}
+ if (item == null)
+ return null;
next[j] = item;
}
|