📄 pyobject.java
字号:
public boolean isCallable() { return __findattr__("__call__") != null; } public boolean isMappingType() { return true; } public boolean isNumberType() { return true; } public boolean isSequenceType() { return true; } /* The basic functions to implement a mapping */ /** * Equivalent to the standard Python __len__ method. * Part of the mapping discipline. * * @return the length of the object **/ public int __len__() { throw Py.AttributeError("__len__"); } /** * Very similar to the standard Python __getitem__ method. * Instead of throwing a KeyError if the item isn't found, * this just returns null. * * Classes that wish to implement __getitem__ should * override this method instead (with the appropriate * semantics. * * @param key the key to lookup in this container * * @return the value corresponding to key or null if key is not found **/ public PyObject __finditem__(PyObject key) { throw Py.AttributeError("__getitem__"); } /** * A variant of the __finditem__ method which accepts a primitive * <code>int</code> as the key. By default, this method will call * <code>__finditem__(PyObject key)</code> with the appropriate args. * The only reason to override this method is for performance. * * @param key the key to lookup in this sequence. * @return the value corresponding to key or null if key is not found. * * @see #__finditem__(PyObject) **/ public PyObject __finditem__(int key) { return __finditem__(new PyInteger(key)); } /** * A variant of the __finditem__ method which accepts a Java * <code>String</code> as the key. By default, this method will call * <code>__finditem__(PyObject key)</code> with the appropriate args. * The only reason to override this method is for performance. * * <b>Warning: key must be an interned string!!!!!!!!</b> * * @param key the key to lookup in this sequence - * <b> must be an interned string </b>. * @return the value corresponding to key or null if key is not found. * * @see #__finditem__(PyObject) **/ public PyObject __finditem__(String key) { return __finditem__(new PyString(key)); } /** * Equivalent to the standard Python __getitem__ method. * This variant takes a primitive <code>int</code> as the key. * This method should not be overridden. * Override the <code>__finditem__</code> method instead. * * @param key the key to lookup in this container. * @return the value corresponding to that key. * @exception PyKeyError if the key is not found. * * @see #__finditem__(int) **/ public PyObject __getitem__(int key) { PyObject ret = __finditem__(key); if (ret == null) throw Py.KeyError(""+key); return ret; } /** * Equivalent to the standard Python __getitem__ method. * This method should not be overridden. * Override the <code>__finditem__</code> method instead. * * @param key the key to lookup in this container. * @return the value corresponding to that key. * @exception PyKeyError if the key is not found. * * @see #__finditem__(PyObject) **/ public PyObject __getitem__(PyObject key) { PyObject ret = __finditem__(key); if (ret == null) throw Py.KeyError(key.toString()); return ret; } /** * Equivalent to the standard Python __setitem__ method. * * @param key the key whose value will be set * @param value the value to set this key to **/ public void __setitem__(PyObject key, PyObject value) { throw Py.AttributeError("__setitem__"); } /** * A variant of the __setitem__ method which accepts a String * as the key. <b>This String must be interned</b>. * By default, this will call * <code>__setitem__(PyObject key, PyObject value)</code> * with the appropriate args. * The only reason to override this method is for performance. * * @param key the key whose value will be set - * <b> must be an interned string </b>. * @param value the value to set this key to * * @see #__setitem__(PyObject, PyObject) **/ public void __setitem__(String key, PyObject value) { __setitem__(new PyString(key), value); } /** * A variant of the __setitem__ method which accepts a primitive * <code>int</code> as the key. * By default, this will call * <code>__setitem__(PyObject key, PyObject value)</code> * with the appropriate args. * The only reason to override this method is for performance. * * @param key the key whose value will be set * @param value the value to set this key to * * @see #__setitem__(PyObject, PyObject) **/ public void __setitem__(int key, PyObject value) { __setitem__(new PyInteger(key), value); } /** * Equivalent to the standard Python __delitem__ method. * * @param key the key to be removed from the container * @exception PyKeyError if the key is not found in the container **/ public void __delitem__(PyObject key) { throw Py.AttributeError("__delitem__"); } /** * A variant of the __delitem__ method which accepts a String * as the key. <b>This String must be interned</b>. * By default, this will call * <code>__delitem__(PyObject key)</code> * with the appropriate args. * The only reason to override this method is for performance. * * @param key the key who will be removed - * <b> must be an interned string </b>. * @exception PyKeyError if the key is not found in the container * * @see #__delitem__(PyObject) **/ public void __delitem__(String key) { __delitem__(new PyString(key)); } public PyObject __getslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { PySlice s = new PySlice(s_start, s_stop, s_step); return __getitem__(s); } public void __setslice__(PyObject s_start, PyObject s_stop, PyObject s_step, PyObject value) { PySlice s = new PySlice(s_start, s_stop, s_step); __setitem__(s, value); } public void __delslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { PySlice s = new PySlice(s_start, s_stop, s_step); __delitem__(s); } public PyObject __getslice__(PyObject start, PyObject stop) { return __getslice__(start, stop, Py.One); } public void __setslice__(PyObject start, PyObject stop, PyObject value) { __setslice__(start, stop, Py.One, value); } public void __delslice__(PyObject start, PyObject stop) { __delslice__(start, stop, Py.One); } /*The basic functions to implement an iterator */ /** * Return an iterator that is used to iterate the element of this * sequence. * From version 2.2, this method is the primary protocol for looping * over sequences. * <p> * If a PyObject subclass should support iteration based in the * __finditem__() method, it must supply an implementation of __iter__() * like this: * <pre> * public PyObject __iter__() { * return new PySequenceIter(this); * } * </pre> * * When iterating over a python sequence from java code, it should be * done with code like this: * <pre> * PyObject iter = seq.__iter__(); * for (PyObject item; (item = iter.__next__()) != null; { * // Do somting with item * } * </pre> * * @since 2.2 */ public PyObject __iter__() { throw Py.TypeError("iteration over non-sequence"); } /** * Return the next element of the sequence that this is an iterator * for. Returns null when the end of the sequence is reached. * * @since 2.2 */ public PyObject __iternext__() { return null; } /*The basic functions to implement a namespace*/ /** * Very similar to the standard Python __getattr__ method. * Instead of throwing a AttributeError if the item isn't found, * this just returns null. * * Classes that wish to implement __getattr__ should * override this method instead (with the appropriate * semantics. * * @param name the name to lookup in this namespace * * @return the value corresponding to name or null if name is not found **/ public PyObject __findattr__(PyString name) { if(name == null) { return null; } return __findattr__(name.internedString()); } /** * A variant of the __findattr__ method which accepts a Java * <code>String</code> as the name. * * By default, this method will call <code>__findattr__(PyString * name)</code> with the appropriate args. The only reason to override * this method is for performance. * * <b>Warning: name must be an interned string!!!!!!!!</b> * * @param name the name to lookup in this namespace * <b> must be an interned string </b>. * @return the value corresponding to name or null if name is not found * * @see #__findattr__(PyString) **/ public PyObject __findattr__(String name) { if (__class__ == null) return null; if (name == "__class__") return __class__; PyObject ret = __class__.lookup(name, false); if (ret != null) return ret._doget(this); return null; } /** * Equivalent to the standard Python __getattr__ method. * This method can not be overridden. * Override the <code>__findattr__</code> method instead. * * @param name the name to lookup in this namespace * @return the value corresponding to name * @exception PyAttributeError if the name is not found. * * @see #__findattr__(PyString) **/ public final PyObject __getattr__(PyString name) { PyObject ret = __findattr__(name); if (ret == null) throw Py.AttributeError(safeRepr() + " has no attribute '" + name + "'"); return ret; } /** * A variant of the __getattr__ method which accepts a Java * <code>String</code> as the name. * This method can not be overridden. * Override the <code>__findattr__</code> method instead. * * <b>Warning: name must be an interned string!!!!!!!!</b> * * @param name the name to lookup in this namespace * <b> must be an interned string </b>. * @return the value corresponding to name * @exception PyAttributeError if the name is not found. * * @see #__findattr__(java.lang.String) **/ public final PyObject __getattr__(String name) { PyObject ret = __findattr__(name); if (ret == null) throw Py.AttributeError(safeRepr() + " has no attribute '" + name + "'"); return ret; } /** * Equivalent to the standard Python __setattr__ method. * This method can not be overridden. * * @param name the name to lookup in this namespace * @return the value corresponding to name * @exception PyAttributeError if the name is not found. * * @see #__setattr__(java.lang.String, PyObject) **/ public final void __setattr__(PyString name, PyObject value) { __setattr__(name.internedString(), value); } /** * A variant of the __setattr__ method which accepts a String * as the key. <b>This String must be interned</b>. * * @param name the name whose value will be set - * <b> must be an interned string </b>. * @param value the value to set this name to * * @see #__setattr__(PyString, PyObject) **/ public void __setattr__(String name, PyObject value) { throw Py.TypeError("readonly class or attribute: " + name); } /** * Equivalent to the standard Python __delattr__ method. * This method can not be overridden. * * @param name the name to which will be removed * @exception PyAttributeError if the name doesn't exist * * @see #__delattr__(java.lang.String) **/ public final void __delattr__(PyString name) { __delattr__(name.internedString()); } /** * A variant of the __delattr__ method which accepts a String * as the key. <b>This String must be interned</b>. * By default, this will call * <code>__delattr__(PyString name)</code>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -