From: <zy...@us...> - 2009-04-11 03:57:04
|
Revision: 6215 http://jython.svn.sourceforge.net/jython/?rev=6215&view=rev Author: zyasoft Date: 2009-04-11 03:57:01 +0000 (Sat, 11 Apr 2009) Log Message: ----------- Added PyNewTuple, to soon replace PyTuple too Modified Paths: -------------- branches/newlist/CoreExposed.includes branches/newlist/src/org/python/core/PyList.java branches/newlist/src/templates/mappings Added Paths: ----------- branches/newlist/Lib/test/test_newtuple.py branches/newlist/src/org/python/core/PyNewTuple.java branches/newlist/src/org/python/core/PyNewTupleDerived.java branches/newlist/src/templates/newtuple.derived Modified: branches/newlist/CoreExposed.includes =================================================================== --- branches/newlist/CoreExposed.includes 2009-04-11 01:11:10 UTC (rev 6214) +++ branches/newlist/CoreExposed.includes 2009-04-11 03:57:01 UTC (rev 6215) @@ -28,6 +28,7 @@ org/python/core/PyMethodDescr.class org/python/core/PyModule.class org/python/core/PyNewList.class +org/python/core/PyNewTuple.class org/python/core/PyNone.class org/python/core/PyObject.class org/python/core/PyProperty.class Added: branches/newlist/Lib/test/test_newtuple.py =================================================================== --- branches/newlist/Lib/test/test_newtuple.py (rev 0) +++ branches/newlist/Lib/test/test_newtuple.py 2009-04-11 03:57:01 UTC (rev 6215) @@ -0,0 +1,12 @@ +import unittest +from test import test_support, seq_tests +from org.python.core import PyNewTuple as newtuple + +class TupleTest(seq_tests.CommonTest): + type2test = newtuple + +def test_main(): + test_support.run_unittest(TupleTest) + +if __name__=="__main__": + test_main() Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-11 01:11:10 UTC (rev 6214) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-11 03:57:01 UTC (rev 6215) @@ -70,7 +70,7 @@ } } - public PyList fromList(List list) { + public static PyList fromList(List list) { return new PyList(list, false); } @@ -461,9 +461,8 @@ @ExposedMethod(doc = BuiltinDocs.list_count_doc) final int list_count(PyObject o) { int count = 0; - PyObject[] array = getArray(); - for (int i = 0, n = size(); i < n; i++) { - if (array[i].equals(o)) { + for (PyObject item : list) { + if (item.equals(o)) { count++; } } @@ -511,11 +510,12 @@ // Follow Python 2.3+ behavior int validStop = boundToSequence(stop); int validStart = boundToSequence(start); - PyObject[] array = getArray(); - for (int i = validStart; i < validStop && i < size(); i++) { - if (array[i].equals(o)) { + int i = 0; + for (PyObject item : list.subList(validStart, validStop)) { + if (item.equals(o)) { return i; } + i++; } throw Py.ValueError(message); } Added: branches/newlist/src/org/python/core/PyNewTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyNewTuple.java (rev 0) +++ branches/newlist/src/org/python/core/PyNewTuple.java 2009-04-11 03:57:01 UTC (rev 6215) @@ -0,0 +1,515 @@ +// Copyright (c) Corporation for National Research Initiatives +package org.python.core; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; +import org.python.expose.MethodType; + +/** + * A builtin python tuple. + */ + +@ExposedType(name = "newtuple", base = PyObject.class) +public class PyNewTuple extends PySequenceList implements List { + public static final PyType TYPE = PyType.fromClass(PyNewTuple.class); + + private final PyObject[] array; + private final List<PyObject> list; + private static final PyNewTuple EMPTY_TUPLE = new PyNewTuple(); + + public PyNewTuple() { + this(TYPE, Py.EmptyObjects); + } + + public PyNewTuple(PyObject... elements) { + this(TYPE, elements); + } + + public PyNewTuple(Collection<PyObject> collection) { + this(TYPE, collection); + } + + public PyNewTuple(PyType subtype, PyObject[] elements) { + super(subtype); +// System.err.println("Initializing from " + Arrays.toString(elements)); + if (elements == null) { + array = new PyObject[0]; + list = Collections.emptyList(); + } else { + array = new PyObject[elements.length]; + System.arraycopy(elements, 0, array, 0, elements.length); + list = Collections.unmodifiableList(Arrays.asList(array)); + } + } + + public PyNewTuple(PyObject[] elements, boolean copy) { + this(TYPE, elements, copy); + } + + public PyNewTuple(PyType subtype, PyObject[] elements, boolean copy) { + super(subtype); + + if (copy) { + array = new PyObject[elements.length]; + System.arraycopy(elements, 0, array, 0, elements.length); + } else { + array = elements; + } + list = Collections.unmodifiableList(Arrays.asList(array)); + } + + public PyNewTuple(PyType subtype, Collection<PyObject> elements) { + super(subtype); + if (elements == null) { + array = new PyObject[0]; + list = Collections.emptyList(); + } else { + array = new PyObject[elements.size()]; + elements.toArray(array); + list = Collections.unmodifiableList(Arrays.asList(array)); + } + } + + private static PyNewTuple fromArrayNoCopy(PyObject[] elements) { +// System.err.println("newtuple (no copy):" + Arrays.toString(elements)); + return new PyNewTuple(elements, false); + } + + @ExposedNew + final static PyObject newtuple_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { +// System.err.println("newtuple_new"); + ArgParser ap = new ArgParser("newtuple", args, keywords, new String[] { "sequence" }, 0); + PyObject S = ap.getPyObject(0, null); +// System.err.println("newtuple: new_=" + new_ + ",S=" + S); + if (new_.for_type == subtype) { + if (S == null) { + return EMPTY_TUPLE; + } + if (S instanceof PyNewTupleDerived) { + return new PyNewTuple(((PyNewTuple)S).getArray()); + } + if (S instanceof PyNewTuple) { + return S; + } + return fromArrayNoCopy(Py.make_array(S)); + } else { + if (S == null) { + return new PyNewTupleDerived(subtype, Py.EmptyObjects); + } + return new PyNewTupleDerived(subtype, Py.make_array(S)); + } + } + + /** + * Return a new PyNewTuple from an iterable. + * + * Raises a TypeError if the object is not iterable. + * + * @param iterable an iterable PyObject + * @return a PyNewTuple containing each item in the iterable + */ + public static PyNewTuple fromIterable(PyObject iterable) { + return fromArrayNoCopy(Py.make_array(iterable)); + } + + + + protected PyObject getslice(int start, int stop, int step) { + if (step > 0 && stop < start) + stop = start; + int n = sliceLength(start, stop, step); + PyObject[] newArray = new PyObject[n]; + PyObject[] array = getArray(); + + if (step == 1) { + System.arraycopy(array, start, newArray, 0, stop-start); + return fromArrayNoCopy(newArray); + } + int j = 0; + for (int i=start; j<n; i+=step) { + newArray[j] = array[i]; + j++; + } + return fromArrayNoCopy(newArray); + } + + protected PyObject repeat(int count) { + if (count < 0) { + count = 0; + } + int size = size(); + if (size == 0 || count == 1) { + if (getType() == TYPE) { + // Since tuples are immutable, we can return a shared copy in this case + return this; + } + if (size == 0) { + return EMPTY_TUPLE; + } + } + + int newSize = size * count; + if (newSize / size != count) { + throw Py.MemoryError(""); + } + + PyObject[] array = getArray(); + PyObject[] newArray = new PyObject[newSize]; + for (int i = 0; i < count; i++) { + System.arraycopy(array, 0, newArray, i * size, size); + } + return fromArrayNoCopy(newArray); + } + + public int __len__() { + return newtuple___len__(); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___len___doc) + final int newtuple___len__() { + return size(); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___contains___doc) + final boolean newtuple___contains__(PyObject o) { + return super.__contains__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ne___doc) + final PyObject newtuple___ne__(PyObject o) { + return super.__ne__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___eq___doc) + final PyObject newtuple___eq__(PyObject o) { + return super.__eq__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___gt___doc) + final PyObject newtuple___gt__(PyObject o) { + return super.__gt__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ge___doc) + final PyObject newtuple___ge__(PyObject o) { + return super.__ge__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___lt___doc) + final PyObject newtuple___lt__(PyObject o) { + return super.__lt__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___le___doc) + final PyObject newtuple___le__(PyObject o) { + return super.__le__(o); + } + + public PyObject __add__(PyObject generic_other) { + return newtuple___add__(generic_other); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___add___doc) + final PyObject newtuple___add__(PyObject generic_other) { + PyNewTuple sum = null; + if (generic_other instanceof PyNewTuple) { + PyNewTuple other = (PyNewTuple)generic_other; + PyObject[] newArray = new PyObject[array.length + other.array.length]; + System.arraycopy(array, 0, newArray, 0, array.length); + System.arraycopy(other.array, 0, newArray, array.length, other.array.length); + sum = fromArrayNoCopy(newArray); + } + return sum; + } + + @Override + public PyObject __mul__(PyObject o) { + return newtuple___mul__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___mul___doc) + final PyObject newtuple___mul__(PyObject o) { + if (!o.isIndex()) { + return null; + } + return repeat(o.asIndex(Py.OverflowError)); + } + + @Override + public PyObject __rmul__(PyObject o) { + return newtuple___rmul__(o); + } + + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___rmul___doc) + final PyObject newtuple___rmul__(PyObject o) { + if (!o.isIndex()) { + return null; + } + return repeat(o.asIndex(Py.OverflowError)); + } + + public PyObject __iter__() { + return newtuple___iter__(); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___iter___doc) + public PyObject newtuple___iter__() { + return new PyFastSequenceIter(this); + } + + @ExposedMethod(defaults = "null", doc = BuiltinDocs.tuple___getslice___doc) + final PyObject newtuple___getslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { + return seq___getslice__(s_start,s_stop,s_step); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___getitem___doc) + final PyObject newtuple___getitem__(PyObject index) { + PyObject ret = seq___finditem__(index); + if(ret == null) { + throw Py.IndexError("index out of range: " + index); + } + return ret; + } + + @ExposedMethod(doc = BuiltinDocs.tuple___getnewargs___doc) + final PyTuple newtuple___getnewargs__() { + return new PyTuple(new PyTuple(getArray())); + } + + public PyTuple __getnewargs__() { + return newtuple___getnewargs__(); + } + + public int hashCode() { + return newtuple___hash__(); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___hash___doc) + final int newtuple___hash__() { + // strengthened hash to avoid common collisions. from CPython + // tupleobject.tuplehash. See http://bugs.python.org/issue942952 + int y; + int len = size(); + int mult = 1000003; + int x = 0x345678; + PyObject[] array = getArray(); + while (--len >= 0) { + y = array[len].hashCode(); + x = (x ^ y) * mult; + mult += 82520 + len + len; + } + return x + 97531; + } + + private String subobjRepr(PyObject o) { + if (o == null) + return "null"; + return o.__repr__().toString(); + } + + public String toString() { + return newtuple___repr__(); + } + + @ExposedMethod(doc = BuiltinDocs.tuple___repr___doc) + final String newtuple___repr__() { + StringBuilder buf = new StringBuilder("("); + for (int i = 0; i < array.length-1; i++) { + buf.append(subobjRepr(array[i])); + buf.append(", "); + } + if (array.length > 0) + buf.append(subobjRepr(array[array.length-1])); + if (array.length == 1) + buf.append(","); + buf.append(")"); + return buf.toString(); + } + + public List subList(int fromIndex, int toIndex) { + return Collections.unmodifiableList(list.subList(fromIndex, toIndex)); + } + + // Make PyNewTuple immutable from the collections interfaces by overriding + // all the mutating methods to throw UnsupportedOperationException exception. + // This is how Collections.unmodifiableList() does it. + public Iterator iterator() { + return new Iterator() { + Iterator i = list.iterator(); + public void remove() { + throw new UnsupportedOperationException(); + } + public boolean hasNext() { + return i.hasNext(); + } + public Object next() { + return i.next(); + } + }; + } + + public boolean add(Object o){ + throw new UnsupportedOperationException(); + } + + public boolean remove(Object o) { + throw new UnsupportedOperationException(); + } + + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public Object set(int index, Object element) { + throw new UnsupportedOperationException(); + } + + public void add(int index, Object element) { + throw new UnsupportedOperationException(); + } + + public Object remove(int index) { + throw new UnsupportedOperationException(); + } + + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException(); + } + + public ListIterator listIterator() { + return listIterator(0); + } + + public ListIterator listIterator(final int index) { + return new ListIterator() { + ListIterator i = list.listIterator(index); + + public boolean hasNext() {return i.hasNext();} + public Object next() {return i.next();} + public boolean hasPrevious() {return i.hasPrevious();} + public Object previous() {return i.previous();} + public int nextIndex() {return i.nextIndex();} + public int previousIndex() {return i.previousIndex();} + + public void remove() { + throw new UnsupportedOperationException(); + } + + public void set(Object o) { + throw new UnsupportedOperationException(); + } + + public void add(Object o) { + throw new UnsupportedOperationException(); + } + }; + } + + protected String unsupportedopMessage(String op, PyObject o2) { + if (op.equals("+")) { + return "can only concatenate tuple (not \"{2}\") to tuple"; + } + return super.unsupportedopMessage(op, o2); + } + + public void pyset(int index, PyObject value) { + throw Py.TypeError("'tuple' object does not support item assignment"); + } + + @Override + public boolean contains(Object o) { + return list.contains(o); + } + + @Override + public boolean containsAll(Collection c) { + return list.containsAll(c); + } + + @Override + public boolean equals(Object o) { + return list.equals(o); + } + + @Override + public Object get(int index) { + return list.get(index); + } + + @Override + public PyObject[] getArray() { + return array; + } + + @Override + public int indexOf(Object o) { + return list.indexOf(o); + } + + @Override + public boolean isEmpty() { + return list.isEmpty(); + } + + @Override + public int lastIndexOf(Object o) { + return list.lastIndexOf(o); + } + + @Override + public void pyadd(int index, PyObject element) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean pyadd(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public PyObject pyget(int index) { + return array[index]; + } + + @Override + public void remove(int start, int stop) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int size() { + return array.length; + } + + @Override + public Object[] toArray() { + return list.toArray(); + } + + @Override + public Object[] toArray(Object[] a) { + return list.toArray(a); + } + +} Added: branches/newlist/src/org/python/core/PyNewTupleDerived.java =================================================================== --- branches/newlist/src/org/python/core/PyNewTupleDerived.java (rev 0) +++ branches/newlist/src/org/python/core/PyNewTupleDerived.java 2009-04-11 03:57:01 UTC (rev 6215) @@ -0,0 +1,1162 @@ +/* Generated file, do not modify. See jython/src/templates/gderived.py. */ +package org.python.core; + +import java.io.Serializable; + +public class PyNewTupleDerived extends PyNewTuple implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + private PyObject dict; + + public PyObject fastGetDict() { + return dict; + } + + public PyObject getDict() { + return dict; + } + + public void setDict(PyObject newDict) { + if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { + dict=newDict; + } else { + throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); + } + } + + public void delDict() { + // deleting an object's instance dict makes it grow a new one + dict=new PyStringMap(); + } + + public PyNewTupleDerived(PyType subtype,PyObject[]elements) { + super(subtype,elements); + slots=new PyObject[subtype.getNumSlots()]; + dict=subtype.instDict(); + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); + } + return super.__float__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + 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__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rshift__(other); + } + + public PyObject __rrshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rrshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rrshift__(other); + } + + public PyObject __and__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__and__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__and__(other); + } + + public PyObject __rand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rand__(other); + } + + public PyObject __or__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__or__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__or__(other); + } + + public PyObject __ror__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ror__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ror__(other); + } + + public PyObject __xor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__xor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__xor__(other); + } + + public PyObject __rxor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rxor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rxor__(other); + } + + public PyObject __lt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lt__(other); + } + + public PyObject __le__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__le__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__le__(other); + } + + public PyObject __gt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__gt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__gt__(other); + } + + public PyObject __ge__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ge__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ge__(other); + } + + public PyObject __eq__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__eq__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__eq__(other); + } + + public PyObject __ne__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ne__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ne__(other); + } + + public PyObject __iadd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iadd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iadd__(other); + } + + public PyObject __isub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__isub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__isub__(other); + } + + public PyObject __imul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imul__(other); + } + + public PyObject __idiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__idiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__idiv__(other); + } + + public PyObject __ifloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ifloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ifloordiv__(other); + } + + public PyObject __itruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__itruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__itruediv__(other); + } + + public PyObject __imod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imod__(other); + } + + public PyObject __ipow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ipow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ipow__(other); + } + + public PyObject __ilshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ilshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ilshift__(other); + } + + public PyObject __irshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__irshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__irshift__(other); + } + + public PyObject __iand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iand__(other); + } + + public PyObject __ior__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ior__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ior__(other); + } + + public PyObject __ixor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ixor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ixor__(other); + } + + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + + public PyObject __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong||res instanceof PyInteger) + return res; + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); + } + return super.__long__(); + } + + public int hashCode() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hash__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) { + return((PyInteger)res).getValue(); + } else + if (res instanceof PyLong) { + return((PyLong)res).getValue().intValue(); + } + throw Py.TypeError("__hash__ should return a int"); + } + if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { + throw Py.TypeError(String.format("unhashable type: '%.200s'",getType().fastGetName())); + } + 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(); + PyType[]where_type=new PyType[1]; + PyObject impl=self_type.lookup_where("__cmp__",where_type); + // Full Compatibility with CPython __cmp__: + // If the derived type don't override __cmp__, the + // *internal* super().__cmp__ should be called, not the + // exposed one. The difference is that the exposed __cmp__ + // throws a TypeError if the argument is an instance of the same type. + if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { + return super.__cmp__(other); + } + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) { + return-2; + } + int c=res.asInt(); + return c<0?-1:c>0?1:0; + } + + public boolean __nonzero__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__nonzero__"); + if (impl==null) { + impl=self_type.lookup("__len__"); + if (impl==null) + return super.__nonzero__(); + } + PyObject o=impl.__get__(this,self_type).__call__(); + Class c=o.getClass(); + if (c!=PyInteger.class&&c!=PyBoolean.class) { + throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",self_type.getName())); + } + return o.__nonzero__(); + } + + public boolean __contains__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__contains__"); + if (impl==null) + return super.__contains__(o); + return impl.__get__(this,self_type).__call__(o).__nonzero__(); + } + + public int __len__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__len__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) + return((PyInteger)res).getValue(); + throw Py.TypeError("__len__ should return a int"); + } + return super.__len__(); + } + + public PyObject __iter__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iter__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + impl=self_type.lookup("__getitem__"); + if (impl==null) + return super.__iter__(); + return new PySequenceIter(this); + } + + public PyObject __iternext__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("next"); + if (impl!=null) { + try { + return impl.__get__(this,self_type).__call__(); + } catch (PyException exc) { + if (Py.matchException(exc,Py.StopIteration)) + return null; + throw exc; + } + } + return super.__iternext__(); // ??? + } + + public PyObject __finditem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(key); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __getitem__(PyObject key) { + // Same as __finditem__, without swallowing LookupErrors. This allows + // __getitem__ implementations written in Python to raise custom + // exceptions (such as subclasses of KeyError). + // + // We are forced to duplicate the code, instead of defining __finditem__ + // in terms of __getitem__. That's because PyObject defines __getitem__ + // in terms of __finditem__. Therefore, we would end with an infinite + // loop when self_type.lookup("__getitem__") returns null: + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ + // + // By duplicating the (short) lookup and call code, we are safe, because + // the call chains will be: + // + // __finditem__ -> super.__finditem__ + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ + + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(key); + return super.__getitem__(key); + } + + public void __setitem__(PyObject key,PyObject value) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key,value); + return; + } + super.__setitem__(key,value); + } + + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); + } + return super.__getslice__(start,stop,step); + } + + public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); + return; + } + super.__setslice__(start,stop,step,value); + } + + public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); + return; + } + super.__delslice__(start,stop,step); + } + + public void __delitem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key); + return; + } + super.__delitem__(key); + } + + public PyObject __call__(PyObject args[],String keywords[]) { + ThreadState ts=Py.getThreadState(); + if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); + try { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__call__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(args,keywords); + return super.__call__(args,keywords); + } finally { + --ts.recursion_depth; + } + } + + public PyObject __findattr_ex__(String name) { + PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. + PyObject getattribute=self_type.lookup("__getattribute__"); + PyString py_name=null; + PyException firstAttributeError=null; + try { + if (getattribute!=null) { + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); + } else { + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation + } + } catch (PyException e) { + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. + } + } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; + } + + public void __setattr__(String name,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); + return; + } + super.__setattr__(name,value); + } + + public void __delattr__(String name) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); + return; + } + super.__delattr__(name); + } + + public PyObject __get__(PyObject obj,PyObject type) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__get__"); + if (impl!=null) { + if (obj==null) + obj=Py.None; + if (type==null) + type=Py.None; + return impl.__get__(this,self_type).__call__(obj,type); + } + return super.__get__(obj,type); + } + + public void __set__(PyObject obj,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__set__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj,value); + return; + } + super.__set__(obj,value); + } + + public void __delete__(PyObject obj) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delete__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj); + return; + } + super.__delete__(obj); + } + + public PyObject __pow__(PyObject other,PyObject modulo) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res; + if (modulo==null) { + res=impl.__get__(this,self_type).__call__(other); + } else { + res=impl.__get__(this,self_type).__call__(other,modulo); + } + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other,modulo); + } + + public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { + PyType self_type=getType(); + if (self_type.isSubType(type)) { + PyObject impl=self_type.lookup("__init__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(args,keywords); + if (res!=Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); + } + proxyInit(); + } + } + } + + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + + public Object __tojava__(Class c) { + // If we are not being asked by the "default" conversion to java, then + // we can provide this as the result, as long as it is a instance of the + // specified class. Without this, derived.__tojava__(PyObject.class) + // would broke. (And that's not pure speculation: PyReflectedFunction's + // ReflectedArgs asks for things like that). + if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { + return this; + } + // Otherwise, we call the derived __tojava__, if it exists: + PyType self_type=getType(); + PyObject impl=self_type.lookup("__tojava__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); + return super.__tojava__(c); + } + + public Object __coerce_ex__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__coerce__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(o); + if (res==Py.NotImplemented) + return Py.None; + if (!(res instanceof PyTuple)) + throw Py.TypeError("__coerce__ didn't return a 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + +} Modified: branches/newlist/src/templates/mappings =================================================================== --- branches/newlist/src/templates/mappings 2009-04-11 01:11:10 UTC (rev 6214) +++ branches/newlist/src/templates/mappings 2009-04-11 03:57:01 UTC (rev 6215) @@ -26,6 +26,7 @@ local.derived:org.python.modules.thread.PyLocalDerived module.derived:org.python.core.PyModuleDerived newlist.derived:org.python.core.PyNewListDerived +newtuple.derived:org.python.core.PyNewTupleDerived object.derived:org.python.core.PyObjectDerived partial.derived:org.python.... [truncated message content] |