01: package org.python.core;
02:
03: public class PyCallIter extends PyIterator {
04: private PyObject callable;
05: private PyObject sentinel;
06: private int idx;
07:
08: public PyCallIter(PyObject callable, PyObject sentinel) {
09: if (!__builtin__.callable(callable)) {
10: throw Py.TypeError("iter(v, w): v must be callable");
11: }
12: this .callable = callable;
13: this .sentinel = sentinel;
14: }
15:
16: public PyObject __iternext__() {
17: PyObject val = null;
18: try {
19: val = callable.__call__();
20: } catch (PyException exc) {
21: if (Py.matchException(exc, Py.StopIteration)) {
22: stopException = exc;
23: return null;
24: }
25: throw exc;
26: }
27: if (val._eq(sentinel).__nonzero__())
28: return null;
29: return val;
30: }
31:
32: }
|