@Override public int __len__() { try { if (model instanceof TemplateSequenceModel) { return ((TemplateSequenceModel) model).size(); } if (model instanceof TemplateHashModelEx) { return ((TemplateHashModelEx) model).size(); } } catch (TemplateModelException e) { throw Py.JavaError(e); } return 0; }
@Override public boolean __nonzero__() { try { if (model instanceof TemplateBooleanModel) { return ((TemplateBooleanModel) model).getAsBoolean(); } if (model instanceof TemplateSequenceModel) { return ((TemplateSequenceModel) model).size() > 0; } if (model instanceof TemplateHashModel) { return !((TemplateHashModelEx) model).isEmpty(); } } catch (TemplateModelException e) { throw Py.JavaError(e); } return false; }
@Override public PyObject __call__(PyObject args[], String keywords[]) { if (model instanceof TemplateMethodModel) { boolean isEx = model instanceof TemplateMethodModelEx; List list = new ArrayList(args.length); try { for (int i = 0; i < args.length; ++i) { list.add( isEx ? (Object) wrap(args[i]) : (Object) ( args[i] == null ? null : args[i].toString())); } return unwrap((TemplateModel) ((TemplateMethodModelEx) model).exec(list)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("call of non-method model (" + getModelClass() + ")"); }
@Override public PyObject __finditem__(String key) { if (model instanceof TemplateHashModel) { try { return unwrap(((TemplateHashModel) model).get(key)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("item lookup on non-hash model (" + getModelClass() + ")"); }
@Override public PyObject __finditem__(int index) { if (model instanceof TemplateSequenceModel) { try { return unwrap(((TemplateSequenceModel) model).get(index)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("item lookup on non-sequence model (" + getModelClass() + ")"); }
public void _jthrow(Throwable t) { if (t instanceof RuntimeException) throw (RuntimeException) t; if (t instanceof Error) throw (Error) t; throw Py.JavaError(t); }
@Override public void close() { try { inputStream.close(); } catch (IOException e) { throw Py.JavaError(e); } } };
@Override public PyObject __call__(PyObject[] args, String[] kws) { Object[] margs = new Object[]{args, kws}; try { return Py.java2py(method.invoke(null, margs)); } catch (Throwable t) { throw Py.JavaError(t); } }
public static PyObject bindStaticJavaMethod(String name, Class<?> cls, String methodName) { Method javaMethod; try { javaMethod = cls.getMethod(methodName, new Class<?>[] {PyObject.class, PyObject[].class, String[].class}); } catch (Exception e) { throw Py.JavaError(e); } return new BoundStaticJavaMethod(name, javaMethod); }
public static PyObject newJavaFunc(Class<?> cls, String name) { try { Method m = cls.getMethod(name, new Class<?>[]{PyObject[].class, String[].class}); return new JavaFunc(m); } catch (NoSuchMethodException e) { throw Py.JavaError(e); } }
@Override public PyObject __call__(PyObject[] args, String kwargs[]) { try { return Py.java2py(javaMethod.invoke(null, self, args, kwargs)); } catch (Throwable t) { throw Py.JavaError(t); } } }
public boolean _doset(PyObject self, PyObject value) { Object jself = Py.tojava(self, addMethod.getDeclaringClass()); T jvalue = Py.tojava(value, eventClass); try { addMethod.invoke(jself, jvalue); } catch (Exception e) { throw Py.JavaError(e); } return true; }
public static void writeUnraisable(Throwable unraisable, PyObject obj) { PyException pye = JavaError(unraisable); stderr.println(String.format("Exception %s in %s ignored", formatException(pye.type, pye.value, true), obj)); }
private void setFunction(Object self, PyObject callable) { initAdapter(); try { adapterField.set(getAdapter(self), callable); } catch (Exception exc) { throw Py.JavaError(exc); } }
public static Class<?> makeAdapter(Class<?> c) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); AdapterMaker maker = new AdapterMaker(proxyPrefix + c.getName(), c); try { maker.build(bytes); } catch (Exception exc) { throw Py.JavaError(exc); } Py.saveClassFile(maker.myClass, bytes); return makeClass(c, null, maker.myClass, bytes); }
public static PyException setException(Throwable t, PyFrame frame) { PyException pye = Py.JavaError(t); pye.normalize(); pye.tracebackHere(frame); getThreadState().exception = pye; return pye; }
@Override public PyObject __finditem__(int index) { if (model instanceof TemplateSequenceModel) { try { return unwrap(((TemplateSequenceModel) model).get(index)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("item lookup on non-sequence model (" + getModelClass() + ")"); }
@Override public PyObject __finditem__(String key) { if (model instanceof TemplateHashModel) { try { return unwrap(((TemplateHashModel) model).get(key)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("item lookup on non-hash model (" + getModelClass() + ")"); }
@Override public PyObject __finditem__(int index) { if (model instanceof TemplateSequenceModel) { try { return unwrap(((TemplateSequenceModel) model).get(index)); } catch (TemplateModelException e) { throw Py.JavaError(e); } } throw Py.TypeError("item lookup on non-sequence model (" + getModelClass() + ")"); }