[Jython-checkins] jython: Extract ifilterfalse.

frank.wierzbicki jython-checkins at python.org
Fri Apr 27 07:13:40 CEST 2012


http://hg.python.org/jython/rev/2dba82856f12
changeset:   6630:2dba82856f12
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Thu Apr 26 22:13:32 2012 -0700
summary:
  Extract ifilterfalse.

files:
  src/org/python/modules/itertools/ifilterfalse.java |  72 ++++++++++
  src/org/python/modules/itertools/itertools.java    |  15 +-
  2 files changed, 73 insertions(+), 14 deletions(-)


diff --git a/src/org/python/modules/itertools/ifilterfalse.java b/src/org/python/modules/itertools/ifilterfalse.java
new file mode 100644
--- /dev/null
+++ b/src/org/python/modules/itertools/ifilterfalse.java
@@ -0,0 +1,72 @@
+/* Copyright (c) Jython Developers */
+package org.python.modules.itertools;
+import org.python.core.ArgParser;
+import org.python.core.Py;
+import org.python.core.PyIterator;
+import org.python.core.PyObject;
+import org.python.core.PyString;
+import org.python.core.PyTuple;
+import org.python.core.PyType;
+import org.python.expose.ExposedClassMethod;
+import org.python.expose.ExposedGet;
+import org.python.expose.ExposedNew;
+import org.python.expose.ExposedMethod;
+import org.python.expose.ExposedType;
+
+import java.util.ArrayList;
+
+ at ExposedType(name = "itertools.ifilterfalse", base = PyObject.class)
+public class ifilterfalse extends PyObject {
+
+    public static final PyType TYPE = PyType.fromClass(ifilterfalse.class);
+    private PyIterator iter;
+
+    public ifilterfalse() {
+        super();
+    }
+
+    public ifilterfalse(PyType subType) {
+        super(subType);
+    }
+
+    public ifilterfalse(PyObject predicate, PyObject iterable) {
+        super();
+        ifilterfalse___init__(predicate, iterable);
+    }
+
+    @ExposedGet
+    public static PyString __doc__ = new PyString(
+            "'ifilterfalse(function or None, sequence) --> ifilterfalse object\n\n"
+                    + "Return those items of sequence for which function(item) is false.\nIf function is None, "
+                    + "return the items that are false.'");
+
+    /**
+     * Creates an iterator that returns the items of the iterable for which
+     * <code>predicate(item)</code> is <code>false</code>. If <code>predicate</code> is null
+     * (None) return the items that are false.
+     */
+    @ExposedNew
+    @ExposedMethod
+    final void ifilterfalse___init__(PyObject[] args, String[] kwds) {
+        ArgParser ap = new ArgParser("ifilterfalse", args, kwds, "predicate", "iterable");
+        ap.noKeywords();
+        PyObject predicate = ap.getPyObject(0);
+        PyObject iterable = ap.getPyObject(1);
+        ifilterfalse___init__(predicate, iterable);
+    }
+
+    public void ifilterfalse___init__(PyObject predicate, PyObject iterable) {
+        iter = new itertools.FilterIterator(predicate, iterable, false);
+    }
+
+    @ExposedMethod
+    public PyObject __iter__() {
+        return iter;
+    }
+
+    @ExposedMethod
+    public PyObject next() {
+        return iter.next();
+    }
+
+}
diff --git a/src/org/python/modules/itertools/itertools.java b/src/org/python/modules/itertools/itertools.java
--- a/src/org/python/modules/itertools/itertools.java
+++ b/src/org/python/modules/itertools/itertools.java
@@ -85,6 +85,7 @@
         dict.__setitem__("chain", chain.TYPE);
         dict.__setitem__("imap", imap.TYPE);
         dict.__setitem__("ifilter", ifilter.TYPE);
+        dict.__setitem__("ifilterfalse", ifilterfalse.TYPE);
         dict.__setitem__("izip", izip.TYPE);
 
         // Hide from Python
@@ -367,20 +368,6 @@
         }
     }
 
-    public static PyString __doc__ifilterfalse = new PyString(
-            "'ifilterfalse(function or None, sequence) --> ifilterfalse object\n\n"
-                    + "Return those items of sequence for which function(item) is false.\nIf function is None, "
-                    + "return the items that are false.'");
-
-    /**
-     * Creates an iterator that returns the items of the iterable for which
-     * <code>predicate(item)</code> is <code>false</code>. If <code>predicate</code> is null
-     * (None) return the items that are false.
-     */
-    public static PyIterator ifilterfalse(PyObject predicate, PyObject iterable) {
-        return new FilterIterator(predicate, iterable, false);
-    }
-
     public static PyString __doc__starmap = new PyString(
             "starmap(function, sequence) --> starmap object\n\nReturn an "
                     + "iterator whose values are returned from the function evaluated\nwith an argument tuple taken from the "

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list