001: package org.python.core;
002:
003: public class PyEnumerate extends PyIterator {
004:
005: private long en_index; /* current index of enumeration */
006: private PyObject en_sit; /* secondary iterator of enumeration */
007: private PyTuple en_result; /* result tuple */
008: protected static PyObject __methods__;
009:
010: //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
011: /* type info */
012:
013: public static final String exposed_name = "enumerate";
014:
015: public static final Class exposed_base = PyObject.class;
016:
017: public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
018: class exposed_next extends PyBuiltinMethodNarrow {
019:
020: exposed_next(PyObject self, PyBuiltinFunction.Info info) {
021: super (self, info);
022: }
023:
024: public PyBuiltinFunction bind(PyObject self) {
025: return new exposed_next(self, info);
026: }
027:
028: public PyObject __call__() {
029: return ((PyEnumerate) self).enumerate_next();
030: }
031:
032: }
033: dict.__setitem__("next", new PyMethodDescr("next",
034: PyEnumerate.class, 0, 0, new exposed_next(null, null)));
035: class exposed___iter__ extends PyBuiltinMethodNarrow {
036:
037: exposed___iter__(PyObject self, PyBuiltinFunction.Info info) {
038: super (self, info);
039: }
040:
041: public PyBuiltinFunction bind(PyObject self) {
042: return new exposed___iter__(self, info);
043: }
044:
045: public PyObject __call__() {
046: return ((PyEnumerate) self).enumerate___iter__();
047: }
048:
049: }
050: dict.__setitem__("__iter__", new PyMethodDescr("__iter__",
051: PyEnumerate.class, 0, 0, new exposed___iter__(null,
052: null)));
053: dict.__setitem__("__new__", new PyNewWrapper(PyEnumerate.class,
054: "__new__", -1, -1) {
055:
056: public PyObject new_impl(boolean init, PyType subtype,
057: PyObject[] args, String[] keywords) {
058: return enumerate_new(this , init, subtype, args,
059: keywords);
060: }
061:
062: });
063: }
064:
065: //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
066:
067: public PyObject enumerate_next() {
068: return next();
069: }
070:
071: public PyObject enumerate___iter__() {
072: return __iter__();
073: }
074:
075: public static PyEnumerate enumerate_new(PyObject new_,
076: boolean init, PyType subtype, PyObject[] args,
077: String[] keywords) {
078: if (args.length != 1) {
079: throw PyBuiltinFunction.DefaultInfo.unexpectedCall(
080: args.length, false, exposed_name, 0, 1);
081: }
082: return new PyEnumerate(args[0]);
083: }
084:
085: public PyEnumerate(PyObject seq) {
086: en_index = 0;
087: en_sit = seq.__iter__();
088: }
089:
090: public PyObject __iternext__() {
091: PyObject next_item;
092: PyObject next_index;
093:
094: next_item = en_sit.__iternext__();
095: if (next_item == null) {
096: if (en_sit instanceof PyIterator
097: && ((PyIterator) en_sit).stopException != null) {
098: stopException = ((PyIterator) en_sit).stopException;
099: }
100: return null;
101: }
102: next_index = new PyInteger((int) en_index);
103: en_index++;
104:
105: en_result = new PyTuple(
106: new PyObject[] { next_index, next_item });
107: return en_result;
108: }
109: }
|