Пример #1
0
  @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;
  }
Пример #4
0
 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__();
 }
Пример #8
0
 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);
 }
Пример #9
0
 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);
 }
Пример #10
0
 @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__();
 }
Пример #11
0
 @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__();
 }
Пример #12
0
 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);
 }
Пример #13
0
 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);
 }
Пример #14
0
 @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);
   }
 }
Пример #15
0
 @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();
   }
 }
Пример #16
0
 @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);
   }
 }
Пример #17
0
 @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();
   }
 }
Пример #18
0
 @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();
   }
 }
Пример #19
0
 @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);
   }
 }
Пример #20
0
 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__();
 }
Пример #21
0
 @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);
   }
 }
Пример #22
0
 @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();
   }
 }
Пример #23
0
 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);
 }
Пример #24
0
 @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);
 }
Пример #25
0
 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__();
 }
Пример #26
0
 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);
 }
Пример #27
0
 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__();
 }
Пример #28
0
 @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);
   }
 }
Пример #29
0
 @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);
   }
 }
Пример #30
0
 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__();
 }