@Override public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom // exceptions (such as subclasses of KeyError). // // We are forced to duplicate the code, instead of defining __finditem__ // in terms of __getitem__. That's because PyObject defines __getitem__ // in terms of __finditem__. Therefore, we would end with an infinite // loop when self_type.lookup("__getitem__") returns null: // // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ // // By duplicating the (short) lookup and call code, we are safe, because // the call chains will be: // // __finditem__ -> super.__finditem__ // // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ PyType self_type = getType(); PyObject impl = self_type.lookup("__getitem__"); if (impl != null) { return impl.__get__(this, self_type).__call__(key); } return super.__getitem__(key); }
public void __del_derived__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__del__"); if (impl != null) { impl.__get__(this, self_type).__call__(); } }
public PyObject custom_event(PyType event) { Class<?> proxy = event.getProxyType(); if (Event.class.isAssignableFrom(proxy)) { // add the stupid handler list attribute and get handler list method // which the bukkit team could not add themselves for some strange reason // event.__setattr__("handlerList", Py.java2py(new HandlerList())); // ((PyType)event.getBase()).addMethod(new // PyBuiltinClassMethodNarrow("getHandlerList", 0, 0) { // @Override // public PyObject __call__() { // return self.__getattr__("handlerList"); // } // }); // event.addMethod(new PyBuiltinClassMethodNarrow("getHandlers", 0, 0) { // @Override // public PyObject __call__() { // return self.__getattr__("handlerList"); // } // }); customEvents.put(event.getName(), (Class<? extends Event>) proxy); } else { throw new IllegalArgumentException( "Tried to register a custom Event which does not extend Event"); } return event; }
public PyObject __iter__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__iter__"); if (impl != null) return impl.__get__(this, self_type).__call__(); impl = self_type.lookup("__getitem__"); if (impl == null) return super.__iter__(); return new PySequenceIter(this); }
public PyObject __call__(PyObject args[], String keywords[]) { PyType self_type = getType(); PyObject impl = self_type.lookup("__call__"); if (impl != null) { return impl.__get__(this, self_type).__call__(args, keywords); } return super.__call__(args, keywords); }
public combinationsWithReplacementDerived(PyType subtype) { super(subtype); slots = new PyObject[subtype.getNumSlots()]; dict = subtype.instDict(); if (subtype.needsFinalizer()) { FinalizeTrigger.ensureFinalizer(this); } }
public int __len__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__len__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(); return res.asInt(); } return super.__len__(); }
public void __delete__(PyObject obj) { PyType self_type = getType(); PyObject impl = self_type.lookup("__delete__"); if (impl != null) { impl.__get__(this, self_type).__call__(obj); return; } super.__delete__(obj); }
public void __delitem__(PyObject key) { // ??? PyType self_type = getType(); PyObject impl = self_type.lookup("__delitem__"); if (impl != null) { impl.__get__(this, self_type).__call__(key); return; } super.__delitem__(key); }
@Override public PyObject __dir__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__dir__"); if (impl != null) { return impl.__get__(this, self_type).__call__(); } return super.__dir__(); }
@Override public boolean __contains__(PyObject o) { PyType self_type = getType(); PyObject impl = self_type.lookup("__contains__"); if (impl == null) { return super.__contains__(o); } return impl.__get__(this, self_type).__call__(o).__nonzero__(); }
public void __delattr__(String name) { PyType self_type = getType(); PyObject impl = self_type.lookup("__delattr__"); if (impl != null) { impl.__get__(this, self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); }
public PyObject __ixor__(PyObject other) { PyType self_type = getType(); PyObject impl = self_type.lookup("__ixor__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(other); if (res == Py.NotImplemented) return null; return res; } return super.__ixor__(other); }
@Override public PyObject write(PyObject b) { PyType self_type = getType(); PyObject impl = self_type.lookup("write"); if (impl != null) { return impl.__get__(this, self_type).__call__(b); } else { return super.write(b); } }
@Override public long truncate() { PyType self_type = getType(); PyObject impl = self_type.lookup("truncate"); if (impl != null) { return impl.__get__(this, self_type).__call__().asLong(); } else { return super.truncate(); } }
@Override public void writelines(PyObject lines) { PyType self_type = getType(); PyObject impl = self_type.lookup("writelines"); if (impl != null) { impl.__get__(this, self_type).__call__(lines); } else { super.writelines(lines); } }
@Override public PyObject readline() { PyType self_type = getType(); PyObject impl = self_type.lookup("readline"); if (impl != null) { return impl.__get__(this, self_type).__call__(Py.None); } else { return super.readline(); } }
@Override public boolean isatty() { PyType self_type = getType(); PyObject impl = self_type.lookup("isatty"); if (impl != null) { return impl.__get__(this, self_type).__call__().__nonzero__(); } else { return super.isatty(); } }
@Override public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { PyType self_type = getType(); PyObject impl = self_type.lookup("__exit__"); if (impl != null) { return impl.__get__(this, self_type).__call__(type, value, traceback).__nonzero__(); } else { return super.__exit__(type, value, traceback); } }
public PyObject __int__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__int__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(); if (res instanceof PyInteger || res instanceof PyLong) return res; throw Py.TypeError("__int__" + " should return an integer"); } return super.__int__(); }
@Override public PyObject read(int n) { PyType self_type = getType(); PyObject impl = self_type.lookup("read"); if (impl != null) { return impl.__get__(this, self_type).__call__(Py.newInteger(n)); } else { return super.read(n); } }
@Override public void close() { PyType self_type = getType(); PyObject impl = self_type.lookup("close"); if (impl != null) { impl.__get__(this, self_type).__call__(); } else { super.close(); } }
public PyObject __get__(PyObject obj, PyObject type) { PyType self_type = getType(); PyObject impl = self_type.lookup("__get__"); if (impl != null) { if (obj == null) obj = Py.None; if (type == null) type = Py.None; return impl.__get__(this, self_type).__call__(obj, type); } return super.__get__(obj, type); }
@Override public void __set__(PyObject obj, PyObject value) { PyType self_type = getType(); PyObject impl = self_type.lookup("__set__"); if (impl != null) { impl.__get__(this, self_type).__call__(obj, value); return; } super.__set__(obj, value); }
public int __len__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__len__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(); if (res instanceof PyInteger) return ((PyInteger) res).getValue(); throw Py.TypeError("__len__ should return a int"); } return super.__len__(); }
public Object __coerce_ex__(PyObject o) { PyType self_type = getType(); PyObject impl = self_type.lookup("__coerce__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(o); if (res == Py.NotImplemented) return Py.None; if (!(res instanceof PyTuple)) throw Py.TypeError("__coerce__ didn't return a 2-tuple"); return ((PyTuple) res).getArray(); } return super.__coerce_ex__(o); }
public PyFloat __float__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__float__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(); if (res instanceof PyFloat) return (PyFloat) res; throw Py.TypeError( "__float__" + " returned non-" + "float" + " (type " + res.getType().fastGetName() + ")"); } return super.__float__(); }
@Override public PyObject readlines(PyObject hint) { PyType self_type = getType(); PyObject impl = self_type.lookup("readlines"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(hint); return res; } else { return super.readlines(hint); } }
@Override public void _checkClosed(String msg) { PyType self_type = getType(); PyObject impl = self_type.lookup("_checkClosed"); if (impl != null) { PyObject pymsg = msg == null ? Py.None : new PyString(msg); impl.__get__(this, self_type).__call__(pymsg); } else { super._checkClosed(msg); } }
public PyUnicode __unicode__() { PyType self_type = getType(); PyObject impl = self_type.lookup("__unicode__"); if (impl != null) { PyObject res = impl.__get__(this, self_type).__call__(); if (res instanceof PyUnicode) return (PyUnicode) res; if (res instanceof PyString) return new PyUnicode((PyString) res); throw Py.TypeError("__unicode__" + " should return a " + "unicode"); } return super.__unicode__(); }