@Override public boolean isCallable() { return __findattr__("__call__") != null; }
@Override public boolean isNumberType() { return __findattr__("__int__") != null || __findattr__("__float__") != null; }
@Override public boolean isMappingType() { return __findattr__("__getitem__") != null; }
@Override public boolean isSequenceType() { return __findattr__("__getitem__") != null; }
@Override public boolean isIndex() { return __findattr__("__index__") != null; }
public PyObject invoke_ex(String name, PyObject[] args, String[] keywords) { PyObject meth = __findattr__(name); if (meth == null) return null; return meth.__call__(args, keywords); }
public PyObject invoke_ex(String name, PyObject arg1) { PyObject meth = __findattr__(name); if (meth == null) return null; return meth.__call__(arg1); }
public PyObject invoke_ex(String name) { PyObject meth = __findattr__(name); if (meth == null) return null; return meth.__call__(); }
public PyObject invoke_ex(String name, PyObject arg1, PyObject arg2) { PyObject meth = __findattr__(name); if (meth == null) return null; return meth.__call__(arg1, arg2); }
@ExposedMethod final PyObject instance___iter__() { PyObject func = __findattr__("__iter__"); if (func != null) return func.__call__(); func = __findattr__("__getitem__"); if (func == null) { return super.__iter__(); } return new PySequenceIter(this); }
@ExposedMethod final boolean instance___nonzero__() { PyObject meth = null; try { meth = __findattr__("__nonzero__"); } catch (PyException exc) { } if (meth == null) { try { meth = __findattr__("__len__"); } catch (PyException exc) { } if (meth == null) { return true; } } PyObject ret = meth.__call__(); return ret.__nonzero__(); }
@Override public void __del__() { try { PyObject method = __findattr__("__del__"); if (method != null) { method.__call__(); } else if (instclass.__del__ != null) { instclass.__del__.__call__(this); } } catch (PyException exc) { // Try to get the right method description. PyObject method = instclass.__del__; try { method = __findattr__("__del__"); } catch (PyException e) { // nothing we can do } Py.writeUnraisable(exc, method); } }
@ExposedMethod final PyObject instance___format__(PyObject formatSpec) { PyObject func = __findattr__("__format__"); if (func == null) { return super.__format__(formatSpec); } return func.__call__(formatSpec); }
private PyObject trySlice(String name, PyObject start, PyObject stop, PyObject extraArg) { PyObject func = __findattr__(name); if (func == null) { return null; } PyObject[] indices = PySlice.indices2(this, start, stop); start = indices[0]; stop = indices[1]; if (extraArg == null) { return func.__call__(start, stop); } else { return func.__call__(start, stop, extraArg); } }
@Override public PyObject __iternext__() { PyObject func = __findattr__("next"); if (func != null) { try { return func.__call__(); } catch (PyException exc) { if (exc.match(Py.StopIteration)) return null; throw exc; } } throw Py.TypeError("instance has no next() method"); }
@ExposedMethod final boolean instance___contains__(PyObject o) { PyObject func = __findattr__("__contains__"); if (func == null) return super.__contains__(o); PyObject ret = func.__call__(o); return ret.__nonzero__(); }
@Override public int hashCode() { PyObject ret; ret = invoke_ex("__hash__"); if (ret == null) { if (__findattr__("__eq__") != null || __findattr__("__cmp__") != null) { throw Py.TypeError("unhashable instance"); } return super.hashCode(); } if (ret instanceof PyInteger) { return ((PyInteger) ret).getValue(); } else if (ret instanceof PyLong) { return ((PyLong) ret).hashCode(); } throw Py.TypeError("__hash__() must really return int" + ret.getType()); }
PyObject getinitargs = object.__findattr__("__getinitargs__"); if (getinitargs != null) { args = (PySequence)getinitargs.__call__(); PyObject getstate = object.__findattr__("__getstate__"); if (getstate == null) { stuff = object.__dict__;