? org/python/core/PyCallIterator.java ? org/python/core/PySeqIterator.java cvs server: Diffing . Index: jython.bat =================================================================== RCS file: /cvsroot/jython/jython/jython.bat,v retrieving revision 1.2 diff -u -r1.2 jython.bat --- jython.bat 2001/11/26 08:23:02 1.2 +++ jython.bat 2001/12/20 20:55:27 @@ -14,4 +14,4 @@ :end rem -Xmx90mb -java.exe -Dpython.home=%JYTHON_HOME% org.python.util.jython %ARGS% +java.exe -Dpython.path=%PYTHON_HOME%\Lib -Dpython.home=%JYTHON_HOME% org.python.util.jython %ARGS% cvs server: Diffing Demo cvs server: Diffing Demo/applet cvs server: Diffing Demo/awt cvs server: Diffing Demo/bean cvs server: Diffing Demo/embed cvs server: Diffing Demo/javaclasses cvs server: Diffing Demo/javaclasses/pygraph cvs server: Diffing Demo/jreload cvs server: Diffing Demo/jreload/_xample cvs server: Diffing Demo/jreload/src cvs server: Diffing Demo/jreload/src/example cvs server: Diffing Demo/swing cvs server: Diffing Doc cvs server: Diffing Doc/api cvs server: Diffing Doc/images cvs server: Diffing Lib Index: Lib/javaos.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/javaos.py,v retrieving revision 2.12 diff -u -r2.12 javaos.py --- Lib/javaos.py 2001/11/28 17:31:50 2.12 +++ Lib/javaos.py 2001/12/20 20:55:28 @@ -44,6 +44,10 @@ pathsep = java.io.File.pathSeparator defpath = '.' linesep = java.lang.System.getProperty('line.separator') +if sep=='.': + extsep = '/' +else: + extsep = '.' def _exit(n=0): java.lang.System.exit(n) Index: Lib/string.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/string.py,v retrieving revision 1.8 diff -u -r1.8 string.py --- Lib/string.py 2000/09/30 10:40:20 1.8 +++ Lib/string.py 2001/12/20 20:55:29 @@ -16,6 +16,8 @@ digits -- a string containing all characters considered decimal digits hexdigits -- a string containing all characters considered hexadecimal digits octdigits -- a string containing all characters considered octal digits +punctuation -- a string containing all characters considered punctuation +printable -- a string containing all characters considered printable """ @@ -24,9 +26,15 @@ lowercase = 'abcdefghijklmnopqrstuvwxyz' uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letters = lowercase + uppercase +ascii_lowercase = lowercase +ascii_uppercase = uppercase +ascii_letters = ascii_lowercase + ascii_uppercase digits = '0123456789' hexdigits = digits + 'abcdef' + 'ABCDEF' octdigits = '01234567' +punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" +printable = digits + letters + punctuation + whitespace + # Case conversion helpers _idmap = '' cvs server: Diffing Lib/jxxload_help cvs server: Diffing Lib/pawt cvs server: Diffing Lib/test cvs server: Diffing Lib/test/bugs cvs server: Diffing Lib/test/bugs/pr133 cvs server: Diffing Lib/test/javatests cvs server: Diffing Misc Index: Misc/make_binops.py =================================================================== RCS file: /cvsroot/jython/jython/Misc/make_binops.py,v retrieving revision 1.4 diff -u -r1.4 make_binops.py --- Misc/make_binops.py 2001/02/04 14:51:47 1.4 +++ Misc/make_binops.py 2001/12/20 20:55:30 @@ -2,6 +2,7 @@ binops = \ [('add', '+'), ('sub', '-'), ('mul', '*'), ('div', '/'), + ('floordiv', '//'), ('mod', '%'), ('divmod', 'divmod'), ('pow', '**'), ('lshift', '<<'), ('rshift', '>>'), ('and', '&'), ('or', '|'), ('xor', '^')] cvs server: Diffing Tools cvs server: Diffing Tools/freeze cvs server: Diffing Tools/jythonc cvs server: Diffing Tools/jythonc/jast cvs server: Diffing bugtests cvs server: Diffing bugtests/classes cvs server: Diffing bugtests/classes/test092m cvs server: Diffing bugtests/classes/test121p cvs server: Diffing bugtests/classes/test217p cvs server: Diffing bugtests/classes/test232p cvs server: Diffing bugtests/classes/test246p cvs server: Diffing bugtests/classes/test301p cvs server: Diffing bugtests/classes/test336p cvs server: Diffing bugtests/classes/test336p/data cvs server: Diffing bugtests/test049p cvs server: Diffing bugtests/test088p cvs server: Diffing bugtests/test122p cvs server: Diffing bugtests/test154p cvs server: Diffing bugtests/test168p cvs server: Diffing bugtests/test168p/submod cvs server: Diffing bugtests/test170p cvs server: Diffing bugtests/test171p cvs server: Diffing bugtests/test173p cvs server: Diffing bugtests/test194m cvs server: Diffing bugtests/test209p cvs server: Diffing bugtests/test209p/foo cvs server: Diffing bugtests/test235p cvs server: Diffing bugtests/test238p cvs server: Diffing bugtests/test240p cvs server: Diffing bugtests/test241p cvs server: Diffing bugtests/test243p cvs server: Diffing bugtests/test243p/real cvs server: Diffing bugtests/test244p cvs server: Diffing bugtests/test246p cvs server: Diffing bugtests/test261p cvs server: Diffing bugtests/test261p/ccs cvs server: Diffing bugtests/test261p/ccs/util cvs server: Diffing bugtests/test262p cvs server: Diffing bugtests/test262p/p1 cvs server: Diffing bugtests/test269p cvs server: Diffing bugtests/test270p cvs server: Diffing bugtests/test273p cvs server: Diffing bugtests/test273p/com cvs server: Diffing bugtests/test277p cvs server: Diffing bugtests/test278p cvs server: Diffing bugtests/test279p cvs server: Diffing bugtests/test293p cvs server: Diffing bugtests/test293p/submod cvs server: Diffing bugtests/test296p cvs server: Diffing bugtests/test308d cvs server: Diffing bugtests/test339p cvs server: Diffing bugtests/test342p cvs server: Diffing com cvs server: Diffing com/ziclix cvs server: Diffing com/ziclix/python cvs server: Diffing com/ziclix/python/sql cvs server: Diffing com/ziclix/python/sql/connect cvs server: Diffing com/ziclix/python/sql/handler cvs server: Diffing com/ziclix/python/sql/pipe cvs server: Diffing com/ziclix/python/sql/pipe/csv cvs server: Diffing com/ziclix/python/sql/pipe/db cvs server: Diffing com/ziclix/python/sql/resource cvs server: Diffing com/ziclix/python/sql/util cvs server: Diffing installer cvs server: Diffing org cvs server: Diffing org/apache cvs server: Diffing org/apache/oro cvs server: Diffing org/apache/oro/text cvs server: Diffing org/apache/oro/text/regex cvs server: Diffing org/python cvs server: Diffing org/python/compiler Index: org/python/compiler/CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.23 diff -u -r2.23 CodeCompiler.java --- org/python/compiler/CodeCompiler.java 2001/11/27 19:07:21 2.23 +++ org/python/compiler/CodeCompiler.java 2001/12/20 20:55:38 @@ -933,7 +933,8 @@ return null; } - public int safe_getitem=0; + public int iter=0; + public int iternext=0; public Object for_stmt(SimpleNode node) throws Exception { beginLoop(); @@ -943,7 +944,7 @@ Label next_loop = code.getLabel(); int list_tmp = code.getLocal(); - int index_tmp = code.getLocal(); + int iter_tmp = code.getLocal(); int expr_tmp = code.getLocal(); setline(node); @@ -952,35 +953,39 @@ node.getChild(1).visit(this); code.astore(list_tmp); - //set up the loop counter - code.iconst(0); - code.istore(index_tmp); + //set up the loop iterator + code.aload(list_tmp); + if (mrefs.iter == 0) { + mrefs.iter = code.pool.Methodref( + "org/python/core/PyObject", + "__iter__", "()" + $pyObj); + } + code.invokevirtual(mrefs.iter); + code.astore(iter_tmp); + //do check at end of loop. Saves one opcode ;-) code.goto_(next_loop); start_loop.setPosition(); - //set index variable to current entry in list + //set iter variable to current entry in list set(node.getChild(0), expr_tmp); //evaluate for body node.getChild(2).visit(this); continue_loop.setPosition(); - //increment counter - code.iinc(index_tmp, 1); next_loop.setPosition(); setline(node); //get the next element from the list - code.aload(list_tmp); - code.iload(index_tmp); - if (mrefs.safe_getitem == 0) { - mrefs.safe_getitem = code.pool.Methodref( + code.aload(iter_tmp); + if (mrefs.iternext == 0) { + mrefs.iternext = code.pool.Methodref( "org/python/core/PyObject", - "__finditem__", "(I)" + $pyObj); + "__iternext__", "()" + $pyObj); } - code.invokevirtual(mrefs.safe_getitem); + code.invokevirtual(mrefs.iternext); code.astore(expr_tmp); code.aload(expr_tmp); //if no more elements then fall through @@ -996,7 +1001,7 @@ break_loop.setPosition(); code.freeLocal(list_tmp); - code.freeLocal(index_tmp); + code.freeLocal(iter_tmp); code.freeLocal(expr_tmp); // Probably need to detect "guaranteed exits" @@ -1406,6 +1411,10 @@ return binaryop(node, "_div"); } + public Object floordiv_2op(SimpleNode node) throws Exception { + return binaryop(node, "_floordiv"); + } + public Object mod_2op(SimpleNode node) throws Exception { return binaryop(node, "_mod"); } @@ -1465,6 +1474,10 @@ public Object aug_divide(SimpleNode node) throws Exception { return aug_binaryop(node, "__idiv__"); + } + + public Object aug_floordivide(SimpleNode node) throws Exception { + return aug_binaryop(node, "__ifloordiv__"); } public Object aug_modulo(SimpleNode node) throws Exception { Index: org/python/compiler/Future.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Future.java,v retrieving revision 2.5 diff -u -r2.5 Future.java --- org/python/compiler/Future.java 2001/11/27 19:07:21 2.5 +++ org/python/compiler/Future.java 2001/12/20 20:55:39 @@ -6,7 +6,7 @@ public class Future extends Object implements PythonGrammarTreeConstants { - private boolean nested_scopes; + private boolean nested_scopes = true; private static final String FUTURE = "__future__"; @@ -35,6 +35,12 @@ // *known* features if (feature.equals("nested_scopes")) { nested_scopes = true; + continue; + } + if (feature.equals("generators")) { + continue; + } + if (feature.equals("division")) { continue; } throw new ParseException("future feature "+feature+ Index: org/python/compiler/ScopesCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopesCompiler.java,v retrieving revision 2.5 diff -u -r2.5 ScopesCompiler.java --- org/python/compiler/ScopesCompiler.java 2001/11/27 19:07:21 2.5 +++ org/python/compiler/ScopesCompiler.java 2001/12/20 20:55:40 @@ -398,6 +398,11 @@ return null; } + public Object floordiv_2op(SimpleNode node) throws Exception { + binaryop(node); + return null; + } + public Object mod_2op(SimpleNode node) throws Exception { binaryop(node); return null; @@ -590,7 +595,7 @@ String name = (String)node.getInfo(); if ( mode != GET) { if (name.equals("__debug__")) - code_compiler.error("can not assign to __debug__",false,node); + code_compiler.error("can not assign to __debug__",true,node); cur.addBound(name); } else cur.addUsed(name); @@ -623,6 +628,11 @@ } public Object aug_divide(SimpleNode node) throws Exception { + aug_assign(node); + return null; + } + + public Object aug_floordivide(SimpleNode node) throws Exception { aug_assign(node); return null; } cvs server: Diffing org/python/core Index: org/python/core/CompilerFlags.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/CompilerFlags.java,v retrieving revision 2.4 diff -u -r2.4 CompilerFlags.java --- org/python/core/CompilerFlags.java 2001/11/27 19:07:21 2.4 +++ org/python/core/CompilerFlags.java 2001/12/20 20:55:40 @@ -10,7 +10,7 @@ nested_scopes = true; } - public boolean nested_scopes; + public boolean nested_scopes = true; public String encoding; } Index: org/python/core/Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.60 diff -u -r2.60 Py.java --- org/python/core/Py.java 2001/12/06 19:30:32 2.60 +++ org/python/core/Py.java 2001/12/20 20:55:45 @@ -120,6 +120,11 @@ return new PyException(Py.TypeError, message); } + public static PyObject ReferenceError; + public static PyException ReferenceError(String message) { + return new PyException(Py.ReferenceError, message); + } + public static PyObject SystemError; public static PyException SystemError(String message) { return new PyException(Py.SystemError, message); @@ -175,6 +180,10 @@ } } + public static PyObject StopIterator; + public static PyException StopIterator(String message) { + return new PyException(Py.StopIterator, message); + } public static PyObject ImportError; public static PyException ImportError(String message) { @@ -236,6 +245,11 @@ warning(SyntaxWarning, message); } + public static PyObject OverflowWarning; + public static void OverflowWarning(String message) { + warning(OverflowWarning, message); + } + public static PyObject RuntimeWarning; public static void RuntimeWarning(String message) { warning(RuntimeWarning, message); @@ -519,6 +533,7 @@ Exception = initExc("Exception", exc, dict); SystemExit = initExc("SystemExit", exc, dict); + StopIterator = initExc("StopIterator", exc, dict); StandardError = initExc("StandardError", exc, dict); KeyboardInterrupt = initExc("KeyboardInterrupt", exc, dict); ImportError = initExc("ImportError", exc, dict); @@ -545,12 +560,14 @@ FloatingPointError = initExc("FloatingPointError", exc, dict); ValueError = initExc("ValueError", exc, dict); UnicodeError = initExc("UnicodeError", exc, dict); + ReferenceError = initExc("ReferenceError", exc, dict); SystemError = initExc("SystemError", exc, dict); MemoryError = initExc("MemoryError", exc, dict); Warning = initExc("Warning", exc, dict); UserWarning = initExc("UserWarning", exc, dict); DeprecationWarning = initExc("DeprecationWarning", exc, dict); SyntaxWarning = initExc("SyntaxWarning", exc, dict); + OverflowWarning = initExc("OverflowWarning", exc, dict); RuntimeWarning = initExc("RuntimeWarning", exc, dict); } Index: org/python/core/PyDictionary.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyDictionary.java,v retrieving revision 2.17 diff -u -r2.17 PyDictionary.java --- org/python/core/PyDictionary.java 2001/10/28 17:13:43 2.17 +++ org/python/core/PyDictionary.java 2001/12/20 20:55:46 @@ -2,6 +2,7 @@ package org.python.core; import java.util.Hashtable; +import java.util.Enumeration; @@ -191,6 +192,10 @@ throw Py.KeyError(key.toString()); } + public PyObject __iter__() { + return new PyDictIterator(this, table.keys()); + } + public String toString() { ThreadState ts = Py.getThreadState(); if (!ts.enterRepr(this)) { @@ -405,5 +410,19 @@ public int hashCode() { throw Py.TypeError("unhashable type"); + } +} + +class PyDictIterator extends PyObject { + Enumeration enumeration; + + public PyDictIterator(PyObject dict, Enumeration e) { + enumeration = e; + } + + public PyObject __iternext__() { + if (!enumeration.hasMoreElements()) + return null; + return (PyObject) enumeration.nextElement(); } } Index: org/python/core/PyFile.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFile.java,v retrieving revision 2.23 diff -u -r2.23 PyFile.java --- org/python/core/PyFile.java 2001/11/28 19:19:54 2.23 +++ org/python/core/PyFile.java 2001/12/20 20:55:48 @@ -706,6 +706,10 @@ char c2 = ' '; char c3 = ' '; int n = mode.length(); + for (int i = 0; i < n; i++) { + if ("awrtb+".indexOf(mode.charAt(i)) < 0) + throw Py.IOError("Unknown open mode:" + mode); + } if (n > 0) { c1 = mode.charAt(0); if (n > 1) { Index: org/python/core/PyFloat.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFloat.java,v retrieving revision 2.10 diff -u -r2.10 PyFloat.java --- org/python/core/PyFloat.java 2001/10/28 17:13:43 2.10 +++ org/python/core/PyFloat.java 2001/12/20 20:55:49 @@ -166,6 +166,24 @@ return new PyFloat(leftv / value); } + public PyObject __floordiv__(PyObject right) { + if (!canCoerce(right)) + return null; + double rightv = coerce(right); + if (rightv == 0) + throw Py.ZeroDivisionError("float division"); + return new PyFloat(Math.floor(value / rightv)); + } + + public PyObject __rfloordiv__(PyObject left) { + if (!canCoerce(left)) + return null; + double leftv = coerce(left); + if (value == 0) + throw Py.ZeroDivisionError("float division"); + return new PyFloat(Math.floor(leftv / value)); + } + private static double modulo(double x, double y) { if (y == 0) throw Py.ZeroDivisionError("float modulo"); @@ -222,8 +240,10 @@ if (!canCoerce(right)) return null; - if (modulo != null && !canCoerce(modulo)) - return null; + if (modulo != null) { + throw Py.TypeError("pow() 3rd argument not " + + "allowed unless all arguments are integers"); + } return _pow(value, coerce(right), modulo); } Index: org/python/core/PyFunction.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFunction.java,v retrieving revision 2.14 diff -u -r2.14 PyFunction.java --- org/python/core/PyFunction.java 2001/11/27 19:07:21 2.14 +++ org/python/core/PyFunction.java 2001/12/20 20:55:49 @@ -99,7 +99,8 @@ if (value instanceof PyDictionary || value instanceof PyStringMap) __dict__ = value; else if (value == Py.None) - __dict__ = null; + throw Py.TypeError("setting function's dictionary to " + + "a non-dict"); else throw Py.TypeError("func_dict must be set to a dict object"); } else { @@ -111,8 +112,7 @@ public void __delattr__(String name) { if (name == "__dict__" || name == "func_dict") { - __dict__ = null; - return; + throw Py.TypeError("function's dictionary may not be deleted"); } else if (name == "func_defaults") { func_defaults = Py.EmptyObjects; return; @@ -144,9 +144,9 @@ return Py.None; return new PyTuple(func_defaults); } - if (name == "__dict__") { + if (name == "__dict__" || name == "func_dict") { if (__dict__ == null) - return Py.None; + __dict__ = new PyStringMap(); return __dict__; } if (__dict__ != null) { Index: org/python/core/PyInstance.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyInstance.java,v retrieving revision 2.27 diff -u -r2.27 PyInstance.java --- org/python/core/PyInstance.java 2001/11/06 16:48:37 2.27 +++ org/python/core/PyInstance.java 2001/12/20 20:55:52 @@ -397,6 +397,15 @@ return (PyString)ret; } + public PyString __unicode__() { + PyObject ret = invoke_ex("__unicode__"); + if (ret == null) + return null; + if (!(ret instanceof PyString)) + throw Py.TypeError("__unicode__ method must return a string"); + return (PyString)ret; + } + public int hashCode() { PyObject ret; ret = invoke_ex("__hash__"); @@ -593,6 +602,16 @@ invoke("__delitem__", key); } + public PyObject __iter__() { + PyObject func = __findattr__("__iter__"); + if (func != null) + return func.__call__(); + func = __findattr__("__getitem__"); + if (func == null) + return super.__iter__(); + return new PySeqIterator(this); + } + public boolean __contains__(PyObject o) { PyObject func = __findattr__("__contains__"); if (func == null) @@ -902,6 +921,54 @@ if (ret != null) return ret; return super.__idiv__(o); + } + + + /** + * Implements the __floordiv__ method by looking it up + * in the instance's dictionary and calling it if it is found. + **/ + public PyObject __floordiv__(PyObject o) { + Object ctmp = __coerce_ex__(o); + if (ctmp == null || ctmp == Py.None) + return invoke_ex("__floordiv__", o); + else { + PyObject o1 = ((PyObject[])ctmp)[0]; + PyObject o2 = ((PyObject[])ctmp)[1]; + if (this == o1) // Prevent recusion if __coerce__ return self + return invoke_ex("__floordiv__", o2); + else + return o1._floordiv(o2); + } + } + + /** + * Implements the __rfloordiv__ method by looking it up + * in the instance's dictionary and calling it if it is found. + **/ + public PyObject __rfloordiv__(PyObject o) { + Object ctmp = __coerce_ex__(o); + if (ctmp == null || ctmp == Py.None) + return invoke_ex("__rfloordiv__", o); + else { + PyObject o1 = ((PyObject[])ctmp)[0]; + PyObject o2 = ((PyObject[])ctmp)[1]; + if (this == o1) // Prevent recusion if __coerce__ return self + return invoke_ex("__rfloordiv__", o2); + else + return o2._floordiv(o1); + } + } + + /** + * Implements the __ifloordiv__ method by looking it up + * in the instance's dictionary and calling it if it is found. + **/ + public PyObject __ifloordiv__(PyObject o) { + PyObject ret = invoke_ex("__ifloordiv__", o); + if (ret != null) + return ret; + return super.__ifloordiv__(o); } /** Index: org/python/core/PyInteger.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyInteger.java,v retrieving revision 2.13 diff -u -r2.13 PyInteger.java --- org/python/core/PyInteger.java 2001/10/28 17:13:43 2.13 +++ org/python/core/PyInteger.java 2001/12/20 20:55:53 @@ -90,19 +90,21 @@ int a = value; int b = rightv; int x = a + b; - if ((x^a) < 0 && (x^b) < 0) - throw Py.OverflowError("integer addition: "+this+" + "+right); - return Py.newInteger(x); + if ((x^a) >= 0 || (x^b) >= 0) + return Py.newInteger(x); + Py.OverflowWarning("integer addition"); + return new PyLong((long) a + (long)b); } public PyObject __radd__(PyObject left) { return __add__(left); } - private static PyInteger _sub(int a, int b) { + private static PyObject _sub(int a, int b) { int x = a - b; - if ((x^a) < 0 && (x^~b) < 0) - throw Py.OverflowError("integer subtraction: "+a+" - "+b); - return Py.newInteger(x); + if ((x^a) >= 0 || (x^~b) >= 0) + return Py.newInteger(x); + Py.OverflowWarning("integer subtraction"); + return new PyLong((long) a - (long)b); } public PyObject __sub__(PyObject right) { @@ -130,10 +132,10 @@ //long x = ((long)value)*((PyInteger)right).value; //System.out.println("mul: "+this+" * "+right+" = "+x); - if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) - throw Py.OverflowError("integer multiplication: "+this+ - " * "+right); - return Py.newInteger((int)x); + if (x <= Integer.MAX_VALUE && x >= Integer.MIN_VALUE) + return Py.newInteger((int)x); + Py.OverflowWarning("integer multiplication"); + return __long__().__mul__(right); } public PyObject __rmul__(PyObject left) { @@ -176,6 +178,18 @@ return Py.newInteger(divide(coerce(left), value)); } + public PyObject __floordiv__(PyObject right) { + if (!canCoerce(right)) + return null; + return Py.newInteger(divide(value, coerce(right))); + } + + public PyObject __rfloordiv__(PyObject left) { + if (!canCoerce(left)) + return null; + return Py.newInteger(divide(coerce(left), value)); + } + private static int modulo(int x, int y, int xdivy) { return x - xdivy*y; } @@ -213,7 +227,7 @@ if (modulo != null && !canCoerce(modulo)) return null; - return _pow(value, coerce(right), modulo); + return _pow(value, coerce(right), modulo, this, right); } public PyObject __rpow__(PyObject left, PyObject modulo) { @@ -223,10 +237,12 @@ if (modulo != null && !canCoerce(modulo)) return null; - return _pow(coerce(left), value, modulo); + return _pow(coerce(left), value, modulo, left, this); } - private static PyInteger _pow(int value, int pow, PyObject modulo) { + private static PyObject _pow(int value, int pow, PyObject modulo, + PyObject left, PyObject right) + { int mod = 0; long tmp = value; boolean neg = false; @@ -238,8 +254,7 @@ if (pow < 0) { if (value != 0) - throw Py.ValueError("cannot raise integer to a " + - "negative power"); + return left.__float__().__pow__(right, modulo); else throw Py.ZeroDivisionError("cannot raise 0 to a " + "negative power"); @@ -261,7 +276,8 @@ } if (result > Integer.MAX_VALUE) { - throw Py.OverflowError("integer pow()"); + Py.OverflowWarning("integer exponentiation"); + return left.__long__().__pow__(right, modulo); } } pow >>= 1; @@ -274,7 +290,8 @@ } if (tmp > Integer.MAX_VALUE) { - throw Py.OverflowError("integer pow()"); + Py.OverflowWarning("integer exponentiation"); + return left.__long__().__pow__(right, modulo); } } Index: org/python/core/PyList.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyList.java,v retrieving revision 2.25 diff -u -r2.25 PyList.java --- org/python/core/PyList.java 2001/11/27 13:51:37 2.25 +++ org/python/core/PyList.java 2001/12/20 20:55:55 @@ -457,7 +457,7 @@ } public PyObject __iadd__(PyObject o) { - extend(fastSequence(o, "argument to += must be a sequence")); + extend(fastSequence(o, "argument to += must be iterable")); return this; } Index: org/python/core/PyLong.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyLong.java,v retrieving revision 2.13 diff -u -r2.13 PyLong.java --- org/python/core/PyLong.java 2001/10/28 17:13:43 2.13 +++ org/python/core/PyLong.java 2001/12/20 20:55:56 @@ -50,6 +50,10 @@ } public double doubleValue() { + return doubleValue(value); + } + + private static double doubleValue(BigInteger value) { double v = value.doubleValue(); if (v == Double.NEGATIVE_INFINITY || v == Double.POSITIVE_INFINITY) { throw Py.OverflowError("long int too long to convert"); @@ -67,6 +71,7 @@ } public Object __tojava__(Class c) { +System.out.println("__tojava__ " + value + " " + c); try { if (c == Byte.TYPE || c == Byte.class) { return new Byte((byte)getLong(Byte.MIN_VALUE, @@ -197,6 +202,18 @@ return new PyLong(divide(coerce(left), value)); } + public PyObject __floordiv__(PyObject right) { + if (!canCoerce(right)) + return null; + return new PyLong(divide(value, coerce(right))); + } + + public PyObject __rfloordiv__(PyObject left) { + if (!canCoerce(left)) + return null; + return new PyLong(divide(coerce(left), value)); + } + private BigInteger modulo(BigInteger x, BigInteger y, BigInteger xdivy) { return x.subtract(xdivy.multiply(y)); } @@ -245,21 +262,21 @@ if (modulo != null && !canCoerce(right)) return null; - return _pow(value, coerce(right), modulo); + return _pow(value, coerce(right), modulo, this, right); } public PyObject __rpow__(PyObject left) { if (!canCoerce(left)) return null; - return _pow(coerce(left), value, null); + return _pow(coerce(left), value, null, left, this); } - public static PyLong _pow(BigInteger value, BigInteger y, - PyObject modulo) + public static PyObject _pow(BigInteger value, BigInteger y, + PyObject modulo, PyObject left, PyObject right) { if (y.compareTo(BigInteger.valueOf(0)) < 0) { if (value.compareTo(BigInteger.valueOf(0)) != 0) - throw Py.ValueError("long integer to a negative power"); + return left.__float__().__pow__(right, modulo); else throw Py.ZeroDivisionError("zero to a negative power"); } Index: org/python/core/PyObject.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyObject.java,v retrieving revision 2.26 diff -u -r2.26 PyObject.java --- org/python/core/PyObject.java 2001/10/28 17:13:43 2.26 +++ org/python/core/PyObject.java 2001/12/20 20:56:01 @@ -150,6 +150,10 @@ return __repr__(); } + public PyString __unicode__() { + return null; + } + /** * Equivalent to the standard Python __hash__ method. This method can * not be overridden. Instead, you should override the standard Java @@ -601,6 +605,15 @@ __delslice__(start, stop, Py.One); } + /*The basic functions to implement an iterator */ + + public PyObject __iter__() { + throw Py.TypeError("iteration over non-sequence"); + } + + public PyObject __iternext__() { + return null; + } /*The basic functions to implement a namespace*/ @@ -1261,11 +1274,9 @@ * @return the result of the search. **/ public boolean __contains__(PyObject o) { - PyObject tmp; - int i = 0; - - while ((tmp = __finditem__(i++)) != null) { - if (o._eq(tmp).__nonzero__()) + PyObject iter = __iter__(); + for (PyObject item = null; (item = iter.__iternext__()) != null; ) { + if (o._eq(item).__nonzero__()) return true; } return false; @@ -1576,6 +1587,51 @@ return x; throw Py.TypeError( "__div__ nor __rdiv__ defined for these operands"); + } + + /** + * Equivalent to the standard Python __floordiv__ method + * @param other the object to perform this binary operation with + * (the right-hand operand). + * @return the result of the floordiv, or null if this operation + * is not defined + **/ + public PyObject __floordiv__(PyObject other) { return null; } + + /** + * Equivalent to the standard Python __rfloordiv__ method + * @param other the object to perform this binary operation with + * (the left-hand operand). + * @return the result of the floordiv, or null if this operation + * is not defined. + **/ + public PyObject __rfloordiv__(PyObject other) { return null; } + + /** + * Equivalent to the standard Python __ifloordiv__ method + * @param other the object to perform this binary operation with + * (the right-hand operand). + * @return the result of the floordiv, or null if this operation + * is not defined + **/ + public PyObject __ifloordiv__(PyObject other) { return _floordiv(other); } + + /** + * Implements the Python expression this // other + * @param other the object to perform this binary operation with. + * @return the result of the floordiv. + * @exception PyTypeError if this operation can't be performed + * with these operands. + **/ + public final PyObject _floordiv(PyObject o2) { + PyObject x = __floordiv__(o2); + if (x != null) + return x; + x = o2.__rfloordiv__(this); + if (x != null) + return x; + throw Py.TypeError( + "__floordiv__ nor __rfloordiv__ defined for these operands"); } /** Index: org/python/core/PySequence.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PySequence.java,v retrieving revision 2.18 diff -u -r2.18 PySequence.java --- org/python/core/PySequence.java 2001/10/28 17:13:43 2.18 +++ org/python/core/PySequence.java 2001/12/20 20:56:02 @@ -185,6 +185,10 @@ return __len__() != 0; } + public PyObject __iter__() { + return new PySeqIterator(this); + } + public synchronized PyObject __eq__(PyObject o) { if (o.__class__ != __class__) return null; @@ -272,11 +276,15 @@ if (!seq.isSequenceType()) throw Py.TypeError(msg); - int n = seq.__len__(); - PyList list = new PyList(); - PyObject item; - for (int i = 0; (item = list.__finditem__(i)) != null; i++) { + PyObject iter = null; + try { + iter = seq.__iter__(); + } catch (PyException exc) { + if (Py.matchException(exc, Py.TypeError)) + throw Py.TypeError(msg); + } + for (PyObject item = null; (item = iter.__iternext__()) != null;) { list.append(item); } return list; @@ -498,3 +506,4 @@ return super.__tojava__(c); } } + Index: org/python/core/PyString.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyString.java,v retrieving revision 2.53 diff -u -r2.53 PyString.java --- org/python/core/PyString.java 2001/12/07 14:15:18 2.53 +++ org/python/core/PyString.java 2001/12/20 20:56:08 @@ -251,6 +251,22 @@ this(String.valueOf(c)); } + public PyString(PyObject[] args, String[] kws) { + ArgParser ap = new ArgParser("str", args, kws, + "string", "encoding", "errors"); + PyObject obj = ap.getPyObject(0); + String encoding = ap.getString(1, null); + String errors = ap.getString(2, null); + if (encoding != null || errors != null) { + string = codecs.decode(obj.__str__(), encoding, errors).toString(); + } else { + PyObject ret = obj.__unicode__(); + if (ret == null) + ret = obj.__str__(); + string = ret.toString(); + } + } + /** Internal use only. Do not call this method explicit. */ public static void classDictInit(PyObject dict) { dict.__setitem__("__str__", new StringFuncs("__str__", 1, 0)); @@ -1802,6 +1818,18 @@ public PyString encode(String encoding, String errors) { return codecs.encode(this, encoding, errors); + } + + public PyString decode() { + return encode(null, null); + } + + public PyString decode(String encoding) { + return decode(encoding, null); + } + + public PyString decode(String encoding, String errors) { + return codecs.decode(this, encoding, errors); } } Index: org/python/core/PyStringMap.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyStringMap.java,v retrieving revision 2.12 diff -u -r2.12 PyStringMap.java --- org/python/core/PyStringMap.java 2001/10/28 17:13:43 2.12 +++ org/python/core/PyStringMap.java 2001/12/20 20:56:09 @@ -127,6 +127,10 @@ } } + public PyObject __iter__() { + return new PyStringMapIterator(); + } + private final void insertkey(String key, PyObject value) { String[] table = keys; int maxindex = table.length; @@ -539,5 +543,27 @@ l.append(value); } return l; + } + + class PyStringMapIterator extends PyObject { + private int idx; + + public PyStringMapIterator() { + this.idx = 0; + } + + public PyObject __iternext__() { + String[] keyTable = keys; + int n = keyTable.length; + + for (; idx < n; idx++) { + String key = keyTable[idx]; + if (key == null || key == "" || values[idx] == null) + continue; + idx++; + return Py.newString(key); + } + return null; + } } } Index: org/python/core/PySystemState.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PySystemState.java,v retrieving revision 2.70 diff -u -r2.70 PySystemState.java --- org/python/core/PySystemState.java 2001/12/06 14:31:12 2.70 +++ org/python/core/PySystemState.java 2001/12/20 20:56:11 @@ -17,13 +17,13 @@ /** * The current version of JPython. */ - public static String version = "2.1b1"; + public static String version = "2.2pre"; private static int PY_MAJOR_VERSION = 2; - private static int PY_MINOR_VERSION = 1; + private static int PY_MINOR_VERSION = 2; private static int PY_MICRO_VERSION = 0; - private static int PY_RELEASE_LEVEL = 0xB; - private static int PY_RELEASE_SERIAL = 1; + private static int PY_RELEASE_LEVEL = 0xA; + private static int PY_RELEASE_SERIAL = 0; public static int hexversion = ((PY_MAJOR_VERSION << 24) | (PY_MINOR_VERSION << 16) | Index: org/python/core/__builtin__.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/__builtin__.java,v retrieving revision 2.39 diff -u -r2.39 __builtin__.java --- org/python/core/__builtin__.java 2001/11/27 19:07:21 2.39 +++ org/python/core/__builtin__.java 2001/12/20 20:56:13 @@ -111,6 +111,7 @@ public static void classDictInit(PyObject dict) { dict.__setitem__("None", Py.None); dict.__setitem__("Ellipsis", Py.Ellipsis); + dict.__setitem__("unicode", PyJavaClass.lookup(PyString.class)); // Work in debug mode by default // Hopefully add -O option in the future to change this @@ -211,6 +212,16 @@ } public static PyCode compile(String data, String filename, String type) { + return compile(data, filename, type, 0, false); + } + + public static PyCode compile(String data, String filename, String type, + int flags) { + return compile(data, filename, type, flags, false); + } + + public static PyCode compile(String data, String filename, String type, + int flags, boolean dont_inherit) { return Py.compile_flags(data,filename,type,Py.getCompilerFlags()); } @@ -826,11 +837,19 @@ return slice(Py.None, stop, Py.None); } + public static PyObject iter(PyObject obj) { + return obj.__iter__(); + } + + public static PyObject iter(PyObject callable, PyObject sentinel) { + return new PyCallIterator(callable, sentinel); + } public static PyString str(PyObject o) { return o.__str__(); } +/* public static PyString unicode(PyObject v) { return unicode(v.__str__(), null, null); } @@ -844,6 +863,7 @@ { return codecs.decode(v, encoding, errors); } +*/ public static PyTuple tuple(PyObject o) { if (o instanceof PyTuple) @@ -912,8 +932,8 @@ if (getitem == null) { // Get the same error as CPython for instances. This // should throw an AttributeError. - if (argstar[j] instanceof PyInstance) - argstar[j].__getattr__("__getitem__"); + //if (argstar[j] instanceof PyInstance) + // argstar[j].__getattr__("__getitem__"); throw Py.TypeError("unindexable object"); } getitems[j] = getitem; Index: org/python/core/codecs.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/codecs.java,v retrieving revision 2.11 diff -u -r2.11 codecs.java --- org/python/core/codecs.java 2001/08/06 20:04:12 2.11 +++ org/python/core/codecs.java 2001/12/20 20:56:14 @@ -362,7 +362,17 @@ return v.toString(); } + /* --- UTF-7 Codec ---------------------------------------------------- */ + public static String PyUnicode_DecodeUTF7(String str, String errors) { + // XXX: Insert implementation here. + return str; + } + + public static String PyUnicode_EncodeUTF7(String str, String errors) { + // XXX: Insert implementation here. + return str; + } /* --- 7-bit ASCII Codec -------------------------------------------- */ Index: org/python/core/exceptions.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/exceptions.java,v retrieving revision 1.10 diff -u -r1.10 exceptions.java --- org/python/core/exceptions.java 2001/11/27 19:07:21 1.10 +++ org/python/core/exceptions.java 2001/12/20 20:56:16 @@ -24,6 +24,7 @@ "Exception\n" + " |\n" + " +-- SystemExit\n" + +" +-- StopIteration\n" + " +-- StandardError\n" + " | |\n" + " | +-- KeyboardInterrupt\n" + @@ -68,6 +69,7 @@ " | | |\n" + " | | +-- UnicodeError\n" + " | |\n" + +" | +-- ReferenceError\n" + " | +-- SystemError\n" + " | +-- MemoryError\n" + " |\n" + @@ -76,6 +78,7 @@ " +-- UserWarning\n" + " +-- DeprecationWarning\n" + " +-- SyntaxWarning\n" + +" +-- OverflowWarning\n" + " +-- RuntimeWarning"; private exceptions() { ; } @@ -142,6 +145,9 @@ "the Python version, and the hardware/OS "+ "platform and version."); + buildClass(dict, "ReferenceError", "StandardError", "empty__init__", + "Weak ref proxy used after referent went away."); + buildClass(dict, "EOFError", "StandardError", "empty__init__", "Read beyond end of file."); @@ -203,8 +209,11 @@ buildClass(dict, "SystemExit", "Exception", "SystemExit", "Request to exit from the interpreter."); + buildClass(dict, "StopIterator", "Exception", "SystemExit", + "Request to exit from the interpreter."); + buildClass(dict, "Warning", "Exception", "empty__init__", - "Base class for warning categories."); + "Signal the end from iterator.next()."); buildClass(dict, "UserWarning", "Warning", "empty__init__", "Base class for warnings generated by user code."); @@ -217,6 +226,10 @@ buildClass(dict, "RuntimeWarning", "Warning", "empty__init__", "Base class for warnings about dubious runtime behavior."); + + buildClass(dict, "OverflowWarning", "Warning", "empty__init__", + "Base class for warnings about numeric overflow."); + ts.frame = ts.frame.f_back; } cvs server: Diffing org/python/modules Index: org/python/modules/_codecs.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/_codecs.java,v retrieving revision 2.9 diff -u -r2.9 _codecs.java --- org/python/modules/_codecs.java 2001/08/05 13:42:28 2.9 +++ org/python/modules/_codecs.java 2001/12/20 20:56:17 @@ -55,6 +55,28 @@ } + /* --- UTF-7 Codec --------------------------------------------------- */ + + public static PyTuple utf_7_decode(String str) { + return utf_7_decode(str, null); + } + + public static PyTuple utf_7_decode(String str, String errors) { + int size = str.length(); + return codec_tuple(codecs.PyUnicode_DecodeUTF7(str, errors), size); + } + + + public static PyTuple utf_7_encode(String str) { + return utf_7_encode(str, null); + } + + public static PyTuple utf_7_encode(String str, String errors) { + int size = str.length(); + return codec_tuple(codecs.PyUnicode_EncodeUTF7(str, errors), size); + } + + /* --- Character Mapping Codec --------------------------------------- */ Index: org/python/modules/_sre.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/_sre.java,v retrieving revision 1.6 diff -u -r1.6 _sre.java --- org/python/modules/_sre.java 2001/04/04 19:08:21 1.6 +++ org/python/modules/_sre.java 2001/12/20 20:56:17 @@ -22,7 +22,7 @@ public class _sre { // update when constants are added or removed - public static int MAGIC = 20010320; + public static int MAGIC = 20010701; public static PatternObject compile(PyString pattern, int flags, Index: org/python/modules/cStringIO.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/cStringIO.java,v retrieving revision 1.12 diff -u -r1.12 cStringIO.java --- org/python/modules/cStringIO.java 2001/11/27 13:51:37 1.12 +++ org/python/modules/cStringIO.java 2001/12/20 20:56:18 @@ -75,6 +75,11 @@ super.__setattr__(name, value); } + public PyObject __iter__() { + return new PyCallIterator(__getattr__("readline"), + Py.newString("")); + } + /** * Free the memory buffer. */ Index: org/python/modules/types.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/types.java,v retrieving revision 2.7 diff -u -r2.7 types.java --- org/python/modules/types.java 2001/11/27 19:07:22 2.7 +++ org/python/modules/types.java 2001/12/20 20:56:18 @@ -49,5 +49,9 @@ PyJavaClass.lookup(PyMethod.class)); dict.__setitem__("UnicodeType", PyJavaClass.lookup(PyString.class)); dict.__setitem__("XRangeType", PyJavaClass.lookup(PyXRange.class)); + + dict.__setitem__("StringTypes", new PyList(new PyObject[] { + PyJavaClass.lookup(PyString.class) + })); } } cvs server: Diffing org/python/modules/sre Index: org/python/modules/sre/SRE_STATE.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/sre/SRE_STATE.java,v retrieving revision 1.7 diff -u -r1.7 SRE_STATE.java --- org/python/modules/sre/SRE_STATE.java 2001/11/27 19:07:22 1.7 +++ org/python/modules/sre/SRE_STATE.java 2001/12/20 20:56:21 @@ -40,24 +40,25 @@ public static final int SRE_OP_CALL = 8; public static final int SRE_OP_CATEGORY = 9; public static final int SRE_OP_CHARSET = 10; - public static final int SRE_OP_GROUPREF = 11; - public static final int SRE_OP_GROUPREF_IGNORE = 12; - public static final int SRE_OP_IN = 13; - public static final int SRE_OP_IN_IGNORE = 14; - public static final int SRE_OP_INFO = 15; - public static final int SRE_OP_JUMP = 16; - public static final int SRE_OP_LITERAL = 17; - public static final int SRE_OP_LITERAL_IGNORE = 18; - public static final int SRE_OP_MARK = 19; - public static final int SRE_OP_MAX_UNTIL = 20; - public static final int SRE_OP_MIN_UNTIL = 21; - public static final int SRE_OP_NOT_LITERAL = 22; - public static final int SRE_OP_NOT_LITERAL_IGNORE = 23; - public static final int SRE_OP_NEGATE = 24; - public static final int SRE_OP_RANGE = 25; - public static final int SRE_OP_REPEAT = 26; - public static final int SRE_OP_REPEAT_ONE = 27; - public static final int SRE_OP_SUBPATTERN = 28; + public static final int SRE_OP_BIGCHARSET = 11; + public static final int SRE_OP_GROUPREF = 12; + public static final int SRE_OP_GROUPREF_IGNORE = 13; + public static final int SRE_OP_IN = 14; + public static final int SRE_OP_IN_IGNORE = 15; + public static final int SRE_OP_INFO = 16; + public static final int SRE_OP_JUMP = 17; + public static final int SRE_OP_LITERAL = 18; + public static final int SRE_OP_LITERAL_IGNORE = 19; + public static final int SRE_OP_MARK = 20; + public static final int SRE_OP_MAX_UNTIL = 21; + public static final int SRE_OP_MIN_UNTIL = 22; + public static final int SRE_OP_NOT_LITERAL = 23; + public static final int SRE_OP_NOT_LITERAL_IGNORE = 24; + public static final int SRE_OP_NEGATE = 25; + public static final int SRE_OP_RANGE = 26; + public static final int SRE_OP_REPEAT = 27; + public static final int SRE_OP_REPEAT_ONE = 28; + public static final int SRE_OP_SUBPATTERN = 29; public static final int SRE_AT_BEGINNING = 0; public static final int SRE_AT_BEGINNING_LINE = 1; cvs server: Diffing org/python/parser Index: org/python/parser/SimpleNode.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/parser/SimpleNode.java,v retrieving revision 2.17 diff -u -r2.17 SimpleNode.java --- org/python/parser/SimpleNode.java 2001/11/27 13:51:38 2.17 +++ org/python/parser/SimpleNode.java 2001/12/20 20:56:44 @@ -277,6 +277,8 @@ return visitor.mul_2op(this); case PythonGrammarTreeConstants.JJTDIV_2OP: return visitor.div_2op(this); + case PythonGrammarTreeConstants.JJTFLOORDIV_2OP: + return visitor.floordiv_2op(this); case PythonGrammarTreeConstants.JJTMOD_2OP: return visitor.mod_2op(this); case PythonGrammarTreeConstants.JJTPOS_1OP: @@ -337,6 +339,8 @@ return visitor.aug_multiply(this); case PythonGrammarTreeConstants.JJTAUG_DIVIDE: return visitor.aug_divide(this); + case PythonGrammarTreeConstants.JJTAUG_FLOORDIVIDE: + return visitor.aug_floordivide(this); case PythonGrammarTreeConstants.JJTAUG_MODULO: return visitor.aug_modulo(this); case PythonGrammarTreeConstants.JJTAUG_AND: Index: org/python/parser/Visitor.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/parser/Visitor.java,v retrieving revision 2.5 diff -u -r2.5 Visitor.java --- org/python/parser/Visitor.java 2001/10/28 17:13:44 2.5 +++ org/python/parser/Visitor.java 2001/12/20 20:56:45 @@ -214,6 +214,10 @@ throw new ParseException("Unhandled Node: "+n); } + public Object floordiv_2op(SimpleNode n) throws Exception { + throw new ParseException("Unhandled Node: "+n); + } + public Object mod_2op(SimpleNode n) throws Exception { throw new ParseException("Unhandled Node: "+n); } @@ -339,6 +343,10 @@ } public Object aug_divide(SimpleNode n) throws Exception { + throw new ParseException("Unhandled Node: "+n); + } + + public Object aug_floordivide(SimpleNode n) throws Exception { throw new ParseException("Unhandled Node: "+n); } Index: org/python/parser/python.jjt =================================================================== RCS file: /cvsroot/jython/jython/org/python/parser/python.jjt,v retrieving revision 2.16 diff -u -r2.16 python.jjt --- org/python/parser/python.jjt 2001/10/30 20:30:10 2.16 +++ org/python/parser/python.jjt 2001/12/20 20:56:47 @@ -243,6 +243,7 @@ | < MINUS: "-" > | < MULTIPLY: "*" > | < DIVIDE: "/" > +| < FLOORDIVIDE: "//" > | < POWER: "**" > | < LSHIFT: "<<" > | < RSHIFT: ">>" > @@ -263,6 +264,7 @@ | < MINUSEQ: "-=" > | < MULTIPLYEQ: "*=" > | < DIVIDEEQ: "/=" > +| < FLOORDIVIDEEQ: "//=" > | < MODULOEQ: "%=" > | < ANDEQ: "&=" > | < OREQ: "|=" > @@ -317,7 +319,7 @@ { < DECNUMBER: ["1"-"9"] (["0"-"9"])* (["j", "J", "l", "L"])? - | "0" ["j", "J"] + | "0" (["0"-"9"])* ["j", "J"] > | < HEXNUMBER: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ (["l","L"])? > | < OCTNUMBER: "0" (["0"-"7"])* (["l","L"])? > @@ -470,6 +472,7 @@ | SmartTestList() #aug_minus(2) | SmartTestList() #aug_multiply(2) | SmartTestList() #aug_divide(2) +| SmartTestList() #aug_floordivide(2) | SmartTestList() #aug_modulo(2) | SmartTestList() #aug_and(2) | SmartTestList() #aug_or(2) @@ -655,6 +658,7 @@ { factor() ( factor() #mul_2op(2) | factor() #div_2op(2) +| factor() #floordiv_2op(2) | factor() #mod_2op(2) )* } cvs server: Diffing org/python/rmi cvs server: Diffing org/python/util --- nul ? +++ org\python\core\PySeqIterator.java Sun Dec 09 12:01:54 2001 @@ -0,0 +1,24 @@ +package org.python.core; + +class PySeqIterator extends PyObject { + private PyObject seq; + private int idx; + + public PySeqIterator(PyObject seq) { + this.seq = seq; + this.idx = 0; + } + + public PyObject __iter__() { + return this; + } + + public PyObject __iternext__() { + return seq.__finditem__(idx++); + } + + public PyObject next() { + return __iternext__(); + } +} + --- nul ? +++ org\python\core\PyCallIterator.java Sun Dec 09 12:01:27 2001 @@ -0,0 +1,35 @@ +package org.python.core; + +public class PyCallIterator extends PyObject { + private PyObject callable; + private PyObject sentinel; + private int idx; + + public PyCallIterator(PyObject callable, PyObject sentinel) { + this.callable = callable; + this.sentinel = sentinel; + } + + public PyObject __iter__() { + return this; + } + + public PyObject __iternext__() { + PyObject val = null; + try { + val = callable.__call__(); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIterator)) + return null; + throw exc; + } + if (val.__eq__(sentinel).__nonzero__()) + return null; + return val; + } + + public PyObject next() { + return __iternext__(); + } +} +