From: <le...@us...> - 2008-08-10 20:51:16
|
Revision: 5133 http://jython.svn.sourceforge.net/jython/?rev=5133&view=rev Author: leosoto Date: 2008-08-10 20:50:55 +0000 (Sun, 10 Aug 2008) Log Message: ----------- Added coercion to the cmp() algorithm, which is also used for comparison operators in the absence of rich cmp methods (See #1031). In the process, __coerce_ex__ was added to deriveds, and a slight refactor was made on types exposing __coerce__ to avoid using the __coerce_ex__ virtual method on the exposed methods code. Fixes test_coercion. Modified Paths: -------------- branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBaseExceptionDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplex.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloat.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyInteger.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLong.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObject.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_csv/PyDialectDerived.java branches/asm/src/org/python/modules/_functools/PyPartialDerived.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java branches/asm/src/templates/object.derived Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1087,6 +1087,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyComplex.java =================================================================== --- branches/asm/src/org/python/core/PyComplex.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyComplex.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -266,12 +266,20 @@ return unsupported_comparison(other); } + public Object __coerce_ex__(PyObject other) { + return complex___coerce_ex__(other); + } + @ExposedMethod final PyObject complex___coerce__(PyObject other) { - return __coerce__(other); + return adaptToCoerceTuple(complex___coerce_ex__(other)); } - public Object __coerce_ex__(PyObject other) { + /** + * Coercion logic for complex. Implemented as a final method to avoid + * invocation of virtual methods from the exposed coerce. + */ + final PyObject complex___coerce_ex__(PyObject other) { if (other instanceof PyComplex) return other; if (other instanceof PyFloat) Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyFloat.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -201,6 +201,19 @@ } public Object __coerce_ex__(PyObject other) { + return float___coerce_ex__(other); + } + + @ExposedMethod + final PyObject float___coerce__(PyObject other) { + return adaptToCoerceTuple(float___coerce_ex__(other)); + } + + /** + * Coercion logic for float. Implemented as a final method to avoid + * invocation of virtual methods from the exposed coerce. + */ + final Object float___coerce_ex__(PyObject other) { if (other instanceof PyFloat) return other; else { @@ -211,6 +224,7 @@ else return Py.None; } + } private static final boolean canCoerce(PyObject other) { @@ -504,11 +518,6 @@ } } - @ExposedMethod - final PyObject float___coerce__(PyObject other) { - return __coerce__(other); - } - public PyObject __neg__() { return float___neg__(); } Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyInteger.java =================================================================== --- branches/asm/src/org/python/core/PyInteger.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyInteger.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -164,6 +164,19 @@ } public Object __coerce_ex__(PyObject other) { + return int___coerce_ex__(other); + } + + @ExposedMethod + final PyObject int___coerce__(PyObject other) { + return adaptToCoerceTuple(int___coerce_ex__(other)); + } + + /** + * Coercion logic for int. Implemented as a final method to avoid + * invocation of virtual methods from the exposed coerced. + */ + final Object int___coerce_ex__(PyObject other) { if (other instanceof PyInteger) return other; else @@ -689,14 +702,9 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject int___ror__(PyObject left){ - return int___or__(left); + return int___or__(left); } - @ExposedMethod - final PyObject int___coerce__(PyObject other) { - return __coerce__(other); - } - public PyObject __neg__() { return int___neg__(); } Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyLong.java =================================================================== --- branches/asm/src/org/python/core/PyLong.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyLong.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -256,6 +256,19 @@ } public Object __coerce_ex__(PyObject other) { + return long___coerce_ex__(other); + } + + @ExposedMethod + final PyObject long___coerce__(PyObject other) { + return adaptToCoerceTuple(long___coerce_ex__(other)); + } + + /** + * Coercion logic for long. Implemented as a final method to avoid + * invocation of virtual methods from the exposed coerce. + */ + final Object long___coerce_ex__(PyObject other) { if (other instanceof PyLong) return other; else @@ -710,11 +723,6 @@ return Py.newLong(coerce(left).or(value)); } - @ExposedMethod - final PyObject long___coerce__(PyObject other) { - return __coerce__(other); - } - public PyObject __neg__() { return long___neg__(); } Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1087,6 +1087,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyObject.java =================================================================== --- branches/asm/src/org/python/core/PyObject.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyObject.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -980,10 +980,14 @@ * * This method can not be overridden. * To implement __coerce__ functionality, override __coerce_ex__ instead. + * + * Also, <b>do not</b> call this method from exposed 'coerce' methods. + * Instead, Use adaptToCoerceTuple over the result of the overriden + * __coerce_ex__. * * @param pyo the other object involved in the coercion. * @return a tuple of this object and pyo coerced to the same type - * or Py.None if no coercion is possible. + * or Py.NotImplemented if no coercion is possible. * @see org.python.core.PyObject#__coerce_ex__(org.python.core.PyObject) **/ public final PyObject __coerce__(PyObject pyo) { @@ -991,6 +995,21 @@ if (o == null) { throw Py.AttributeError("__coerce__"); } + return adaptToCoerceTuple(o); + } + + /** + * Adapts the result of __coerce_ex__ to a tuple of two elements, with the + * resulting coerced values, or to Py.NotImplemented, if o is Py.None. + * + * This is safe to be used from subclasses exposing '__coerce__' + * (as opposed to {@link #__coerce__(PyObject)}, which calls the virtual + * method {@link #__coerce_ex__(PyObject)}) + * + * @param o either a PyObject[2] or a PyObject, as given by + * {@link #__coerce_ex__(PyObject)}. + */ + protected final PyObject adaptToCoerceTuple(Object o) { if (o == Py.None) { return Py.NotImplemented; } @@ -1001,8 +1020,6 @@ } } - - /* The basic comparision operations */ /** @@ -1155,29 +1172,40 @@ if (this == other) return 0; - int result; - result = this.__cmp__(other); - if (result != -2) + int result = _try__cmp__(other); + if (result != -2) { return result; - - if (!(this instanceof PyInstance)) { - result = other.__cmp__(this); - if (result != -2) - return -result; } - return this._default_cmp(other); } /* * Like _cmp_unsafe but limited to ==/!= as 0/!=0, - * avoids to invoke Py.id + * thus it avoids to invoke _default_cmp. */ private final int _cmpeq_unsafe(PyObject other) { // Shortcut for equal objects if (this == other) return 0; + int result = _try__cmp__(other); + if (result != -2) { + return result; + } + + return this._is(other).__nonzero__()?0:1; + } + + /** + * Tries a 3-way comparison, using __cmp__. It tries the following + * operations until one of them succeed:<ul> + * <li>this.__cmp__(other) + * <li>other.__cmp__(this) + * <li>this._coerce(other) followed by coerced_this.__cmp__(coerced_other)</ul> + * + * @return -1, 0, -1 or -2, according to the {@link #__cmp__} protocol. + */ + private int _try__cmp__(PyObject other) { int result; result = this.__cmp__(other); if (result != -2) @@ -1188,8 +1216,23 @@ if (result != -2) return -result; } + // Final attempt: coerce both arguments and compare that. We are doing + // this the same point where CPython 2.5 does. (See + // <http://svn.python.org/projects/python/tags/r252/Objects/object.c> at + // the end of try_3way_compare). + // + // This is not exactly was is specified on + // <http://docs.python.org/ref/coercion-rules.html>, where coercion is + // supposed to happen before trying __cmp__. - return this._is(other).__nonzero__()?0:1; + PyObject[] coerced = _coerce(other); + if (coerced != null) { + result = coerced[0].__cmp__(coerced[1]); + if (result != -2) { + return result; + } + } + return -2; } Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,4 +1111,18 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + } Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTupleDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyTupleDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,6 +1111,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTypeDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyTypeDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1087,6 +1087,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1111,4 +1111,18 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + } Modified: branches/asm/src/org/python/modules/_csv/PyDialectDerived.java =================================================================== --- branches/asm/src/org/python/modules/_csv/PyDialectDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/_csv/PyDialectDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1089,6 +1089,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/asm/src/org/python/modules/_functools/PyPartialDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/_functools/PyPartialDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1089,6 +1089,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1113,6 +1113,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1113,6 +1113,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1113,6 +1113,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1113,6 +1113,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1089,6 +1089,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-08-10 20:50:55 UTC (rev 5133) @@ -1089,6 +1089,20 @@ 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==null||res==Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + public String toString() { PyType self_type=getType(); PyObject impl=self_type.lookup("__repr__"); Modified: branches/asm/src/templates/object.derived =================================================================== --- branches/asm/src/templates/object.derived 2008-08-10 19:52:51 UTC (rev 5132) +++ branches/asm/src/templates/object.derived 2008-08-10 20:50:55 UTC (rev 5133) @@ -444,3 +444,18 @@ 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 == null || res == Py.None) + return res; + if (!(res instanceof PyTuple)) + throw Py.TypeError("coercion should return None or 2-tuple"); + return ((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |