Ejemplo 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__();
   }
 }
Ejemplo n.º 3
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);
  }
Ejemplo 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);
 }
Ejemplo n.º 6
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__();
 }
Ejemplo n.º 7
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__();
 }
 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__();
 }
Ejemplo 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);
 }
Ejemplo 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);
 }
Ejemplo 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);
 }
Ejemplo 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);
 }
Ejemplo 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();
   }
 }
Ejemplo 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);
   }
 }
Ejemplo 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);
   }
 }
Ejemplo 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();
   }
 }
Ejemplo 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();
   }
 }
Ejemplo 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);
   }
 }
Ejemplo 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__();
 }
Ejemplo 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);
   }
 }
Ejemplo 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();
   }
 }
Ejemplo 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);
 }
Ejemplo 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);
 }
Ejemplo 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__();
 }
Ejemplo 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);
 }
Ejemplo 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);
   }
 }
Ejemplo 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__();
 }
Ejemplo 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);
 }
Ejemplo 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__();
 }