/** * Check that the value of an PyInteger is suitable for storage in a (Python) byte array, and * convert it to the Java byte value that can be stored there. (Java bytes run -128..127 whereas * Python bytes run 0..255.) * * @param value to convert. * @throws PyException (ValueError) if value<0 or value>255 */ protected static final byte byteCheck(PyInteger value) throws PyException { return byteCheck(value.asInt()); }
@Override public int hashCode() { return getPyObject().__hash__().asInt(); } }
boolean isInheritingFromAbstractProcessor = ((PyInteger) pyIsInheritingFromAbstractProcessor).asInt() != 0; if (!isInheritingFromAbstractProcessor)
/** * Test method for {@link org.python.core.BaseBytes#pyget(int)}. */ public void testPyget() { // Need interpreter interp = new PythonInterpreter(); // Fill and access via pyget int[] aRef = randomInts(random, MEDIUM); BaseBytes a = getInstance(aRef); for (int i = 0; i < MEDIUM; i++) { PyInteger r = a.pyget(i); // System.out.printf(" aRef[%2d]=%3d r=%3d\n", i, aRef[i], r.asInt()); assertEquals(aRef[i], r.asInt()); } // Check IndexError exceptions generated for (int i : new int[] {-1, -100, MEDIUM, MEDIUM + 1}) { try { PyInteger r = a.pyget(i); fail("Exception not thrown for pyget(" + i + ") =" + r); } catch (PyException pye) { assertEquals(Py.IndexError, pye.type); // System.out.printf(" Exception: %s\n", pye); } } }
PyInteger pyb = new PyInteger(b); a.__setitem__(i, pyb); int ai = a.pyget(i).asInt(); if (verbose >= 3) { System.out.printf(" __setitem__(%2d,%3d) : a[%2d]=%3d\n", i, b, i, ai);
} else if (v instanceof PyInteger) { write_byte(TYPE_INT); write_int(((PyInteger) v).asInt()); } else if (v instanceof PyLong) { write_byte(TYPE_LONG);