Esempio n. 1
0
 public PyObject __pow__(PyObject other, PyObject modulo) {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("__pow__");
   if (impl != null) {
     PyObject res;
     if (modulo == null) {
       res = impl.__get__(this, self_type).__call__(other);
     } else {
       res = impl.__get__(this, self_type).__call__(other, modulo);
     }
     if (res == Py.NotImplemented) return null;
     return res;
   }
   return super.__pow__(other, modulo);
 }
 public void __del_derived__() {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("__del__");
   if (impl != null) {
     impl.__get__(this, self_type).__call__();
   }
 }
  @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);
  }
Esempio n. 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);
 }
 @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 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__();
 }
Esempio n. 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);
 }
Esempio n. 10
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);
 }
Esempio n. 11
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);
 }
Esempio n. 12
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);
 }
Esempio n. 13
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();
   }
 }
Esempio n. 14
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);
   }
 }
Esempio n. 15
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);
   }
 }
Esempio n. 16
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();
   }
 }
Esempio n. 17
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();
   }
 }
Esempio n. 18
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);
   }
 }
Esempio n. 19
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__();
 }
Esempio n. 20
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);
   }
 }
Esempio n. 21
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();
   }
 }
Esempio n. 22
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);
 }
Esempio n. 23
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);
 }
Esempio n. 24
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__();
 }
Esempio n. 25
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);
 }
Esempio n. 26
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);
   }
 }
Esempio n. 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__();
 }
Esempio n. 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);
   }
 }
 public void __setattr__(String name, PyObject value) {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("__setattr__");
   if (impl != null) {
     impl.__get__(this, self_type).__call__(PyString.fromInterned(name), value);
     // CPython does not support instance-acquired finalizers.
     // So we don't check for __del__ here.
     return;
   }
   super.__setattr__(name, value);
 }
Esempio n. 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__();
 }