[Jython-checkins] jython: Missing new files for r7899
jim.baker
jython-checkins at python.org
Sat Feb 13 00:40:31 EST 2016
https://hg.python.org/jython/rev/78320ba69644
changeset: 7900:78320ba69644
user: Jim Baker <jim.baker at rackspace.com>
date: Fri Feb 12 22:40:12 2016 -0700
summary:
Missing new files for r7899
files:
src/org/python/core/PyListIterator.java | 49 ++++++++++++
src/org/python/core/PyTupleIterator.java | 23 +++++
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/src/org/python/core/PyListIterator.java b/src/org/python/core/PyListIterator.java
new file mode 100644
--- /dev/null
+++ b/src/org/python/core/PyListIterator.java
@@ -0,0 +1,49 @@
+package org.python.core;
+
+import org.python.expose.ExposedType;
+
+ at ExposedType(name = "listiterator", base = PyIterator.class, isBaseType = false)
+public class PyListIterator extends PyIterator {
+
+ public static final PyType TYPE = PyType.fromClass(PyListIterator.class);
+ private PyList list;
+ private boolean stopped = false;
+ private int index = 0;
+
+ public PyListIterator(PyList list) {
+ this.list = list;
+ }
+
+ public PyObject __iternext__() {
+ synchronized (list) {
+ if (stopped) {
+ // Need to prevent the iteration from restarting, even after a StopIteration,
+ // due to the list subsequently growing.
+ // Keeping track of this flag ensures that next(it) will throw StopIteration
+ // exceptions on all subsequent invocations.
+ return null;
+ } else if (index >= list.size()) {
+ stopped = true;
+ return null;
+ } else {
+ return list.pyget(index++);
+ }
+ }
+ }
+
+ /* Traverseproc implementation */
+ @Override
+ public int traverse(Visitproc visit, Object arg) {
+ int retValue = super.traverse(visit, arg);
+ if (retValue != 0) {
+ return retValue;
+ }
+ return list == null ? 0 : visit.visit(list, arg);
+ }
+
+ @Override
+ public boolean refersDirectlyTo(PyObject ob) {
+ return ob != null && (ob == list || super.refersDirectlyTo(ob));
+ }
+
+}
diff --git a/src/org/python/core/PyTupleIterator.java b/src/org/python/core/PyTupleIterator.java
new file mode 100644
--- /dev/null
+++ b/src/org/python/core/PyTupleIterator.java
@@ -0,0 +1,23 @@
+package org.python.core;
+
+import org.python.expose.ExposedType;
+import java.util.Iterator;
+
+ at ExposedType(name = "tupleiterator", base = PyIterator.class, isBaseType = false)
+public class PyTupleIterator extends PyIterator {
+
+ public static final PyType TYPE = PyType.fromClass(PyTupleIterator.class);
+ private Iterator<PyObject> iterator;
+
+ public PyTupleIterator(PyTuple tuple) {
+ iterator = tuple.getList().iterator();
+ }
+
+ public PyObject __iternext__() {
+ if (!iterator.hasNext()) {
+ return null;
+ } else {
+ return iterator.next();
+ }
+ }
+}
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list