Package org.python.core

Examples of org.python.core.PyIterator


    /**
     * Creates an iterator that returns consecutive integers starting at <code>init</code>.
     */
    public static PyIterator count(final int init) {
        return new PyIterator() {
            int counter = init;

            public PyObject __iternext__() {
                return new PyInteger(counter++);
            }
View Full Code Here


    /**
     * Creates an iterator that returns the same object the number of times given by
     * <code>times</code>.
     */
    public static PyIterator repeat(final PyObject object, final int times) {
        return new PyIterator() {
            int counter = times;

            public PyObject __iternext__() {
                if (counter > 0) {
                    counter--;
View Full Code Here

    /**
     * Creates an iterator that returns the same object over and over again.
     */
    public static PyIterator repeat(final PyObject object) {
        return new PyIterator() {
            public PyObject __iternext__() {
                return object;
            }
                       
            public PyString __repr__() {
View Full Code Here

        for (int j = 0; j < n; j++) {
            iters[j] = Py.iter(argstar[j + 1], "argument " + (j + 1)
                    + " to imap() must support iteration");
        }

        return new PyIterator() {
            PyObject[] args = new PyObject[n];

            PyObject element = null;

            public PyObject __iternext__() {
View Full Code Here

        callArgs[i] = arg;
        i++;
      }
    }
    if (contextKwArgs != null) {
      PyIterator values = (PyIterator) contextKwArgs.itervalues();
      PyObject value = values.__iternext__();
      while (value != null) {
        callArgs[i] = value;
        value = values.__iternext__();
        i++;
      }

      contextKwArgsNames = new String[contextKwArgs.size()];
      PyIterator keys = (PyIterator) contextKwArgs.iterkeys();
      PyObject key = keys.__iternext__();
      int j = 0;
      while (key != null) {
        contextKwArgsNames[j] = ((PyString) key).asString();
        key = keys.__iternext__();
        j++;
      }
    }
  }
View Full Code Here

                        }
                    }
                });
            }
            else if (ret instanceof PyIterator) {
                final PyIterator iter = (PyIterator) ret;
                getResponse().setEntity(new OutputRepresentation(mediaType) {
                   
                    @Override
                    public void write(OutputStream outputStream) throws IOException {
                        for (Iterator i = iter.iterator(); i.hasNext();) {
                            outputStream.write(i.next().toString().getBytes());
                            outputStream.write('\n');
                        }
                    }
                });
View Full Code Here

                            }
                        }
                    });
                }
                else if (ret instanceof PyIterator) {
                    final PyIterator iter = (PyIterator) ret;
                    response.setEntity(new OutputRepresentation(mediaType) {
   
                        @Override
                        public void write(OutputStream outputStream) throws IOException {
                            for (Iterator i = iter.iterator(); i.hasNext();) {
                                outputStream.write(i.next().toString().getBytes());
                                outputStream.write('\n');
                            }
                        }
                    });
                }
                else if (ret instanceof PyObjectDerived) {
                    final PyObjectDerived iter = (PyObjectDerived)ret;
                    response.setEntity(new OutputRepresentation(mediaType) {
   
                        @Override
                        public void write(OutputStream outputStream) throws IOException {
                            PyObject next = null;
                            while ((next = iter.__iternext__()) != null) {
                                outputStream.write(next.toString().getBytes());
                                outputStream.write('\n');
                            }
                        }
                    });
View Full Code Here

                        }
                    }
                });
            }
            else if (ret instanceof PyIterator) {
                final PyIterator iter = (PyIterator) ret;
                getResponse().setEntity(new OutputRepresentation(mediaType) {
                   
                    @Override
                    public void write(OutputStream outputStream) throws IOException {
                        for (Iterator i = iter.iterator(); i.hasNext();) {
                            outputStream.write(i.next().toString().getBytes());
                            outputStream.write('\n');
                        }
                    }
                });
View Full Code Here

TOP

Related Classes of org.python.core.PyIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.