Exemplo n.º 1
0
  final void file_writelines(PyObject a) {
    PyObject iter = Py.iter(a, "writelines() requires an iterable argument");

    PyObject item = null;
    while ((item = iter.__iternext__()) != null) {
      if (!(item instanceof PyString))
        throw Py.TypeError("writelines() argument must be a " + "sequence of strings");
      write(item.toString());
    }
  }
Exemplo n.º 2
0
  // Return a copy of a sequence where the __len__() method is
  // telling the thruth.
  protected static PyObject fastSequence(PyObject seq, String msg) {
    if (seq instanceof PyList || seq instanceof PyTuple) return seq;

    if (!seq.isSequenceType()) throw Py.TypeError(msg);

    PyList list = new PyList();
    PyObject iter = Py.iter(seq, msg);
    for (PyObject item = null; (item = iter.__iternext__()) != null; ) {
      list.append(item);
    }
    return list;
  }