public static final void checkBounds(long size, long off, long len) { if ((off | len | (off + len) | (size - (off + len))) < 0) { throw Py.IndexError("Memory access offset=" + off + " size=" + len + " is out of bounds"); } }
/** * Return the argument at the given index, raise an IndexError if out of range. */ public PyObject arg(int index) { if (index >= 0 && index <= arguments.length - 1) { return arguments[index]; } throw Py.IndexError("index out of range"); }
private PyObject removeNode(Node node) { // should ALWAYS be called inside a synchronized block if (node == header) { throw Py.IndexError("pop from an empty deque"); } PyObject obj = node.data; node.left.right = node.right; node.right.left = node.left; node.right = null; node.left = null; node.data = null; size--; state++; return obj; }
public PyObject checkIdxAndGetItem(PyObject idx) { PyObject res = checkIdxAndFindItem(idx); if (res == null) { throw Py.IndexError("index out of range: " + idx); } return res; }
@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 int checkIdx(int idx) { int i = fixindex(idx); if (i == -1) { throw Py.IndexError(getTypeName() + " assignment index out of range"); } return i; }
@ExposedMethod final PyObject astlist___getitem__(PyObject o) { PyObject ret = seq___finditem__(o); if(ret == null) { throw Py.IndexError("index out of range: " + o); } return ret; }
@ExposedMethod(doc = BuiltinDocs.str___getitem___doc) final PyObject str___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if (ret == null) { throw Py.IndexError("string index out of range"); } return ret; }
public PyObject start(PyObject index_) { int index = getindex(index_); if (index < 0 || index >= groups) throw Py.IndexError("no such group"); return Py.newInteger(mark[index*2]); }
public PyObject end(PyObject index_) { int index = getindex(index_); if (index < 0 || index >= groups) throw Py.IndexError("no such group"); return Py.newInteger(mark[index*2+1]); }
public PyTuple span(PyObject index_) { int index = getindex(index_); if (index < 0 || index >= groups) throw Py.IndexError("no such group"); int start = mark[index*2]; int end = mark[index*2+1]; return _pair(start, end); }
@ExposedMethod final PyObject array___getitem__(PyObject o) { PyObject ret = seq___finditem__(o); if (ret == null) { throw Py.IndexError("index out of range: " + o); } return ret; }
@ExposedMethod(doc = BuiltinDocs.xrange___getitem___doc) final PyObject xrange___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if (ret == null) { throw Py.IndexError("xrange object index out of range"); } return ret; }
@ExposedMethod(doc = BuiltinDocs.list___getitem___doc) final synchronized PyObject list___getitem__(PyObject o) { PyObject ret = seq___finditem__(o); if (ret == null) { throw Py.IndexError("index out of range: " + o); } return ret; }
@ExposedMethod(doc = BuiltinDocs.tuple___getitem___doc) final PyObject tuple___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if (ret == null) { throw Py.IndexError("index out of range: " + index); } return ret; }
/** * Check that an index is within the range of the array, that is <tt>0<=index<size</tt>. * * @param index to check * @throws PyException (IndexError) if the index is outside the array bounds */ protected final void indexCheck(int index) throws PyException { if (index < 0 || index >= size) { throw Py.IndexError(getType().fastGetName() + " index out of range"); } }
@ExposedMethod(defaults = "-1", doc = BuiltinDocs.bytearray_pop_doc) final synchronized PyInteger bytearray_pop(int i) { if (size == 0) { throw Py.IndexError("pop from empty list"); } else { // Deal with slice interpretation of single index if (i < 0) { i += size; } // Use List.remove(int) return remove(i); } }
@Override public PyObject __call__(PyObject index) { List jlist = asList(); if (jlist.isEmpty()) { throw Py.IndexError("pop from empty list"); } ListIndexDelegate ldel = new ListIndexDelegate(jlist); PyObject item = ldel.checkIdxAndFindItem(index.asInt()); if (item == null) { throw Py.IndexError("pop index out of range"); } else { ldel.checkIdxAndDelItem(index); return item; } } };
private PyObject getslice_by_index(int index, PyObject def) { if (index < 0 || index >= groups) throw Py.IndexError("no such group"); index *= 2; int start = mark[index]; int end = mark[index+1]; //System.out.println("group:" + index + " " + start + " " + // end + " l:" + string.length()); if (string == null || start < 0) return def; return string.__getslice__(Py.newInteger(start), Py.newInteger(end)); }
public static void SyntaxError__init__(PyObject self, PyObject[] args, String[] kwargs) { PyBaseException.TYPE.invoke("__init__", self, args, kwargs); initSlots(self); if (args.length >= 1) { self.__setattr__("msg", args[0]); } if (args.length == 2) { PyObject[] info = Py.make_array(args[1]); if (info.length != 4) { throw Py.IndexError("tuple index out of range"); } self.__setattr__("filename", info[0]); self.__setattr__("lineno", info[1]); self.__setattr__("offset", info[2]); self.__setattr__("text", info[3]); } }