1 package org.python.core; 2 3 public class PyEnumerate extends PyIterator { 4 5 private long en_index; 6 private PyObject en_sit; 7 private PyTuple en_result; 8 protected static PyObject __methods__; 9 10 11 12 public static final String exposed_name="enumerate"; 13 14 public static final Class exposed_base=PyObject.class; 15 16 public static void typeSetup(PyObject dict,PyType.Newstyle marker) { 17 class exposed_next extends PyBuiltinFunctionNarrow { 18 19 private PyEnumerate self; 20 21 public PyObject getSelf() { 22 return self; 23 } 24 25 exposed_next(PyEnumerate self,PyBuiltinFunction.Info info) { 26 super(info); 27 this.self=self; 28 } 29 30 public PyBuiltinFunction makeBound(PyObject self) { 31 return new exposed_next((PyEnumerate)self,info); 32 } 33 34 public PyObject __call__() { 35 return self.enumerate_next(); 36 } 37 38 public PyObject inst_call(PyObject gself) { 39 PyEnumerate self=(PyEnumerate)gself; 40 return self.enumerate_next(); 41 } 42 43 } 44 dict.__setitem__("next",new PyMethodDescr("next",PyEnumerate.class,0,0,new exposed_next(null,null))); 45 class exposed___iter__ extends PyBuiltinFunctionNarrow { 46 47 private PyEnumerate self; 48 49 public PyObject getSelf() { 50 return self; 51 } 52 53 exposed___iter__(PyEnumerate self,PyBuiltinFunction.Info info) { 54 super(info); 55 this.self=self; 56 } 57 58 public PyBuiltinFunction makeBound(PyObject self) { 59 return new exposed___iter__((PyEnumerate)self,info); 60 } 61 62 public PyObject __call__() { 63 return self.enumerate___iter__(); 64 } 65 66 public PyObject inst_call(PyObject gself) { 67 PyEnumerate self=(PyEnumerate)gself; 68 return self.enumerate___iter__(); 69 } 70 71 } 72 dict.__setitem__("__iter__",new PyMethodDescr("__iter__",PyEnumerate.class,0,0,new exposed___iter__(null,null))); 73 dict.__setitem__("__new__",new PyNewWrapper(PyEnumerate.class,"__new__",-1,-1) { 74 public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String []keywords) { 75 return enumerate_new(this,init,subtype,args,keywords); 76 } 77 }); 78 } 79 80 public PyObject enumerate_next() { 81 return next(); 82 } 83 84 public PyObject enumerate___iter__() { 85 return __iter__(); 86 } 87 88 public static PyEnumerate enumerate_new(PyObject new_, boolean init, PyType subtype, 89 PyObject[] args, String [] keywords) { 90 if (args.length != 1) { 91 throw PyBuiltinFunction.DefaultInfo.unexpectedCall(args.length,false,exposed_name,0,1); 92 } 93 return new PyEnumerate(args[0]); 94 } 95 96 public PyEnumerate(PyObject seq) { 97 en_index = 0; 98 en_sit = seq.__iter__(); 99 } 100 101 public PyObject __iternext__() { 102 PyObject next_item; 103 PyObject next_index; 104 105 next_item = en_sit.__iternext__(); 106 if(next_item == null) 107 return null; 108 next_index = new PyInteger((int)en_index); 109 en_index++; 110 111 en_result = new PyTuple(new PyObject[] {next_index, next_item}); 112 return en_result; 113 } 114 } 115 | Popular Tags |