Esempio n. 1
0
 public boolean __nonzero__() {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("__nonzero__");
   if (impl == null) {
     impl = self_type.lookup("__len__");
     if (impl == null) return super.__nonzero__();
   }
   PyObject o = impl.__get__(this, self_type).__call__();
   if (o.getClass() != PyInteger.class && o.getClass() != PyBoolean.class) {
     throw Py.TypeError(
         String.format("__nonzero__ should return bool or int, returned %s", self_type.getName()));
   }
   return o.__nonzero__();
 }
Esempio n. 2
0
 public void setDict(PyObject newDict) {
   if (newDict instanceof PyStringMap || newDict instanceof PyDictionary) {
     dict = newDict;
   } else {
     throw Py.TypeError("__dict__ must be set to a Dictionary " + newDict.getClass().getName());
   }
 }
 private boolean checkCallback(Object[] args) {
   PyInstance inst = (PyInstance) args[0];
   String mName = (String) args[1];
   PyObject method = inst.__getattr__(mName);
   if (method == null || !method.getClass().getName().contains("PyMethod")) {
     log(-100, "checkCallback: Object: %s, Method not found: %s", inst, mName);
     return false;
   }
   return true;
 }
 public void setDict(PyObject newDict) {
   if (newDict instanceof PyStringMap || newDict instanceof PyDictionary) {
     dict = newDict;
     if (dict.__finditem__(PyString.fromInterned("__del__")) != null
         && !JyAttribute.hasAttr(this, JyAttribute.FINALIZE_TRIGGER_ATTR)) {
       FinalizeTrigger.ensureFinalizer(this);
     }
   } else {
     throw Py.TypeError("__dict__ must be set to a Dictionary " + newDict.getClass().getName());
   }
 }
 // TODO implement generalized callback
 private boolean runCallback(Object[] args) {
   PyInstance inst = (PyInstance) args[0];
   String mName = (String) args[1];
   PyObject method = inst.__getattr__(mName);
   if (method == null || !method.getClass().getName().contains("PyMethod")) {
     log(-1, "runCallback: Object: %s, Method not found: %s", inst, mName);
     return false;
   }
   try {
     PyString pmsg = new PyString("not yet supported");
     inst.invoke(mName, pmsg);
   } catch (Exception ex) {
     log(-1, "runCallback: invoke: %s", ex.getMessage());
     return false;
   }
   return true;
 }