/** * Determine whether obj is a Python 3 exception class * * @param obj a PyObject * @return true if an exception */ private static boolean isPy3kExceptionClass(PyObject obj) { if (!(obj instanceof PyType)) { return false; } PyType type = ((PyType)obj); if (type.isSubType(PyBaseException.TYPE)) { return true; } return type.getProxyType() != null && Throwable.class.isAssignableFrom(type.getProxyType()); }
continue; Class<?> proxy = ((PyType)base).getProxyType(); if (proxy == null) { continue;
protected Class<?> resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException { String clsName = v.getName(); if (clsName.startsWith("org.python.proxies")) { int idx = clsName.lastIndexOf('$'); if (idx > 19) { clsName = clsName.substring(19, idx); } idx = clsName.indexOf('$'); if (idx >= 0) { String mod = clsName.substring(0, idx); clsName = clsName.substring(idx + 1); PyObject module = importModule(mod); PyType pycls = (PyType)module.__getattr__(clsName.intern()); return pycls.getProxyType(); } } try { return super.resolveClass(v); } catch (ClassNotFoundException exc) { PyObject m = importModule(clsName); Object cls = m.__tojava__(Class.class); if (cls != null && cls != Py.NoConversion) { return (Class<?>)cls; } throw exc; } }
continue; Class<?> proxy = ((PyType)base).getProxyType(); if (proxy == null) {
Class<?> c = getType().getProxyType(); Object javaProxy = JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); if (javaProxy != null || c == null) {
throw Py.TypeError("invalid self argument to constructor"); Class<?> javaClass = self.getType().getProxyType(); if (javaClass == null) { throw Py.TypeError("self invalid - must be a Java subclass [self=" + self + "]");
@Override public Object decode(final Object object) { if (object instanceof PyNone) return null; if (object instanceof PyBoolean) { return ((PyBoolean) object).getBooleanValue(); } if (object instanceof PyInteger) { return ((PyInteger) object).getValue(); } if (object instanceof PyFloat) { return ((PyFloat) object).getValue(); } if (object instanceof PyString) { return ((PyString) object).getString(); } if (object instanceof PyObject) { // Unwrap Python objects when they wrap Java ones. final PyObject pyObj = (PyObject) object; final Class<?> javaType = pyObj.getType().getProxyType(); if (javaType != null) return pyObj.__tojava__(javaType); } return object; }