From: <fwi...@us...> - 2006-05-28 03:58:58
|
Revision: 2769 Author: fwierzbicki Date: 2006-05-27 20:58:51 -0700 (Sat, 27 May 2006) ViewCVS: http://svn.sourceforge.net/jython/?rev=2769&view=rev Log Message: ----------- pickling support for complex, list, and timetuple. Also some cleanup of list internals. Modified Paths: -------------- trunk/jython/src/org/python/core/PyComplex.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyObjectList.java trunk/jython/src/org/python/core/PySequenceList.java trunk/jython/src/org/python/modules/time/PyTimeTuple.java Modified: trunk/jython/src/org/python/core/PyComplex.java =================================================================== --- trunk/jython/src/org/python/core/PyComplex.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/core/PyComplex.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -869,6 +869,34 @@ } dict.__setitem__("__nonzero__",new PyMethodDescr("__nonzero__",PyComplex.class,0,0,new exposed___nonzero__(null,null))); + class exposed___reduce__ extends PyBuiltinFunctionNarrow { + + private PyComplex self; + + public PyObject getSelf() { + return self; + } + + exposed___reduce__(PyComplex self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___reduce__((PyComplex)self,info); + } + + public PyObject __call__() { + return self.complex___reduce__(); + } + + public PyObject inst_call(PyObject gself) { + PyComplex self=(PyComplex)gself; + return self.complex___reduce__(); + } + + } + dict.__setitem__("__reduce__",new PyMethodDescr("__reduce__",PyComplex.class,0,0,new exposed___reduce__(null,null))); class exposed___repr__ extends PyBuiltinFunctionNarrow { private PyComplex self; @@ -1595,6 +1623,24 @@ return new PyComplex(real, -imag); } + /** + * Used for pickling. + * + * @return a tuple of (class, (Integer)) + */ + public PyObject __reduce__() { + return complex___reduce__(); + } + + final PyObject complex___reduce__() { + return new PyTuple(new PyObject[]{ + getType(), + new PyTuple(new PyObject[]{ + getReal(), getImag() + }) + }); + } + public boolean isMappingType() { return false; } public boolean isSequenceType() { return false; } } Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/core/PyList.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -892,6 +892,34 @@ } dict.__setitem__("__imul__",new PyMethodDescr("__imul__",PyList.class,1,1,new exposed___imul__(null,null))); + class exposed___reduce__ extends PyBuiltinFunctionNarrow { + + private PyList self; + + public PyObject getSelf() { + return self; + } + + exposed___reduce__(PyList self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___reduce__((PyList)self,info); + } + + public PyObject __call__() { + return self.list___reduce__(); + } + + public PyObject inst_call(PyObject gself) { + PyList self=(PyList)gself; + return self.list___reduce__(); + } + + } + dict.__setitem__("__reduce__",new PyMethodDescr("__reduce__",PyList.class,0,0,new exposed___reduce__(null,null))); class exposed___mul__ extends PyBuiltinFunctionNarrow { private PyList self; @@ -1060,31 +1088,37 @@ } //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py + private static final PyType LISTTYPE = PyType.fromClass(PyList.class); + public PyList() { - this(Py.EmptyObjects); + this(LISTTYPE, Py.EmptyObjects); } public PyList(PyType type) { super(type); } - public PyList(Collection c) { - super(c); + public PyList(PyType type, PyObject[] elements) { + super(type, elements); } + public PyList(PyType type, Collection c) { + super(type, c); + } + // TODO: fix dependency so it can be removed. // Shouldn't be required (see PyList(Collection c), but test_re.py fails // without it. Probably used by reflection. public PyList(Vector v) { - super(v); + super(LISTTYPE, v); } public PyList(PyObject[] elements) { - super(elements); + this(LISTTYPE, elements); } public PyList(PyObject o) { - this(); + this(LISTTYPE); PyObject iter = o.__iter__(); for (PyObject item = null; (item = iter.__iternext__()) != null; ) { append(item); @@ -1676,4 +1710,26 @@ final int list_hashCode() { throw Py.TypeError("unhashable type"); } + + /** + * Used for pickling. + * + * @return a tuple of (class, tuple) + */ + public PyObject __reduce__() { + return list___reduce__(); + } + + final PyObject list___reduce__() { + PyTuple newargs = __getnewargs__(); + return new PyTuple(new PyObject[]{ + getType(), newargs + }); + } + + public PyTuple __getnewargs__() { + return new PyTuple(new PyObject[] + {new PyTuple(list.getArray())} + ); + } } Modified: trunk/jython/src/org/python/core/PyListDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyListDerived.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/core/PyListDerived.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -41,18 +41,6 @@ return super.__repr__(); } - public PyUnicode __unicode__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__unicode__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyUnicode) - return(PyUnicode)res; - throw Py.TypeError("__unicode__"+" should return a "+"unicode"); - } - return super.__unicode__(); - } - public PyString __hex__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hex__"); @@ -157,6 +145,14 @@ return super.__invert__(); } + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + public PyObject __add__(PyObject other) { PyType self_type=getType(); PyObject impl=self_type.lookup("__add__"); @@ -695,6 +691,20 @@ return super.hashCode(); } + public PyUnicode __unicode__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__unicode__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyUnicode) + return(PyUnicode)res; + if (res instanceof PyString) + return new PyUnicode((PyString)res); + throw Py.TypeError("__unicode__"+" should return a "+"unicode"); + } + return super.__unicode__(); + } + public int __cmp__(PyObject other) { PyType self_type=getType(); PyObject impl=self_type.lookup("__cmp__"); @@ -768,7 +778,7 @@ public PyObject __finditem__(PyObject key) { // ??? PyType self_type=getType(); - PyObject impl=self_type.lookup("__finditem__"); + PyObject impl=self_type.lookup("__getitem__"); if (impl!=null) try { return impl.__get__(this,self_type).__call__(key); @@ -793,7 +803,7 @@ public PyObject __getitem__(PyObject key) { // ??? PyType self_type=getType(); PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) + if (impl!=null) { try { return impl.__get__(this,self_type).__call__(key); } catch (PyException exc) { @@ -801,10 +811,11 @@ return null; throw exc; } + } return super.__getitem__(key); } - public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) Modified: trunk/jython/src/org/python/core/PyObjectList.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectList.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/core/PyObjectList.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -175,7 +175,7 @@ * * @return backing array object */ - PyObject[] getArray() { + protected PyObject[] getArray() { return (PyObject[])array.getArray(); } Modified: trunk/jython/src/org/python/core/PySequenceList.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceList.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/core/PySequenceList.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -47,7 +47,8 @@ list = new PyObjectList(elements); } - public PySequenceList(Collection c) { + public PySequenceList(PyType type, Collection c) { + super(type); list = new PyObjectList(c); } Modified: trunk/jython/src/org/python/modules/time/PyTimeTuple.java =================================================================== --- trunk/jython/src/org/python/modules/time/PyTimeTuple.java 2006-05-27 03:58:08 UTC (rev 2768) +++ trunk/jython/src/org/python/modules/time/PyTimeTuple.java 2006-05-28 03:58:51 UTC (rev 2769) @@ -1,7 +1,12 @@ package org.python.modules.time; import org.python.core.Py; +import org.python.core.PyBuiltinFunction; +import org.python.core.PyBuiltinFunctionNarrow; +import org.python.core.PyGetSetDescr; import org.python.core.PyInteger; +import org.python.core.PyList; +import org.python.core.PyMethodDescr; import org.python.core.PyObject; import org.python.core.PyTuple; import org.python.core.PyType; @@ -17,6 +22,7 @@ private PyInteger tm_yday; private PyInteger tm_isdst; + //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py /* type info */ public static final String exposed_name="timetuple"; @@ -24,8 +30,113 @@ public static final Class exposed_base=PyTuple.class; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - PyTimeTupleSetup.typeSetup(dict, marker); + dict.__setitem__("tm_year",new PyGetSetDescr("tm_year",PyTimeTuple.class,"getYear",null)); + dict.__setitem__("tm_mon",new PyGetSetDescr("tm_mon",PyTimeTuple.class,"getMon",null)); + dict.__setitem__("tm_mday",new PyGetSetDescr("tm_mday",PyTimeTuple.class,"getMday",null)); + dict.__setitem__("tm_hour",new PyGetSetDescr("tm_hour",PyTimeTuple.class,"getHour",null)); + dict.__setitem__("tm_min",new PyGetSetDescr("tm_min",PyTimeTuple.class,"getMin",null)); + dict.__setitem__("tm_sec",new PyGetSetDescr("tm_sec",PyTimeTuple.class,"getSec",null)); + dict.__setitem__("tm_wday",new PyGetSetDescr("tm_wday",PyTimeTuple.class,"getWday",null)); + dict.__setitem__("tm_yday",new PyGetSetDescr("tm_yday",PyTimeTuple.class,"getYday",null)); + dict.__setitem__("tm_isdst",new PyGetSetDescr("tm_isdst",PyTimeTuple.class,"getIsdst",null)); + class exposed___ne__ extends PyBuiltinFunctionNarrow { + + private PyTimeTuple self; + + public PyObject getSelf() { + return self; + } + + exposed___ne__(PyTimeTuple self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___ne__((PyTimeTuple)self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=self.timetuple___ne__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + public PyObject inst_call(PyObject gself,PyObject arg0) { + PyTimeTuple self=(PyTimeTuple)gself; + PyObject ret=self.timetuple___ne__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ne__",new PyMethodDescr("__ne__",PyTimeTuple.class,1,1,new exposed___ne__(null,null))); + class exposed___eq__ extends PyBuiltinFunctionNarrow { + + private PyTimeTuple self; + + public PyObject getSelf() { + return self; + } + + exposed___eq__(PyTimeTuple self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___eq__((PyTimeTuple)self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=self.timetuple___eq__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + public PyObject inst_call(PyObject gself,PyObject arg0) { + PyTimeTuple self=(PyTimeTuple)gself; + PyObject ret=self.timetuple___eq__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyTimeTuple.class,1,1,new exposed___eq__(null,null))); + class exposed___reduce__ extends PyBuiltinFunctionNarrow { + + private PyTimeTuple self; + + public PyObject getSelf() { + return self; + } + + exposed___reduce__(PyTimeTuple self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___reduce__((PyTimeTuple)self,info); + } + + public PyObject __call__() { + return self.timetuple___reduce__(); + } + + public PyObject inst_call(PyObject gself) { + PyTimeTuple self=(PyTimeTuple)gself; + return self.timetuple___reduce__(); + } + + } + dict.__setitem__("__reduce__",new PyMethodDescr("__reduce__",PyTimeTuple.class,0,0,new exposed___reduce__(null,null))); } + //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py private static final PyType TIMETUPLETYPE = PyType.fromClass(PyTimeTuple.class); @@ -134,4 +245,26 @@ int i = cmp(this, tl, o, ol); return (i < 0) ? Py.Zero : Py.One; } + + /** + * Used for pickling. + * + * @return a tuple of (class, tuple) + */ + public PyObject __reduce__() { + return timetuple___reduce__(); + } + + final PyObject timetuple___reduce__() { + PyTuple newargs = __getnewargs__(); + return new PyTuple(new PyObject[]{ + getType(), newargs + }); + } + + public PyTuple __getnewargs__() { + return new PyTuple(new PyObject[] + {new PyList(getArray())} + ); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |