From: <pj...@us...> - 2009-05-08 06:42:03
|
Revision: 6318 http://jython.svn.sourceforge.net/jython/?rev=6318&view=rev Author: pjenvey Date: 2009-05-08 06:41:51 +0000 (Fri, 08 May 2009) Log Message: ----------- match slice __str__ to its __repr__ Modified Paths: -------------- trunk/jython/src/org/python/core/PySlice.java Modified: trunk/jython/src/org/python/core/PySlice.java =================================================================== --- trunk/jython/src/org/python/core/PySlice.java 2009-05-08 05:51:42 UTC (rev 6317) +++ trunk/jython/src/org/python/core/PySlice.java 2009-05-08 06:41:51 UTC (rev 6318) @@ -65,6 +65,7 @@ } } + @Override public int hashCode() { return slice___hash__(); } @@ -74,16 +75,7 @@ throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); } - public PyString __str__() { - return new PyString(getStart().__repr__() + ":" + getStop().__repr__() + ":" - + getStep().__repr__()); - } - - public PyString __repr__() { - return new PyString("slice(" + getStart().__repr__() + ", " + getStop().__repr__() + ", " - + getStep().__repr__() + ")"); - } - + @Override public PyObject __eq__(PyObject o) { if (getType() != o.getType() && !(getType().isSubType(o.getType()))) { return null; @@ -92,17 +84,15 @@ return Py.True; } PySlice oSlice = (PySlice)o; - if (eq(getStart(), oSlice.getStart()) && eq(getStop(), oSlice.getStop()) - && eq(getStep(), oSlice.getStep())) { - return Py.True; - } - return Py.False; + return Py.newBoolean(eq(getStart(), oSlice.getStart()) && eq(getStop(), oSlice.getStop()) + && eq(getStep(), oSlice.getStep())); } private static final boolean eq(PyObject o1, PyObject o2) { return o1._cmp(o2) == 0; } + @Override public PyObject __ne__(PyObject o) { return __eq__(o).__not__(); } @@ -221,6 +211,16 @@ throw Py.TypeError("slice indices must be integers or None or have an __index__ method"); } + @Override + public String toString() { + return slice_toString(); + } + + @ExposedMethod(names = "__repr__", doc = BuiltinDocs.slice___repr___doc) + final String slice_toString() { + return String.format("slice(%s, %s, %s)", getStart(), getStop(), getStep()); + } + public final PyObject getStart() { return start; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |