01: // Copyright 2000 Finn Bock
02:
03: package org.python.core;
04:
05: /**
06: * An abstract helper class usefull when implementing an iterator object. This
07: * implementation supply a correct __iter__() and a next() method based on the
08: * __iternext__() implementation. The __iternext__() method must be supplied by
09: * the subclass.
10: *
11: * If the implementation raises a StopIteration exception, it should be stored
12: * in stopException so the correct exception can be thrown to preserve the line
13: * numbers in the traceback.
14: */
15: public abstract class PyIterator extends PyObject {
16: public PyObject __iter__() {
17: return this ;
18: }
19:
20: public static PyString __doc__next = new PyString(
21: "x.next() -> the next value, or raise StopIteration");
22:
23: public PyObject next() {
24: PyObject ret = __iternext__();
25: if (ret == null) {
26: if (stopException != null) {
27: PyException toThrow = stopException;
28: stopException = null;
29: throw toThrow;
30: }
31: throw Py.StopIteration("");
32: }
33: return ret;
34: }
35:
36: public abstract PyObject __iternext__();
37:
38: protected PyException stopException;
39: }
|