private static int signedInt(long x) { if (x >= 2147483648L && x < 4294967296L) { return (int)(x - 4294967296L); } else if (x >= 0) { return (int)x; } else { throw Py.ValueError("invalid storage"); } }
/** * Convenience method providing the exception when an method requires the file to be open, and * it isn't. * * @return ValueError to throw */ private PyException closedValueError() { return Py.ValueError("I/O operation on closed file"); }
public synchronized void release() { if (locked) { locked = false; notifyAll(); } else { throw Py.ValueError("lock not acquired"); } }
/** * Return a ready-to-throw exception indicating an unpaired surrogate. * * @param p index within that sequence of the problematic code unit * @param c the code unit * @return an exception */ private static PyException unpairedSurrogate(int p, int c) { String fmt = "unpaired surrogate %#4x at code unit %d"; String msg = String.format(fmt, c, p); return Py.ValueError(msg); }
@ExposedMethod final void array_fromunicode(PyObject input) { if (!(input instanceof PyUnicode)) { throw Py.ValueError("fromunicode argument must be an unicode object"); } if (!"u".equals(typecode)) { throw Py.ValueError("fromunicode() may only be called on type 'u' arrays"); } extend(input); }
@ExposedGet(name = "cell_contents") public PyObject getCellContents() { if (ob_ref == null) { throw Py.ValueError("Cell is empty"); } return ob_ref; }
public static CompileMode getMode(String mode) { if (!mode.equals("exec") && !mode.equals("eval") && !mode.equals("single")) { throw Py.ValueError("compile() arg 3 must be 'exec' or 'eval' or 'single'"); } return valueOf(mode); } }
private void load_proto() { int proto = file.read(1).charAt(0); if (proto < 0 || proto > 2) throw Py.ValueError("unsupported pickle protocol: " + proto); }
public static PyFrame _getframe(int depth) { PyFrame f = Py.getFrame(); while (depth > 0 && f != null) { f = f.f_back; --depth; } if (f == null) { throw Py.ValueError("call stack is not deep enough"); } return f; }
Object unpack(ByteStream buf) { int bits = LEreadInt(buf); float v = Float.intBitsToFloat(bits); if (PyFloat.float_format == PyFloat.Format.UNKNOWN && ( Float.isInfinite(v) || Float.isNaN(v))) { throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); } return Py.newFloat(v); } }
static void raise_errmsg(String msg, PyObject s, PyObject pos, PyObject end) { /* Use the Python function json.decoder.errmsg to raise a nice looking ValueError exception */ final PyObject errmsg_fn = get_errmsg_fn(); if (errmsg_fn != null) { throw Py.ValueError(errmsg_fn.__call__(Py.newString(msg), s, pos, end).asString()); } else { throw Py.ValueError(msg); } }
@ExposedMethod public final int array_index(PyObject value) { int index = indexInternal(value); if (index != -1) { return index; } throw Py.ValueError("array.index(" + value + "): " + value + " not found in array"); }
@ExposedMethod(doc = BuiltinDocs.unicode_format_doc) final PyObject unicode_format(PyObject[] args, String[] keywords) { try { return new PyUnicode(buildFormattedString(args, keywords, null, null)); } catch (IllegalArgumentException e) { throw Py.ValueError(e.getMessage()); } }
private SplitIterator newSplitIterator(PyUnicode sep, int maxsplit) { if (sep == null) { return new WhitespaceSplitIterator(maxsplit); } else if (sep.getCodePointCount() == 0) { throw Py.ValueError("empty separator"); } else { return new SepSplitIterator(sep, maxsplit); } }
@ExposedMethod public PyObject BZ2File_next(PyObject[] args, String[] kwds) { checkReadBufferInit(); if (buffer == null || buffer.closed()) { throw Py.ValueError("Cannot call next() on closed file"); } inIterMode = true; return null; }
public int compare(KV o1, KV o2) { int result; if (cmp != null && cmp != Py.None) { result = cmp.__call__(o1.key, o2.key).asInt(); } else { result = o1.key._cmp(o2.key); } if (this.list.gListAllocatedStatus >= 0) { throw Py.ValueError("list modified during sort"); } return result; }
final int tuple_index(PyObject value, int start, int stop) { int validStart = boundToSequence(start); int validStop = boundToSequence(stop); for (int i = validStart; i < validStop; i++) { if (array[i].equals(value)) { return i; } } throw Py.ValueError("tuple.index(x): x not in list"); }
public void checkIdxAndSetSlice(PySlice slice, PyObject value) { int[] indices = slice.indicesEx(len()); if ((slice.step != Py.None) && value.__len__() != indices[3]) { throw Py.ValueError(String.format("attempt to assign sequence of size %d to extended " + "slice of size %d", value.__len__(), indices[3])); } setSlice(indices[0], indices[1], indices[2], value); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rshift___doc) final PyObject long___rshift__(PyObject right) { if (!canCoerce(right)) { return null; } int rightv = coerceInt(right); if (rightv < 0) { throw Py.ValueError("negative shift count"); } return Py.newLong(getValue().shiftRight(rightv)); }
public static int indexOf(PyObject seq, PyObject item) { int i = 0; PyObject iter = seq.__iter__(); for (PyObject tmp = null; (tmp = iter.__iternext__()) != null; i++) { if (item._eq(tmp).__nonzero__()) { return i; } } throw Py.ValueError("sequence.index(x): x not in list"); }