@Override public Object pyInstanceToJava(Object pyInstance) { return ((PyInstance) pyInstance).__tojava__(java.lang.Object.class); }
/** * Implements the __add__ method by looking it up * in the instance's dictionary and calling it if it is found. */ @ExposedMethod(type = MethodType.BINARY) public PyObject instance___add__(PyObject o) { Object ctmp = __coerce_ex__(o); if (ctmp == null || ctmp == Py.None) return invoke_ex("__add__", o); else { PyObject o1 = ((PyObject[]) ctmp)[0]; PyObject o2 = ((PyObject[]) ctmp)[1]; if (this == o1) { // Prevent recursion if __coerce__ return self return invoke_ex("__add__", o2); } else { return o1._add(o2); } } }
@Override public boolean isSequenceType() { return __findattr__("__getitem__") != null; }
@Override public PyObject __call__(PyObject[] args, String[] keywords) { PyInstance inst; inst = new PyInstance(this); if (__del__ != null) { FinalizeTrigger.ensureFinalizer(inst); } inst.__init__(args, keywords); return inst; }
@ExposedMethod final PyObject instance___getslice__(PyObject start, PyObject stop, PyObject step) { if (step != null) { return __getitem__(new PySlice(start, stop, step)); } PyObject ret = trySlice("__getslice__", start, stop); if (ret != null) { return ret; } return super.__getslice__(start, stop, step); }
@ExposedMethod final void instance___delslice__(PyObject start, PyObject stop, PyObject step) { if (step != null) { __delitem__(new PySlice(start, stop, step)); } else if (trySlice("__delslice__", start, stop) == null) { super.__delslice__(start, stop, step); } }
@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()); }
@ExposedNew public static PyObject instance___new__(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("instance", args, keywords, "name", "bases", "dict"); PyClass klass = (PyClass) ap.getPyObjectByType(0, PyClass.TYPE); PyObject dict = ap.getPyObject(1, Py.None); if (dict == Py.None) { dict = null; } else if (!(dict instanceof PyStringMap || dict instanceof PyDictionary)) { throw Py.TypeError("instance() second arg must be dictionary or None"); } return new PyInstance(klass, dict); }
@Override public String toString() { return __repr__().toString(); }
@Override public PyObject __finditem__(int key) { return __finditem__(new PyInteger(key)); }
/** * Implements the __sub__ method by looking it up * in the instance's dictionary and calling it if it is found. */ @ExposedMethod(type = MethodType.BINARY) public PyObject instance___sub__(PyObject o) { Object ctmp = __coerce_ex__(o); if (ctmp == null || ctmp == Py.None) return invoke_ex("__sub__", o); else { PyObject o1 = ((PyObject[]) ctmp)[0]; PyObject o2 = ((PyObject[]) ctmp)[1]; if (this == o1) { // Prevent recursion if __coerce__ return self return invoke_ex("__sub__", o2); } else { return o1._sub(o2); } } }
@Override public boolean isIndex() { return __findattr__("__index__") != null; }
final private void load_obj() { PyObject[] args = new PyObject[marker()-1]; pop(args); PyObject klass = pop(); pop(); PyObject value = null; if (args.length == 0 && klass instanceof PyClass && klass.__findattr__("__getinitargs__") == null) { value = new PyInstance((PyClass)klass); } else { value = klass.__call__(args); } push(value); }
/** * Implements the __rsub__ method by looking it up * in the instance's dictionary and calling it if it is found. */ @ExposedMethod(type = MethodType.BINARY) public PyObject instance___rsub__(PyObject o) { Object ctmp = __coerce_ex__(o); if (ctmp == null || ctmp == Py.None) return invoke_ex("__rsub__", o); else { PyObject o1 = ((PyObject[]) ctmp)[0]; PyObject o2 = ((PyObject[]) ctmp)[1]; if (this == o1) { // Prevent recursion if __coerce__ return self return invoke_ex("__rsub__", o2); } else { return o2._sub(o1); } } }
@Override public Object pyInstanceToJava(Object pyInstance) { return ((PyInstance) pyInstance).__tojava__(java.lang.Object.class); }
@Override public boolean isCallable() { return __findattr__("__call__") != null; }
final private void load_inst() { PyObject[] args = new PyObject[marker()]; pop(args); pop(); String module = file.readlineNoNl(); String name = file.readlineNoNl(); PyObject klass = find_class(module, name); PyObject value = null; if (args.length == 0 && klass instanceof PyClass && klass.__findattr__("__getinitargs__") == null) { value = new PyInstance((PyClass)klass); } else { value = klass.__call__(args); } push(value); }
/** * Implements the __rdiv__ method by looking it up * in the instance's dictionary and calling it if it is found. */ @ExposedMethod(type = MethodType.BINARY) public PyObject instance___rdiv__(PyObject o) { Object ctmp = __coerce_ex__(o); if (ctmp == null || ctmp == Py.None) return invoke_ex("__rdiv__", o); else { PyObject o1 = ((PyObject[]) ctmp)[0]; PyObject o2 = ((PyObject[]) ctmp)[1]; if (this == o1) { // Prevent recursion if __coerce__ return self return invoke_ex("__rdiv__", o2); } else { return o2._div(o1); } } }
@Override public Object pyInstanceToJava(Object pyInstance) { return ((PyInstance) pyInstance).__tojava__(java.lang.Object.class); }