From: <cg...@us...> - 2007-04-13 06:37:56
|
Revision: 3150 http://svn.sourceforge.net/jython/?rev=3150&view=rev Author: cgroves Date: 2007-04-12 23:37:55 -0700 (Thu, 12 Apr 2007) Log Message: ----------- Exposed rich comparison methods to fix bugs 1658688, 1658687, 1658685, and 1658683 Modified Paths: -------------- trunk/jython/Lib/test/test_descrtut.py trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyDictionary.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/templates/dict.expose trunk/jython/src/templates/sequence.expose trunk/jython/src/templates/str.expose trunk/jython/src/templates/tuple.expose Modified: trunk/jython/Lib/test/test_descrtut.py =================================================================== --- trunk/jython/Lib/test/test_descrtut.py 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/Lib/test/test_descrtut.py 2007-04-13 06:37:55 UTC (rev 3150) @@ -189,14 +189,18 @@ '__delslice__', '__doc__', '__eq__', + '__ge__', '__getattribute__', '__getitem__', '__getslice__', + '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', + '__le__', '__len__', + '__lt__', '__mul__', '__ne__', '__new__', Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PyArray.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -67,6 +67,82 @@ } dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyArray.class,1,1,new exposed___eq__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyArray.class,1,1,new exposed___lt__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyArray.class,1,1,new exposed___le__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyArray.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyArray.class,1,1,new exposed___ge__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PyDictionary.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -54,6 +54,82 @@ } dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyDictionary.class,1,1,new exposed___eq__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDictionary)self).dict___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyDictionary.class,1,1,new exposed___lt__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDictionary)self).dict___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyDictionary.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDictionary)self).dict___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyDictionary.class,1,1,new exposed___ge__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDictionary)self).dict___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyDictionary.class,1,1,new exposed___le__(null,null))); class exposed___cmp__ extends PyBuiltinMethodNarrow { exposed___cmp__(PyObject self,PyBuiltinFunction.Info info) { @@ -735,6 +811,38 @@ if (eq_result == null) return null; return eq_result == Py.One?Py.Zero:Py.One; } + + final PyObject dict___lt__(PyObject ob_other){ + int result = __cmp__(ob_other); + if(result == -2){ + return null; + } + return result < 0 ? Py.One : Py.Zero; + } + + final PyObject dict___gt__(PyObject ob_other){ + int result = __cmp__(ob_other); + if(result == -2){ + return null; + } + return result > 0 ? Py.One : Py.Zero; + } + + final PyObject dict___le__(PyObject ob_other){ + int result = __cmp__(ob_other); + if(result == -2){ + return null; + } + return result <= 0 ? Py.One : Py.Zero; + } + + final PyObject dict___ge__(PyObject ob_other){ + int result = __cmp__(ob_other); + if(result == -2){ + return null; + } + return result >= 0 ? Py.One : Py.Zero; + } public int __cmp__(PyObject ob_other) { return dict___cmp__(ob_other); Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PyList.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -62,6 +62,82 @@ } dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyList.class,1,1,new exposed___eq__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyList)self).seq___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyList.class,1,1,new exposed___lt__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyList)self).seq___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyList.class,1,1,new exposed___le__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyList)self).seq___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyList.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyList)self).seq___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyList.class,1,1,new exposed___ge__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PySequence.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -137,6 +137,10 @@ return (i == -1) ? Py.One : Py.Zero; return __finditem__(i)._lt(o.__finditem__(i)); } + + final synchronized PyObject seq___lt__(PyObject o){ + return __lt__(o); + } public synchronized PyObject __le__(PyObject o) { if (!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { @@ -147,6 +151,10 @@ return (i == -1 || i == -2) ? Py.One : Py.Zero; return __finditem__(i)._le(o.__finditem__(i)); } + + final synchronized PyObject seq___le__(PyObject o){ + return __le__(o); + } public synchronized PyObject __gt__(PyObject o) { if (!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { @@ -157,6 +165,10 @@ return (i == -3) ? Py.One : Py.Zero; return __finditem__(i)._gt(o.__finditem__(i)); } + + final synchronized PyObject seq___gt__(PyObject o){ + return __gt__(o); + } public synchronized PyObject __ge__(PyObject o) { if (!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { @@ -167,6 +179,10 @@ return (i == -3 || i == -2) ? Py.One : Py.Zero; return __finditem__(i)._ge(o.__finditem__(i)); } + + final synchronized PyObject seq___ge__(PyObject o){ + return __ge__(o); + } // Return value >= 0 is the index where the sequences differs. // -1: reached the end of o1 without a difference Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PyString.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -50,6 +50,82 @@ } dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyString.class,1,1,new exposed___eq__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyString)self).str___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyString.class,1,1,new exposed___lt__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyString)self).str___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyString.class,1,1,new exposed___le__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyString)self).str___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyString.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyString)self).str___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyString.class,1,1,new exposed___ge__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { @@ -1859,13 +1935,17 @@ return null; return string.equals(s) ? Py.Zero : Py.One; } - + public PyObject __lt__(PyObject other) { String s = coerce(other); if (s == null) return null; return string.compareTo(s) < 0 ? Py.One : Py.Zero; } + + final PyObject str___lt__(PyObject other){ + return __lt__(other); + } public PyObject __le__(PyObject other) { String s = coerce(other); @@ -1873,6 +1953,10 @@ return null; return string.compareTo(s) <= 0 ? Py.One : Py.Zero; } + + final PyObject str___le__(PyObject other){ + return __le__(other); + } public PyObject __gt__(PyObject other) { String s = coerce(other); @@ -1880,6 +1964,10 @@ return null; return string.compareTo(s) > 0 ? Py.One : Py.Zero; } + + final PyObject str___gt__(PyObject other){ + return __gt__(other); + } public PyObject __ge__(PyObject other) { String s = coerce(other); @@ -1887,6 +1975,10 @@ return null; return string.compareTo(s) >= 0 ? Py.One : Py.Zero; } + + final PyObject str___ge__(PyObject other){ + return __ge__(other); + } private static String coerce(PyObject o) { if (o instanceof PyString) Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/org/python/core/PyTuple.java 2007-04-13 06:37:55 UTC (rev 3150) @@ -63,6 +63,82 @@ } dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyTuple.class,1,1,new exposed___eq__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyTuple)self).tuple___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyTuple.class,1,1,new exposed___lt__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyTuple)self).tuple___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyTuple.class,1,1,new exposed___le__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyTuple)self).tuple___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyTuple.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyTuple)self).tuple___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyTuple.class,1,1,new exposed___ge__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { @@ -344,6 +420,22 @@ return super.__eq__(o); } + final PyObject tuple___gt__(PyObject o) { + return super.__gt__(o); + } + + final PyObject tuple___ge__(PyObject o) { + return super.__ge__(o); + } + + final PyObject tuple___lt__(PyObject o) { + return super.__lt__(o); + } + + final PyObject tuple___le__(PyObject o) { + return super.__le__(o); + } + public PyObject __add__(PyObject generic_other) { return tuple___add__(generic_other); } Modified: trunk/jython/src/templates/dict.expose =================================================================== --- trunk/jython/src/templates/dict.expose 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/templates/dict.expose 2007-04-13 06:37:55 UTC (rev 3150) @@ -2,7 +2,7 @@ type_name: dict type_class: PyDictionary # exposed methods -expose_binary: __ne__ __eq__ +expose_binary: __ne__ __eq__ __lt__ __gt__ __ge__ __le__ expose_vanilla_cmp: expose_cmeth: fromkeys o o? expose_key_getitem: @@ -35,5 +35,4 @@ `void; # TODO: # ('__getattribute__'), -# '__lt__', '__gt__', '__ge__', __le__' # (__doc__) Modified: trunk/jython/src/templates/sequence.expose =================================================================== --- trunk/jython/src/templates/sequence.expose 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/templates/sequence.expose 2007-04-13 06:37:55 UTC (rev 3150) @@ -1,7 +1,7 @@ # sequence itself is not python visible # exposed methods -expose_binary: seq_> __ne__ __eq__ +expose_binary: seq_> __ne__ __eq__ __lt__ __le__ __gt__ __ge__ expose_meth: object_> :b __contains__ o expose_meth: seq_> :- __delitem__ o expose_meth: seq_> :- __setitem__ oo Modified: trunk/jython/src/templates/str.expose =================================================================== --- trunk/jython/src/templates/str.expose 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/templates/str.expose 2007-04-13 06:37:55 UTC (rev 3150) @@ -5,7 +5,7 @@ expose_index_getitem: seq_> expose_meth: seq_> __getslice__ ooo? # -expose_binary: __ne__ __eq__ +expose_binary: __ne__ __eq__ __lt__ __le__ __gt__ __ge__ expose_meth: :b __contains__ o expose_meth: :i __len__ expose_meth: __add__ o Modified: trunk/jython/src/templates/tuple.expose =================================================================== --- trunk/jython/src/templates/tuple.expose 2007-04-13 06:36:46 UTC (rev 3149) +++ trunk/jython/src/templates/tuple.expose 2007-04-13 06:37:55 UTC (rev 3150) @@ -7,7 +7,7 @@ expose_meth: seq_> __getslice__ ooo? #expose_meth: seq_> __iter__ # -expose_binary: __ne__ __eq__ +expose_binary: __ne__ __eq__ __lt__ __le__ __gt__ __ge__ expose_meth: :b __contains__ o expose_meth: :i __len__ expose_meth: __add__ o This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |