Top Description Inners Fields Constructors Methods
org.python.core

public Class PyObjectUtil

extends Object
Class Inheritance
Imports
java.util.Map, .StringJoiner

Miscellaneous static helpers commonly needed to implement Python objects in Java.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PyObjectUtil.NoConversion

The type of exception thrown when an attempt to convert an object to a common data type fails.

Field Summary

Modifier and TypeField and Description
public static final PyObjectUtil.NoConversion
NO_CONVERSION

A statically allocated NoConversion used in conversion methods to signal "cannot convert".

public static final StopIteration
STOP_ITERATION

A statically allocated StopIteration used to signal exhaustion of an iterator, but providing no useful stack context.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static String

Returns:

a name for func
functionStr
(Object
the function
func
)

Produce a String name for a function-like object or its str() if it doesn't even have a __qualname__.

pack-priv static String

Returns:

a string like {'a': 2, 'b': 3}
mapRepr
(Map<? extends Object, ?>
to be reproduced
map
)

An implementation of dict.__repr__ that may be applied to any Java Map between Objects, in which keys and values are represented as with repr().

pack-priv static String

Returns:

string denoting o
toAt
(Object
the object (not its type)
o
)

A string along the lines "T object at 0xhhh", where T is the type of o.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NO_CONVERSIONback to summary
public static final PyObjectUtil.NoConversion NO_CONVERSION

A statically allocated NoConversion used in conversion methods to signal "cannot convert". No stack context is preserved in the exception.

STOP_ITERATIONback to summary
public static final StopIteration STOP_ITERATION

A statically allocated StopIteration used to signal exhaustion of an iterator, but providing no useful stack context.

Constructor Detail

PyObjectUtilback to summary
private PyObjectUtil()

Method Detail

functionStrback to summary
pack-priv static String functionStr(Object func)

Produce a String name for a function-like object or its str() if it doesn't even have a __qualname__.

    def functionStr(func):
        try:
            qualname = func.__qualname__
        except AttributeError:
            return str(func)
        try:
            module = func.__module__
            if module is not None and mod != 'builtins':
                return ".".join(module, qualname)
        except AttributeError:
            pass
        return qualname
This differs from its CPython counterpart _PyObject_FunctionStr by decisively not adding parentheses.
Parameters
func:Object

the function

Returns:String

a name for func

mapReprback to summary
pack-priv static String mapRepr(Map<? extends Object, ?> map) throws Throwable

An implementation of dict.__repr__ that may be applied to any Java Map between Objects, in which keys and values are represented as with repr().

Parameters
map:Map<? extends Object, ?>

to be reproduced

Returns:String

a string like {'a': 2, 'b': 3}

Exceptions
Throwable:
from the repr() implementation

toAtback to summary
pack-priv static String toAt(Object o)

A string along the lines "T object at 0xhhh", where T is the type of o. This is for creating default __repr__ implementations seen around the code base and containing this form. By implementing it here, we encapsulate the problem of qualified type name and what "address" or "identity" should mean.

Parameters
o:Object

the object (not its type)

Returns:String

string denoting o

org.python.core back to summary

public Class PyObjectUtil.NoConversion

extends Exception
Class Inheritance

The type of exception thrown when an attempt to convert an object to a common data type fails. This type of exception carries no stack context, since it is used only as a sort of "alternative return value".

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.Exception.serialVersionUID.

Constructor Detail

NoConversionback to summary
private NoConversion()