Index: org/python/core/PyEnumerate.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyEnumerate.java,v retrieving revision 2.2 diff -u -r2.2 PyEnumerate.java --- org/python/core/PyEnumerate.java 23 Feb 2005 04:26:21 -0000 2.2 +++ org/python/core/PyEnumerate.java 25 May 2005 09:21:20 -0000 @@ -6,19 +6,100 @@ private PyObject en_sit; /* secondary iterator of enumeration */ private PyTuple en_result; /* result tuple */ protected static PyObject __methods__; + + /* type info */ - static { - PyList list = new PyList(); - String[] methods = {"next"}; - list.append(new PyString(methods[0])); - __methods__ = list; + public static final String exposed_name="enumerate"; + + public static final Class exposed_base=PyObject.class; + + public static void typeSetup(PyObject dict,PyType.Newstyle marker) { + class exposed_next extends PyBuiltinFunctionNarrow { + + private PyEnumerate self; + + public PyObject getSelf() { + return self; + } + + exposed_next(PyEnumerate self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed_next((PyEnumerate)self,info); + } + + public PyObject __call__() { + return self.enumerate_next(); + } + + public PyObject inst_call(PyObject gself) { + PyEnumerate self=(PyEnumerate)gself; + return self.enumerate_next(); + } + + } + dict.__setitem__("next",new PyMethodDescr("next",PyEnumerate.class,0,0,new exposed_next(null,null))); + class exposed___iter__ extends PyBuiltinFunctionNarrow { + + private PyEnumerate self; + + public PyObject getSelf() { + return self; + } + + exposed___iter__(PyEnumerate self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___iter__((PyEnumerate)self,info); + } + + public PyObject __call__() { + return self.enumerate___iter__(); + } + + public PyObject inst_call(PyObject gself) { + PyEnumerate self=(PyEnumerate)gself; + return self.enumerate___iter__(); + } + + } + dict.__setitem__("__iter__",new PyMethodDescr("__iter__",PyEnumerate.class,0,0,new exposed___iter__(null,null))); + dict.__setitem__("__new__",new PyNewWrapper(PyEnumerate.class,"__new__",-1,-1) { + + public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { + return enumerate_new(this,init,subtype,args,keywords); + } + + }); + } + + public PyObject enumerate_next() { + return next(); + } + + public PyObject enumerate___iter__() { + return __iter__(); } + public static PyEnumerate enumerate_new(PyObject new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + if (args.length != 1) { + throw PyBuiltinFunction.DefaultInfo.unexpectedCall(args.length,false,exposed_name,0,1); + } + return new PyEnumerate(args[0]); + } + public PyEnumerate(PyObject seq) { en_index = 0; en_sit = seq.__iter__(); } - + public PyObject __iternext__() { PyObject next_item; PyObject next_index; @@ -32,15 +113,4 @@ en_result = new PyTuple(new PyObject[] {next_index, next_item}); return en_result; } - - public PyObject __findattr__(String name) { - if (name.equals("__methods__")) { - return __methods__; - } - return super.__findattr__(name); - } - - public String toString() { - return ""; - } }