org.python.core
Class PyObject

java.lang.Object
  extended byorg.python.core.PyObject
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
_weakref.AbstractReference, cStringIO.StringIO, MatchObject, MD5Object, PyBeanEvent, PyBuiltinFunctionSet, PyCell, PyClass, PyCode, PyComplex, PyCompoundCallable, PyDictionary, PyFile, PyFloat, PyFrame, PyFunction, PyInstance, PyInteger, PyJavaPackage, PyLock, PyLong, PyMethod, PyModule, PyReflectedField, PyReflectedFunction, PySequence, PySingleton, PySlice, PyStringMap, PySystemState, PyTraceback, RegexObject, xreadlines.XReadlineObj

public class PyObject
extends Object
implements Serializable

All objects known to the Jython runtime system are represented by an instance of the class PyObject or one of its subclasses.

Since:
JPython 0.0
Version:
1.1, 1/5/98
Author:
Jim Hugunin - hugunin@python.org
See Also:
Serialized Form

Field Summary
 PyClass __class__
          The Python class of this object.
 
Constructor Summary
PyObject()
          The standard constructor for a PyObject.
 
Method Summary
 PyObject __abs__()
          Equivalent to the standard Python __abs__ method.
 PyObject __add__(PyObject other)
          Equivalent to the standard Python __add__ method
 PyObject __and__(PyObject other)
          Equivalent to the standard Python __and__ method
 PyObject __anye__(PyObject other)
           
 PyObject __bde__(PyObject other)
           
 PyObject __call__()
          A variant of the __call__ method with no arguments.
 PyObject __call__(PyObject arg0)
          A variant of the __call__ method with one argument.
 PyObject __call__(PyObject[] args)
          A variant of the __call__ method when no keywords are passed.
 PyObject __call__(PyObject[] args, String[] keywords)
          The basic method to override when implementing a callable object.
 PyObject __call__(PyObject arg0, PyObject arg1)
          A variant of the __call__ method with two arguments.
 PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords)
          A variant of the __call__ method with one extra initial argument.
 PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2)
          A variant of the __call__ method with three arguments.
 PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3)
          A variant of the __call__ method with four arguments.
 int __cmp__(PyObject other)
          Equivalent to the standard Python __cmp__ method.
 PyObject __coerce__(PyObject pyo)
          Equivalent to the standard Python __coerce__ method.
 Object __coerce_ex__(PyObject o)
          Implements numeric coercion
 PyComplex __complex__()
          Equivalent to the standard Python __complex__ method.
 boolean __contains__(PyObject o)
          Equivalent to the standard Python __contains__ method.
 void __delattr__(PyString name)
          Equivalent to the standard Python __delattr__ method.
 void __delattr__(String name)
          A variant of the __delattr__ method which accepts a String as the key.
 void __delitem__(PyObject key)
          Equivalent to the standard Python __delitem__ method.
 void __delitem__(String key)
          A variant of the __delitem__ method which accepts a String as the key.
 void __delslice__(PyObject start, PyObject stop)
           
 void __delslice__(PyObject s_start, PyObject s_stop, PyObject s_step)
           
 PyObject __dir__()
          Equivalent to the standard Python __dir__ method.
 PyObject __div__(PyObject other)
          Equivalent to the standard Python __div__ method
 PyObject __divmod__(PyObject other)
          Equivalent to the standard Python __divmod__ method
 PyObject __eq__(PyObject other)
          Equivalent to the standard Python __eq__ method.
 PyObject __findattr__(PyString name)
          Very similar to the standard Python __getattr__ method.
 PyObject __findattr__(String name)
          A variant of the __findattr__ method which accepts a Java String as the name.
 PyObject __finditem__(int key)
          A variant of the __finditem__ method which accepts a primitive int as the key.
 PyObject __finditem__(PyObject key)
          Very similar to the standard Python __getitem__ method.
 PyObject __finditem__(String key)
          A variant of the __finditem__ method which accepts a Java String as the key.
 PyFloat __float__()
          Equivalent to the standard Python __float__ method.
 PyObject __ge__(PyObject other)
          Equivalent to the standard Python __ge__ method.
 PyObject __getattr__(PyString name)
          Equivalent to the standard Python __getattr__ method.
 PyObject __getattr__(String name)
          A variant of the __getattr__ method which accepts a Java String as the name.
 PyObject __getitem__(int key)
          Equivalent to the standard Python __getitem__ method.
 PyObject __getitem__(PyObject key)
          Equivalent to the standard Python __getitem__ method.
 PyObject __getslice__(PyObject start, PyObject stop)
           
 PyObject __getslice__(PyObject s_start, PyObject s_stop, PyObject s_step)
           
 PyObject __gt__(PyObject other)
          Equivalent to the standard Python __gt__ method.
 PyInteger __hash__()
          Equivalent to the standard Python __hash__ method.
 PyString __hex__()
          Equivalent to the standard Python __hex__ method Should only be overridden by numeric objects that can be reasonably represented as a hexadecimal string.
 PyObject __iadd__(PyObject other)
          Equivalent to the standard Python __iadd__ method
 PyObject __iand__(PyObject other)
          Equivalent to the standard Python __iand__ method
 PyObject __idiv__(PyObject other)
          Equivalent to the standard Python __idiv__ method
 PyObject __idivmod__(PyObject other)
          Equivalent to the standard Python __idivmod__ method
 PyObject __ilshift__(PyObject other)
          Equivalent to the standard Python __ilshift__ method
 PyObject __imod__(PyObject other)
          Equivalent to the standard Python __imod__ method
 PyObject __imul__(PyObject other)
          Equivalent to the standard Python __imul__ method
 PyInteger __int__()
          Equivalent to the standard Python __int__ method.
 PyObject __invert__()
          Equivalent to the standard Python __invert__ method.
 PyObject __ior__(PyObject other)
          Equivalent to the standard Python __ior__ method
 PyObject __ipow__(PyObject other)
          Equivalent to the standard Python __ipow__ method
 PyObject __irshift__(PyObject other)
          Equivalent to the standard Python __irshift__ method
 PyObject __isub__(PyObject other)
          Equivalent to the standard Python __isub__ method
 PyObject __ixor__(PyObject other)
          Equivalent to the standard Python __ixor__ method
 PyObject __lde__(PyObject other)
           
 PyObject __le__(PyObject other)
          Equivalent to the standard Python __le__ method.
 int __len__()
          Equivalent to the standard Python __len__ method.
 PyObject __like__(PyObject other)
           
 PyLong __long__()
          Equivalent to the standard Python __long__ method.
 PyObject __lshift__(PyObject other)
          Equivalent to the standard Python __lshift__ method
 PyObject __lt__(PyObject other)
          Equivalent to the standard Python __lt__ method.
 PyObject __mod__(PyObject other)
          Equivalent to the standard Python __mod__ method
 PyObject __mul__(PyObject other)
          Equivalent to the standard Python __mul__ method
 PyObject __ne__(PyObject other)
          Equivalent to the standard Python __ne__ method.
 PyObject __neg__()
          Equivalent to the standard Python __neg__ method.
 boolean __nonzero__()
          Equivalent to the standard Python __nonzero__ method.
 PyObject __not__()
          Implements boolean not
 PyString __oct__()
          Equivalent to the standard Python __oct__ method.
 PyObject __or__(PyObject other)
          Equivalent to the standard Python __or__ method
 PyObject __pos__()
          Equivalent to the standard Python __pos__ method.
 PyObject __pow__(PyObject other)
          Equivalent to the standard Python __pow__ method
 PyObject __pow__(PyObject o2, PyObject o3)
          Implements the three argument power function.
 PyObject __radd__(PyObject other)
          Equivalent to the standard Python __radd__ method
 PyObject __rand__(PyObject other)
          Equivalent to the standard Python __rand__ method
 PyObject __rcontained__(PyObject other)
           
 PyObject __rcontains__(PyObject other)
           
 PyObject __rde__(PyObject other)
           
 PyObject __rdiv__(PyObject other)
          Equivalent to the standard Python __rdiv__ method
 PyObject __rdivmod__(PyObject other)
          Equivalent to the standard Python __rdivmod__ method
 PyString __repr__()
          Equivalent to the standard Python __repr__ method.
 PyObject __rexact__(PyObject other)
           
 PyObject __rlshift__(PyObject other)
          Equivalent to the standard Python __rlshift__ method
 PyObject __rmod__(PyObject other)
          Equivalent to the standard Python __rmod__ method
 PyObject __rmul__(PyObject other)
          Equivalent to the standard Python __rmul__ method
 PyObject __ror__(PyObject other)
          Equivalent to the standard Python __ror__ method
 PyObject __roverlaps__(PyObject other)
           
 PyObject __rpow__(PyObject other)
          Equivalent to the standard Python __rpow__ method
 PyObject __rrshift__(PyObject other)
          Equivalent to the standard Python __rrshift__ method
 PyObject __rshift__(PyObject other)
          Equivalent to the standard Python __rshift__ method
 PyObject __rsub__(PyObject other)
          Equivalent to the standard Python __rsub__ method
 PyObject __rxor__(PyObject other)
          Equivalent to the standard Python __rxor__ method
 void __setattr__(PyString name, PyObject value)
          Equivalent to the standard Python __setattr__ method.
 void __setattr__(String name, PyObject value)
          A variant of the __setattr__ method which accepts a String as the key.
 void __setitem__(int key, PyObject value)
          A variant of the __setitem__ method which accepts a primitive int as the key.
 void __setitem__(PyObject key, PyObject value)
          Equivalent to the standard Python __setitem__ method.
 void __setitem__(String key, PyObject value)
          A variant of the __setitem__ method which accepts a String as the key.
 void __setslice__(PyObject start, PyObject stop, PyObject value)
           
 void __setslice__(PyObject s_start, PyObject s_stop, PyObject s_step, PyObject value)
           
 PyString __str__()
          Equivalent to the standard Python __str__ method.
 PyString __str2__()
           
 PyObject __sub__(PyObject other)
          Equivalent to the standard Python __sub__ method
 Object __tojava__(Class c)
          Equivalent to the Jython __tojava__ method.
 PyObject __xor__(PyObject other)
          Equivalent to the standard Python __xor__ method
 PyObject _add(PyObject o2)
          Implements the Python expression this + other
 PyObject _and(PyObject o2)
          Implements the Python expression this & other
 PyObject _anye(PyObject o)
          Implements the Python expression this ? other.
 PyObject _bde(PyObject o)
          Implements the Python expression this -> other.
 PyObject _callextra(PyObject[] args, String[] keywords, PyObject starargs, PyObject kwargs)
          Deprecated.  
 int _cmp(PyObject o)
          Implements cmp(this, other)
 PyObject _div(PyObject o2)
          Implements the Python expression this / other
 PyObject _divmod(PyObject o2)
          Implements the Python expression this divmod other
 boolean _dodel(PyObject container)
           
 PyObject _doget(PyObject container)
           
 PyObject _doget(PyObject container, PyObject wherefound)
           
 boolean _doset(PyObject container, PyObject value)
           
 PyObject _eq(PyObject o)
          Implements the Python expression this == other.
 PyObject _ge(PyObject o)
          Implements the Python expression this >= other.
 PyObject _gt(PyObject o)
          Implements the Python expression this > other.
 PyObject _in(PyObject o)
          Implements in operator.
 PyObject _is(PyObject o)
          Implements is operator.
 PyObject _isnot(PyObject o)
          Implements is not operator.
 PyObject _jcall(Object[] args)
           
 PyObject _jcallexc(Object[] args)
          A convenience function for PyProxy's.
 void _jthrow(Throwable t)
           
 PyObject _lde(PyObject o)
          Implements the Python expression this -> other.
 PyObject _le(PyObject o)
          Implements the Python expression this <= other.
 PyObject _like(PyObject o)
          Implements the Python expression this like other.
 PyObject _lshift(PyObject o2)
          Implements the Python expression this << other
 PyObject _lt(PyObject o)
          Implements the Python expression this < other.
 PyObject _mod(PyObject o2)
          Implements the Python expression this % other
 PyObject _mul(PyObject o2)
          Implements the Python expression this * other
 PyObject _ne(PyObject o)
          Implements the Python expression this != other.
 PyObject _notin(PyObject o)
          Implements not in operator.
 PyObject _or(PyObject o2)
          Implements the Python expression this | other
 PyObject _pow(PyObject o2)
          Implements the Python expression this ** other
 PyObject _rcontained(PyObject o)
          Implements the Python expression this rcontained other.
 PyObject _rcontains(PyObject o)
          Implements the Python expression this rcontains other.
 PyObject _rde(PyObject o)
          Implements the Python expression this -> other.
 PyObject _rexact(PyObject o)
          Implements the Python expression this rexact other.
 PyObject _roverlaps(PyObject o)
          Implements the Python expression this roverlaps other.
 PyObject _rshift(PyObject o2)
          Implements the Python expression this >> other
 PyObject _sub(PyObject o2)
          Implements the Python expression this - other
 PyObject _xor(PyObject o2)
          Implements the Python expression this ^ other
 boolean equals(Object ob_other)
          Should almost never be overridden.
 int hashCode()
           
 PyObject invoke(String name)
          Shortcut for calling a method on a PyObject with no args.
 PyObject invoke(String name, PyObject arg1)
          Shortcut for calling a method on a PyObject with one arg.
 PyObject invoke(String name, PyObject[] args)
           
 PyObject invoke(String name, PyObject[] args, String[] keywords)
          Shortcut for calling a method on a PyObject from Java.
 PyObject invoke(String name, PyObject arg1, PyObject arg2)
          Shortcut for calling a method on a PyObject with two args.
 boolean isCallable()
           
 boolean isMappingType()
           
 boolean isNumberType()
           
 boolean isSequenceType()
           
 String safeRepr()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__class__

public transient PyClass __class__
The Python class of this object. Unlike in CPython, all types have this attribute, even builtins. This should only be set in the constructor, never modified otherwise.

Constructor Detail

PyObject

public PyObject()
The standard constructor for a PyObject. It will set the __class__ field to correspond to the specific subclass of PyObject being instantiated.

Method Detail

__repr__

public PyString __repr__()
Equivalent to the standard Python __repr__ method. This method should not typically need to be overrriden. The easiest way to configure the string representation of a PyObject is to override the standard Java toString method.


safeRepr

public String safeRepr()
                throws PyIgnoreMethodTag
Throws:
PyIgnoreMethodTag

__str__

public PyString __str__()
Equivalent to the standard Python __str__ method. This method should not typically need to be overridden. The easiest way to configure the string representation of a PyObject is to override the standard Java toString method.


__str2__

public PyString __str2__()

__hash__

public final PyInteger __hash__()
Equivalent to the standard Python __hash__ method. This method can not be overridden. Instead, you should override the standard Java hashCode method to return an appropriate hash code for the PyObject.


hashCode

public int hashCode()

equals

public boolean equals(Object ob_other)
Should almost never be overridden. If overridden, it is the subclasses responsibility to ensure that a.equals(b) == true iff cmp(a,b) == 0


__nonzero__

public boolean __nonzero__()
Equivalent to the standard Python __nonzero__ method. Returns whether of not a given PyObject is considered true.


__tojava__

public Object __tojava__(Class c)
Equivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special object Py.NoConversion if this PyObject can not be converted to the desired Java class.

Parameters:
c - the Class to convert this PyObject to.

__call__

public PyObject __call__(PyObject[] args,
                         String[] keywords)
The basic method to override when implementing a callable object. The first len(args)-len(keywords) members of args[] are plain arguments. The last len(keywords) arguments are the values of the keyword arguments.

Parameters:
args - all arguments to the function (including keyword arguments).
keywords - the keywords used for all keyword arguments.

__call__

public PyObject __call__(PyObject arg1,
                         PyObject[] args,
                         String[] keywords)
A variant of the __call__ method with one extra initial argument. This variant is used to allow method invocations to be performed efficiently. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
arg1 - the first argument to the function.
args - the last arguments to the function (including keyword arguments).
keywords - the keywords used for all keyword arguments.

__call__

public PyObject __call__(PyObject[] args)
A variant of the __call__ method when no keywords are passed. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
args - all arguments to the function.

__call__

public PyObject __call__()
A variant of the __call__ method with no arguments. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.


__call__

public PyObject __call__(PyObject arg0)
A variant of the __call__ method with one argument. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
arg0 - the single argument to the function.

__call__

public PyObject __call__(PyObject arg0,
                         PyObject arg1)
A variant of the __call__ method with two arguments. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
arg0 - the first argument to the function.
arg1 - the second argument to the function.

__call__

public PyObject __call__(PyObject arg0,
                         PyObject arg1,
                         PyObject arg2)
A variant of the __call__ method with three arguments. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
arg0 - the first argument to the function.
arg1 - the second argument to the function.
arg2 - the third argument to the function.

__call__

public PyObject __call__(PyObject arg0,
                         PyObject arg1,
                         PyObject arg2,
                         PyObject arg3)
A variant of the __call__ method with four arguments. The default behavior is to invoke __call__(args, keywords) with the appropriate arguments. The only reason to override this function would be for improved performance.

Parameters:
arg0 - the first argument to the function.
arg1 - the second argument to the function.
arg2 - the third argument to the function.
arg3 - the fourth argument to the function.

_callextra

public PyObject _callextra(PyObject[] args,
                           String[] keywords,
                           PyObject starargs,
                           PyObject kwargs)
Deprecated.  


isCallable

public boolean isCallable()

isMappingType

public boolean isMappingType()

isNumberType

public boolean isNumberType()

isSequenceType

public boolean isSequenceType()

__len__

public int __len__()
Equivalent to the standard Python __len__ method. Part of the mapping discipline.

Returns:
the length of the object

__finditem__

public PyObject __finditem__(PyObject key)
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.

Parameters:
key - the key to lookup in this container
Returns:
the value corresponding to key or null if key is not found

__finditem__

public PyObject __finditem__(int key)
A variant of the __finditem__ method which accepts a primitive int as the key. By default, this method will call __finditem__(PyObject key) with the appropriate args. The only reason to override this method is for performance.

Parameters:
key - the key to lookup in this sequence.
Returns:
the value corresponding to key or null if key is not found.
See Also:
__finditem__(PyObject)

__finditem__

public PyObject __finditem__(String key)
A variant of the __finditem__ method which accepts a Java String as the key. By default, this method will call __finditem__(PyObject key) with the appropriate args. The only reason to override this method is for performance. Warning: key must be an interned string!!!!!!!!

Parameters:
key - the key to lookup in this sequence - must be an interned string .
Returns:
the value corresponding to key or null if key is not found.
See Also:
__finditem__(PyObject)

__getitem__

public PyObject __getitem__(int key)
Equivalent to the standard Python __getitem__ method. This variant takes a primitive int as the key. This method should not be overridden. Override the __finditem__ method instead.

Parameters:
key - the key to lookup in this container.
Returns:
the value corresponding to that key.
Throws:
PyKeyError - if the key is not found.
See Also:
__finditem__(int)

__getitem__

public PyObject __getitem__(PyObject key)
Equivalent to the standard Python __getitem__ method. This method should not be overridden. Override the __finditem__ method instead.

Parameters:
key - the key to lookup in this container.
Returns:
the value corresponding to that key.
Throws:
PyKeyError - if the key is not found.
See Also:
__finditem__(PyObject)

__setitem__

public void __setitem__(PyObject key,
                        PyObject value)
Equivalent to the standard Python __setitem__ method.

Parameters:
key - the key whose value will be set
value - the value to set this key to

__setitem__

public void __setitem__(String key,
                        PyObject value)
A variant of the __setitem__ method which accepts a String as the key. This String must be interned. By default, this will call __setitem__(PyObject key, PyObject value) with the appropriate args. The only reason to override this method is for performance.

Parameters:
key - the key whose value will be set - must be an interned string .
value - the value to set this key to
See Also:
__setitem__(PyObject, PyObject)

__setitem__

public void __setitem__(int key,
                        PyObject value)
A variant of the __setitem__ method which accepts a primitive int as the key. By default, this will call __setitem__(PyObject key, PyObject value) with the appropriate args. The only reason to override this method is for performance.

Parameters:
key - the key whose value will be set
value - the value to set this key to
See Also:
__setitem__(PyObject, PyObject)

__delitem__

public void __delitem__(PyObject key)
Equivalent to the standard Python __delitem__ method.

Parameters:
key - the key to be removed from the container
Throws:
PyKeyError - if the key is not found in the container

__delitem__

public void __delitem__(String key)
A variant of the __delitem__ method which accepts a String as the key. This String must be interned. By default, this will call __delitem__(PyObject key) with the appropriate args. The only reason to override this method is for performance.

Parameters:
key - the key who will be removed - must be an interned string .
Throws:
PyKeyError - if the key is not found in the container
See Also:
__delitem__(PyObject)

__getslice__

public PyObject __getslice__(PyObject s_start,
                             PyObject s_stop,
                             PyObject s_step)

__setslice__

public void __setslice__(PyObject s_start,
                         PyObject s_stop,
                         PyObject s_step,
                         PyObject value)

__delslice__

public void __delslice__(PyObject s_start,