final synchronized int list_index(PyObject o) { return _index(o, "list.index(x): x not in list", 0, size()); }
@ExposedMethod(doc = BuiltinDocs.list___len___doc) final synchronized int list___len__() { return size(); }
public int index(PyObject o, int start) { return list_index(o, start, size()); }
final synchronized int list_index(PyObject o, int start) { return _index(o, "list.index(x): x not in list", start, size()); }
@Override public synchronized Object[] toArray(Object[] a) { int size = size(); Class<?> type = a.getClass().getComponentType(); if (a.length < size) { a = (Object[])Array.newInstance(type, size); } for (int i = 0; i < size; i++) { a[i] = list.get(i).__tojava__(type); } if (a.length > size) { for (int i = size; i < a.length; i++) { a[i] = null; } } return a; }
@Override protected synchronized PyObject repeat(int count) { if (count < 0) { count = 0; } int size = size(); int newSize = size * count; if (count != 0 && newSize / count != size) { throw Py.MemoryError(""); } PyObject[] elements = list.toArray(new PyObject[size]); PyObject[] newList = new PyObject[newSize]; for (int i = 0; i < count; i++) { System.arraycopy(elements, 0, newList, i * size, size); } return new PyList(newList); }
@Override public Object invokeGet(PyObject obj) { PyList weakrefs = WeakrefModule.getweakrefs(obj); switch (weakrefs.size()) { case 0: return Py.None; case 1: return weakrefs.pyget(0); default: return weakrefs; } }
@ExposedMethod(doc = BuiltinDocs.list_remove_doc) final synchronized void list_remove(PyObject o) { del(_index(o, "list.remove(x): x not in list", 0, size())); gListAllocatedStatus = list.size(); }
@ExposedMethod(defaults = "-1", doc = BuiltinDocs.list_pop_doc) final synchronized PyObject list_pop(int n) { int length = size(); if (length == 0) { throw Py.IndexError("pop from empty list"); } if (n < 0) { n += length; } if (n < 0 || n >= length) { throw Py.IndexError("pop index out of range"); } PyObject v = list.remove(n); return v; }
private PyObject join_list(PyList list, PyString string) { PyObject joiner = string.__getslice__(Py.Zero, Py.Zero); if (list.size() == 0) { return joiner; } return joiner.__getattr__("join").__call__(list); }
public boolean enterRepr(PyObject obj) { if (reprStack == null) { reprStack = new PyList(new PyObject[] {obj}); return true; } for (int i = reprStack.size() - 1; i >= 0; i--) { if (obj == reprStack.pyget(i)) { return false; } } reprStack.append(obj); return true; }
@ExposedMethod(names = "__repr__") final synchronized String list_toString() { ThreadState ts = Py.getThreadState(); if (!ts.enterRepr(this)) { return "[...]"; } StringBuilder buf = new StringBuilder("["); int length = size(); int i = 0; for (PyObject item : list) { buf.append(item.__repr__().toString()); if (i < length - 1) { buf.append(", "); } i++; } buf.append("]"); ts.exitRepr(this); return buf.toString(); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___imul___doc) final synchronized PyObject list___imul__(PyObject o) { if (!o.isIndex()) { return null; } int count = o.asIndex(Py.OverflowError); int size = size(); if (size == 0 || count == 1) { return this; } if (count < 1) { clear(); return this; } if (size > Integer.MAX_VALUE / count) { throw Py.MemoryError(""); } int newSize = size * count; if (list instanceof ArrayList) { ((ArrayList) list).ensureCapacity(newSize); } List<PyObject> oldList = new ArrayList<PyObject>(list); for (int i = 1; i < count; i++) { list.addAll(oldList); } gListAllocatedStatus = list.size(); // now omit? return this; }
@ExposedMethod(defaults = {"null", "null"}, doc = BuiltinDocs.list_index_doc) final synchronized int list_index(PyObject o, PyObject start, PyObject stop) { int startInt = start == null ? 0 : PySlice.calculateSliceIndex(start); int stopInt = stop == null ? size() : PySlice.calculateSliceIndex(stop); return list_index(o, startInt, stopInt); }
PyDictionary inputs = (PyDictionary) process(engine).__getattr__("inputs"); if (args.size() != inputs.size()) { throw new RuntimeException( String.format( "process function specified %d arguments but" + " describes %d inputs", args.size(), inputs.size())); for (int i = 0; i < args.size(); i++) { String arg = args.get(i).toString(); PyTuple input = (PyTuple) inputs.get(arg); int defaultIdx = defaults.size() - (args.size() - i); if (defaultIdx >= 0) { defaultValue = defaults.get(defaultIdx);
if (other.getType().isSubType(PyList.TYPE)) { PyList oList = (PyList) other; if (jList.size() != oList.size()) { return Py.False;
@ExposedNew public static PyObject StructLayout_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("__init__", args, keywords, new String[] { "fields", "union" }, 1); if (!(ap.getPyObject(0) instanceof PyList)) { throw Py.TypeError("expected list of jffi.StructLayout.Field"); } PyList pyFields = (PyList) ap.getPyObject(0); Field[] fields = new Field[pyFields.size()]; for (int i = 0; i < fields.length; ++i) { PyObject pyField = pyFields.pyget(i); if (!(pyField instanceof Field)) { throw Py.TypeError(String.format("element %d of field list is not an instance of jffi.StructLayout.Field", i)); } fields[i] = (Field) pyField; } return StructUtil.newStructLayout(fields, ap.getPyObject(1, Py.False).__nonzero__()); }
for (i = 0; i < ((PyList)names).size(); i++) { PyObject name = ((PyList)names).pyget(i); PyObject value = this.__findattr__(name.toString());