From: <pj...@us...> - 2009-10-16 03:34:18
|
Revision: 6863 http://jython.svn.sourceforge.net/jython/?rev=6863&view=rev Author: pjenvey Date: 2009-10-16 03:34:01 +0000 (Fri, 16 Oct 2009) Log Message: ----------- make the exposed methods final, cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyGenerator.java Modified: trunk/jython/src/org/python/core/PyGenerator.java =================================================================== --- trunk/jython/src/org/python/core/PyGenerator.java 2009-10-16 02:41:41 UTC (rev 6862) +++ trunk/jython/src/org/python/core/PyGenerator.java 2009-10-16 03:34:01 UTC (rev 6863) @@ -1,3 +1,4 @@ +/* Copyright (c) Jython Developers */ package org.python.core; import org.python.expose.ExposedGet; @@ -30,8 +31,12 @@ generatorExit = Py.makeException(Py.GeneratorExit); } + public PyObject send(PyObject value) { + return generator_send(value); + } + @ExposedMethod - public PyObject send(PyObject value) { + final PyObject generator_send(PyObject value) { if (gi_frame == null) { throw Py.StopIteration(""); } @@ -42,8 +47,12 @@ return next(); } + public PyObject throw$(PyObject type, PyObject value, PyObject tb) { + return generator_throw$(type, value, tb); + } + @ExposedMethod(names="throw", defaults={"null", "null"}) - public PyObject throw$(PyObject type, PyObject value, PyObject tb) { + final PyObject generator_throw$(PyObject type, PyObject value, PyObject tb) { if (tb == Py.None) { tb = null; } else if (tb != null && !(tb instanceof PyTraceback)) { @@ -52,8 +61,12 @@ return raiseException(Py.makeException(type, value, tb)); } + public PyObject close() { + return generator_close(); + } + @ExposedMethod - public PyObject close() { + final PyObject generator_close() { try { raiseException(generatorExit); throw Py.RuntimeError("generator ignored GeneratorExit"); @@ -66,14 +79,22 @@ } @Override + public PyObject next() { + return generator_next(); + } + @ExposedMethod(doc="x.next() -> the next value, or raise StopIteration") - public PyObject next() { + final PyObject generator_next() { return super.next(); } @Override + public PyObject __iter__() { + return generator___iter__(); + } + @ExposedMethod - public PyObject __iter__() { + final PyObject generator___iter__() { return this; } @@ -87,37 +108,39 @@ @Override protected void finalize() throws Throwable { - if (gi_frame == null || gi_frame.f_lasti == -1) + if (gi_frame == null || gi_frame.f_lasti == -1) { return; + } try { close(); - } catch (PyException e) { + } catch (PyException pye) { // PEP 342 specifies that if an exception is raised by close, // we output to stderr and then forget about it; - String className = PyException.exceptionClassName(e.type); + String className = PyException.exceptionClassName(pye.type); int lastDot = className.lastIndexOf('.'); if (lastDot != -1) { className = className.substring(lastDot + 1); } - String msg = String.format("Exception %s: %s in %s", className, e.value.__repr__() - .toString(), __repr__().toString()); + String msg = String.format("Exception %s: %s in %s", className, pye.value.__repr__(), + __repr__()); Py.println(Py.getSystemState().stderr, Py.newString(msg)); - } catch (Throwable e) { + } catch (Throwable t) { // but we currently ignore any Java exception completely. perhaps we // can also output something meaningful too? } finally { super.finalize(); } } - + @Override public PyObject __iternext__() { return __iternext__(Py.getThreadState()); } public PyObject __iternext__(ThreadState state) { - if (gi_running) + if (gi_running) { throw Py.ValueError("generator already executing"); + } if (gi_frame == null) { return null; } @@ -130,12 +153,12 @@ PyObject result = null; try { result = gi_frame.f_code.call(state, gi_frame, closure); - } catch(PyException e) { - if (!(e.type == Py.StopIteration || e.type == Py.GeneratorExit)) { + } catch (PyException pye) { + if (!(pye.type == Py.StopIteration || pye.type == Py.GeneratorExit)) { gi_frame = null; - throw e; + throw pye; } else { - stopException = e; + stopException = pye; gi_frame = null; return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |