public void __setattr__(String name, PyObject value) { // softspace is the only writeable file object attribute if (name == "softspace") softspace = value.__nonzero__(); else if (name == "mode" || name == "closed" || name == "name") throw Py.TypeError("readonly attribute: " + name); else throw Py.AttributeError(name); }
public static PyObject EnvironmentError__str__(PyObject self, PyObject[] args, String[] kwargs) { PyObject errno = self.__findattr__("errno"); PyObject strerror = self.__findattr__("strerror"); PyObject filename = self.__findattr__("filename"); PyString result; if (filename.__nonzero__()) { result = Py.newString("[Errno %s] %s: %s"); result = (PyString) result.__mod__(new PyTuple(errno, strerror, filename.__repr__())); } else if (errno.__nonzero__() && strerror.__nonzero__()) { result = Py.newString("[Errno %s] %s"); result = (PyString) result.__mod__(new PyTuple(errno, strerror)); } else { return PyBaseException.TYPE.invoke("__str__", self, args, kwargs); } return result; }
public void sort(PyObject cmp, PyObject key, PyObject reverse) { boolean bReverse = reverse.__nonzero__(); if (key == Py.None || key == null) { if (cmp == Py.None || cmp == null) { sort(bReverse); } else { sort(cmp, bReverse); } } else { sort(cmp, key, bReverse); } }
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__(); }