Top Inners Fields Constructors Methods
org.python.core

public final Class Py

Additional top-level classes in compilation unit: FixedFileWrapper, JavaCode, JavaFunc.

extends PrePy
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .CharArrayWriter, .File, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .ObjectStreamException, .OutputStream, .PrintWriter, .Serializable, .StreamCorruptedException, java.lang.reflect.InvocationTargetException, .Method, java.sql.Date, .Time, .Timestamp, java.util.ArrayList, .Calendar, .List, java.util.logging.Level, org.python.antlr.base.mod, org.python.core.adapter.ClassicPyObjectAdapter, .ExtensiblePyObjectAdapter, org.python.modules.posix.PosixModule, jline.console.UserInterruptException, jnr.constants.Constant, jnr.constants.platform.Errno, jnr.posix.util.Platform

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static ExtensiblePyObjectAdapter
adapter

Handles wrapping Java objects in PyObject to expose them to jython.

public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
private static final PyString[]
bytes

Table used by makeCharacter(char) to intern single byte strings.

public static PyObject
private static Console
console

The handler for interactive consoles, set by installConsole(Console) and accessed by getConsole().

public static volatile PySystemState
public static PyObject
public static final PyObject
Ellipsis

The singleton Ellipsis Python object - written as ...

public static final PyFrozenSet
EmptyFrozenSet

A frozenset with zero elements

public static final PyObject[]
EmptyObjects

A zero-length array of PyObject's to pass to functions when we have no arguments

public static final PyString
EmptyString

A zero-length Python byte string

public static final PyTuple
EmptyTuple

A tuple with zero elements

public static final PyUnicode
EmptyUnicode

A zero-length Python Unicode string

public static PyObject
public static PyObject
public static PyObject
public static final PyBoolean
False

The Python boolean False

public static PyObject
public static PyObject
public static PyObject
private static IdImpl
private static final String
public static PyObject
public static PyObject
public static PyObject
public static PyObject
private static final PyInteger[]
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
private static int
public static final PyString
Newline

A Python string containing '\n'

public static final Object
NoConversion

A unique object to indicate no conversion is possible in __tojava__ methods

public static final String[]
NoKeywords

A zero-length array of Strings to pass to functions that don't have any keyword arguments

public static final PyObject
None

The singleton None Python object

public static final PyObject
NotImplemented

The singleton NotImplemented Python object.

public static PyObject
public static final PyInteger
One

The Python integer 1

public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static final PyString
Space

A Python string containing ' '

public static PyObject
public static StdoutWrapper
pack-priv static StdoutWrapper
public static PyObject
public static PyObject
public static PyObject
private static boolean
public static PyObject
public static PyObject
public static PyObject
private static final ThreadStateMapping
public static final long
TPFLAGS_BASETYPE

Set if the type allows subclassing

public static final long
TPFLAGS_HEAPTYPE

Set if the type object is dynamically allocated

public static final long
TPFLAGS_IS_ABSTRACT

Type is abstract and cannot be instantiated

public static final PyBoolean
True

The Python boolean True

public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static final PyUnicode
UnicodeNewline

A Python unicode string containing '\n'

public static final PyUnicode
UnicodeSpace

A Python unicode string containing ' '

public static PyObject
public static PyObject
public static PyObject
public static PyObject
public static PyObject
private static PyObject
public static final PyInteger
Zero

The Python integer 0

public static PyObject
Inherited from org.python.core.PrePy:
COMMENTDEBUGERRORimportLoggerloggerMESSAGEWARNING

Constructor Summary

AccessConstructor and Description
private
Py()

Method Summary

Modifier and TypeMethod and Description
private static PyTuple
abstractGetBases(PyObject cls)

Return the __bases__ of cls.

private static boolean
public static void
private static void
appendSyntaxError(StringBuilder buf, PyObject value)

Helper to tracebackToString(PyObject, PyObject) when the value in an exception turns out to be a syntax error.

private static void
appendSyntaxErrorText(StringBuilder
to append with generated message text
buf
,
int
the offset into text
offset
,
String
a source code line
text
)

Generate two lines showing where a SyntaxError was caused.

private static String
asMessageString(PyObject value, boolean useRepr)

Defensive method to avoid exceptions from decoding (or import encodings)

public static void
assert_(PyObject test, PyObject message)

public static void
public static PyException
public static PyException
public static PyException
public static void
private static void
checkClass(PyObject cls, String message)

Throw a TypeError with the specified message if cls does not appear to be a Python class.

public static PyCode
compile(InputStream istream, String filename, CompileMode kind)

public static PyObject
compile_command_flags(String string, String filename, CompileMode kind, CompilerFlags cflags, boolean stdprompt)

public static PyCode

Returns:

Code object for the compiled module
compile_flags
(mod
Module node, coming from the parsing process
node
,
String
Internal name for the compiled code. Typically generated by calling getName().
name
,
String
Source file name
filename
,
boolean
True to track source line numbers on the generated code
linenumbers
,
boolean
True to call the sys.displayhook on the result of the code
printResults
,
CompilerFlags
Compiler flags
cflags
)

Entry point for compiling modules.

public static PyCode
compile_flags(mod node, String filename, CompileMode kind, CompilerFlags cflags)

public static PyCode
compile_flags(InputStream istream, String filename, CompileMode kind, CompilerFlags cflags)

Compiles python source code coming from a file or another external stream

public static PyCode
compile_flags(String data, String filename, CompileMode kind, CompilerFlags cflags)

Compiles python source code coming from String (raw bytes) data.

public static void
private static PyObject

Returns:

null if cls provides no checker, otherwise the result of calling the checker
dispatchToChecker
(PyObject
the argument to call the checker with
checkerArg
,
PyObject
a Python class
cls
,
String
the checker name
checkerName
)

Attempt to dispatch an isinstance/issubclass call to cls's associated __instancecheck__/__subclasscheck__.

public static void
displayException(PyObject
of exception
type
,
PyObject
the exception parameter (second argument to raise)
value
,
PyObject
traceback of the call stack where the exception originally occurred
tb
,
PyObject
to print encoded string to, or null meaning standard error
file
)

Print the description of an exception as a big string.

protected static PyObject
ensureInterface(PyObject cls, Class<?> interfce)

public static PyException
public static PyException
EOFError(String message)

private static PyString
exceptionToBytes(PyObject type, PyObject value, PyObject tb, String encoding, String errors)

Helper for displayException(PyObject, PyObject, PyObject, PyObject), falling back to US-ASCII as the last resort encoding.

pack-priv static String

Returns:

string representation of the traceback and exception
exceptionToString
(PyObject
of exception
type
,
PyObject
the exception parameter (second argument to raise)
value
,
PyObject
traceback of the call stack where the exception originally occurred
tb
)

Format the description of an exception as a big string.

public static void
exec(PyObject o, PyObject globals, PyObject locals)

public static String

Returns:

unicode version of path
fileSystemDecode
(PyString
as bytes to decode, or already as unicode
filename
)

Return a file name or path as Unicode (Java UTF-16 String), decoded if necessary from a Python bytes object, using the file system encoding.

public static String

Returns:

unicode version of the file name
fileSystemDecode
(PyObject
as bytes to decode, or already as unicode
filename
)

As fileSystemDecode(PyString) but raising ValueError if not a str or unicode.

private static List<String>

Returns:

equivalent Java list
fileSystemDecode
(PyList
a Python search path
path
)

Convert a PyList path to a list of Java String objects decoded from the path elements to strings guaranteed usable in the Java API.

public static PyString

Returns:

encoded bytes version of path
fileSystemEncode
(String
as unicode to encode, or already as bytes
filename
)

Return a PyString object we can use as a file name or file path in places where Python expects a bytes (that is a str) object in the file system encoding.

public static PyString

Returns:

encoded bytes version of path
fileSystemEncode
(PyString
as unicode to encode, or already as bytes
filename
)

Return a PyString object we can use as a file name or file path in places where Python expects a bytes (that is, str) object in the file system encoding.

public static Class<?>

Returns:

the class, or null if it wasn't found or something went wrong
findClass
(String
of the Java class.
name
)

Find and load a Java class by name.

public static Class<?>

Returns:

the class, or null if it simply wasn't found
findClassEx
(String
Name of the Java class.
name
,
String
for finding the class. Used in debugging messages.
reason
)

Find and load a Java class by name.

private static Class<?>

Returns:

the loaded class
findClassInternal
(String
of the Java class to load and initialise
name
,
String
to be given in debug output (or null to suppress debug output.
reason
)

Common code for findClass(String) and findClassEx(String, String).

private static void
findClassTrying(String name, String reason, ClassLoader cl, String place)

public static PyException
public static void
public static String
public static String
formatException(PyObject type, PyObject value, boolean useRepr)

private static PyException
public static void
public static PyException
public static ExtensiblePyObjectAdapter

Returns:

the ExtensiblePyObjectAdapter used by java2py.
getAdapter
()

private static String
getAttr(PyObject target, String internedName, String def)

Get a String attribute from an object or a return a default.

public static CompilerFlags
public static CompilerFlags
getCompilerFlags(int flags, boolean dont_inherit)

public static CompilerFlags
getCompilerFlags(CompilerFlags flags, boolean dont_inherit)

public static Console

Returns:

the Jython Console
getConsole
()

Get the Jython Console (used for input(), raw_input(), etc.) as constructed and set by PySystemState initialization.

public static PyString
getenv(PyString name)

The same as getenv(name, null).

public static PyString

Returns:

the corresponding value or defaultValue.
getenv
(PyString
of the environment variable.
name
,
PyString
to return if key is not defined (may be null.
defaultValue
)

Get the value of the environment variable named from os.environ or return the given default value.

public static String
getenv(String name)

The same as getenv(name, null).

public static String

Returns:

the corresponding value or defaultValue.
getenv
(String
to access in the environment.
name
,
String
to return if key is not defined.
defaultValue
)

Get the value of the environment variable named from os.environ or return the given default value.

private static PyObject

Returns:

os.environ
getEnvironment
()

Get the environment variables from os.environ.

public static PyFrame
public static synchronized String
private static String
public static final PySystemState
public static final ThreadState
public static final ThreadState
getThreadState(PySystemState newSystemState)

pack-priv static void
handleSystemExit(PyException
supplies the message or exit status
exc
)

Exit the process, if Options#inspect==false, cleaning up the system state.

public static long
public static String
public static PyException
public static boolean
public static void
private static PyObject
public static PyException
IndexError(String message)

pack-priv static void
private static PyObject
initExc(String name, PyObject exceptions, PyObject dict)

public static void
initProxy(PyProxy proxy, String module, String pyclass, Object[] args)

public static synchronized boolean
public static void
installConsole(Console
The new Console object
console
)

Install the provided Console, first uninstalling any current one.

public static PyException
public static PyException
IOError(String message)

public static PyException
public static PyException
IOError(Constant errno, String filename)

public static PyException
IOError(Constant errno, PyObject filename)

public static boolean
public static boolean
public static PyObject
iter(PyObject seq, String message)

public static PyObject
java2py(Object o)

Uses the PyObjectAdapter passed to PySystemState#initialize to turn o into a PyObject.

public static long
public static PyException
public static synchronized PyObject

Returns:

a Python-class that extends cls and interfce
javaPyClass
(PyObject cls, Class<?> interfce)

Returns a Python-class that extends cls and interfce.

public static PyObject[]
javas2pys(Object... objects)

Uses the PyObjectAdapter passed to PySystemState#initialize to turn objects into an array of PyObjects.

public static PyException
public static PyException
KeyError(String message)

public static PyException
private static Class<?>
pack-priv static PyObject[]

Returns:

array of elements from iterable
make_array
(PyObject
to evaluate
iterable
)

Turn any Python iterable into an array of its elements.

public static final PyString
public static final PyString
makeCharacter(char c)

public static PyObject
makeClass(String name, PyObject[] bases, PyCode code)

public static PyObject
makeClass(String name, PyObject[] bases, PyCode code, PyObject[] closure_cells)

public static PyObject
makeClass(String name, PyObject base, PyObject dict)

public static PyObject

Returns:

a new Python Class PyObject
makeClass
(String
the String name of the class
name
,
PyObject[]
an array of PyObject base classes
bases
,
PyObject
the class's namespace, containing the class body definition
dict
)

Create a new Python class.

public static PyException
makeException(PyObject type, PyObject value, PyObject traceback)

public static PyException
public static PyException
public static PyException
private static File
public static final PyUnicode
makeUnicodeCharacter(int codepoint)

public static boolean
matchException(PyException pye, PyObject exc)
Deprecated As of Jython 2.5, use PyException#match instead.

pack-priv static void
public static void
public static PyException
public static PyException
NameError(String message)

public static PyBoolean
newBoolean(boolean t)

pack-priv static PyString

Returns:

a new PyString
newBytes
(String
character codes are all < 256.
s
)

Return a not-necessarily new PyString from a Java String where the caller guarantees that the character codes are all < 256.

public static PyCode
newCode(int argcount, String[] varnames, String filename, String name, boolean args, boolean keywords, PyFunctionTable funcs, int func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags)

public static PyCode
newCode(int argcount, String[] varnames, String filename, String name, int firstlineno, boolean args, boolean keywords, PyFunctionTable funcs, int func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags)

public static PyCode
newCode(int argcount, String[] varnames, String filename, String name, boolean args, boolean keywords, PyFunctionTable funcs, int func_id)

public static PyCode
newCode(int argcount, String[] varnames, String filename, String name, int firstlineno, boolean args, boolean keywords, PyFunctionTable funcs, int func_id)

public static PyObject
newDate(Date date)

public static PyObject
public static PyObject
newDecimal(String decimal)

public static PyFloat
newFloat(float v)

public static PyFloat
newFloat(double v)

public static PyComplex
newImaginary(double v)

public static final PyInteger
newInteger(int i)

public static PyObject
newInteger(long i)

public static <T> T

Returns:

an instance of cls in form of the interface jcls
newJ
(PyObject
- the class to be instanciated
cls
,
Class<T>
- the Java-type to be returned
jcls
,
Object...
are automatically converted to Jython-PyObjects
args
)

This method is a compact helper to access Python-constructors from Java.

public static <T> T

Returns:

an instance of cls in form of the interface jcls
newJ
(PyObject
- the class to be instanciated
cls
,
Class<T>
- the Java-type to be returned
jcls
,
PyObject[]
for the Python-class constructor
args
,
String[]
are applied to the last args
keywords
)

This method is a compact helper to access Python-constructors from Java.

public static <T> T

Returns:

an instance of cls in form of the interface jcls
newJ
(PyObject
- the class to be instanciated
cls
,
Class<T>
- the Java-type to be returned
jcls
,
String[]
are applied to the last args
keywords
,
Object...
are automatically converted to Jython-PyObjects
args
)

This method is a compact helper to access Python-constructors from Java.

public static <T> T

Returns:

a new instance of the desired class
newJ
(PyModule
the module containing the desired class
module
,
Class<T>
Java-type of the desired clas, must have the same name
jcls
,
Object...
constructor-arguments
args
)

Works like newJ(PyObject, Class, Object...), but looks up the Python-class in the module-dict using the interface-name, i.e. jcls.getSimpleName().

public static <T> T

Returns:

a new instance of the desired class
newJ
(PyModule
the module containing the desired class
module
,
Class<T>
Java-type of the desired class, must have the same name
jcls
,
String[]
are applied to the last args in the list
keywords
,
Object...
constructor-arguments
args
)

Works like newJ(PyObject, Class, String[], Object...), but looks up the Python-class in the module-dict using the interface-name, i.e. jcls.getSimpleName().

public static PyCode
newJavaCode(Class<?> cls, String name)

public static PyObject
newJavaFunc(Class<?> cls, String name)

public static PyLong
public static PyLong
public static PyLong
newLong(int i)

public static PyLong
newLong(long l)

public static PyString

Returns:

a new or re-used PyString
newString
(char
character codes < 256.
c
)

Return a not-necessarily new PyString from a Java char.

pack-priv static PyString

Returns:

a new or re-used PyString
newString
(String
character codes are all < 256.
s
,
boolean
is true if the caller promises the codes are all < 256.
promise
)

Return a not-necessarily new PyString from a Java String.

public static PyString

Returns:

a new or re-used PyString
newString
(String
character codes should all be < 256 or an error occurs.
s
)

Return a not-necessarily new PyString from a Java String.

public static PyStringMap
public static PyString

Returns:

PyString or PyUnicode according to content of s.
newStringOrUnicode
(String
string content
s
)

Return a PyString for the given Java String, if it can be represented as US-ASCII, and a PyUnicode otherwise.

public static PyString

Returns:

PyString or PyUnicode according to content of s.
newStringOrUnicode
(PyObject
string of which the type sets a precedent
precedent
,
String
string content
s
)

Return a PyString for the given Java String, if it can be represented as US-ASCII and if a preceding object is not a PyUnicode, and a PyUnicode otherwise.

public static PyString
public static PyObject
newTime(Time time)

public static PyUnicode

Returns:

a new or re-used PyUnicode
newUnicode
(char
to convert to a PyUnicode.
c
)

Return a not-necessarily new PyUnicode from a Java char.

public static PyUnicode

Returns:

a new or re-used PyUnicode
newUnicode
(String
to wrap as a PyUnicode.
s
)

Return a not-necessarily new PyUnicode from a Java String.

public static PyUnicode
newUnicode(String s, boolean isBasic)

public static PyException
public static PyException
OSError(String message)

public static PyException
public static PyException
public static PyException
OSError(Constant errno, PyObject filename)

public static PyException
public static void
public static void
public static void
public static void
printException(Throwable
to display
t
)

Display an exception and stack trace through printException(Throwable, PyFrame, PyObject).

public static void
printException(Throwable
to display
t
,
PyFrame
frame at which to start the stack trace
f
)

Display an exception and stack trace through printException(Throwable, PyFrame, PyObject).

public static synchronized void
printException(Throwable
to display
t
,
PyFrame
frame at which to start the stack trace
f
,
PyObject
output onto this stream or Py#stderr if null
file
)

Display an exception and stack trace.

public static void
public static void
public static void
public static void
public static void
public static boolean
public static byte
public static char
public static char
public static double
public static float
public static int
public static int
public static long
public static short
public static void
pack-priv static boolean
pack-priv static boolean
public static PyException
public static PyObject
runCode(PyCode code, PyObject locals, PyObject globals)

public static void
runMain(PyRunnable main, String[] args)

Initializes a default PythonInterpreter and runs the code from PyRunnable#getMain as __main__ Called by the code generated in org.python.compiler.Module#addMain()

public static void
runMain(CodeBootstrap main, String[] args)

Initializes a default PythonInterpreter and runs the code loaded from the CodeBootstrap as __main__ Called by the code generated in org.python.compiler.Module#addMain()

public static PyException
public static void
public static void
protected static void
setAdapter(ExtensiblePyObjectAdapter
The new ExtensiblePyObjectAdapter
adapter
)

Set the ExtensiblePyObjectAdapter used by java2py.

public static PyException
public static void
public static final PySystemState
setSystemState(PySystemState newSystemState)

public static PyException
public static PyException
public static void
public static PyException
public static <T> T
tojava(PyObject
the PyObject to convert.
o
,
Class<T>
the class to convert it to.
c
)

Convert a given PyObject to an instance of a Java class.

public static Object
public static PyException
TypeError(String message)

public static PyException
public static PyException
UnicodeDecodeError(String encoding, String object, int start, int end, String reason)

public static PyException
UnicodeEncodeError(String encoding, String object, int start, int end, String reason)

public static PyException
public static PyException
UnicodeTranslateError(String object, int start, int end, String reason)

public static void
public static PyObject[]
unpackSequence(PyObject obj, int length)

public static void
public static PyException
ValueError(String message)

private static String
public static void
Warning(String message)

public static void
warning(PyObject category, String message)

public static void
warning(PyObject category, String message, int stacklevel)

public static void
warning(PyObject category, String message, String filename, int lineno, String module, PyObject registry)

public static void
warnPy3k(String message)

public static void
warnPy3k(String message, int stacklevel)

public static void
public static PyException
Inherited from org.python.core.PrePy:
getCommandResultgetCommandResultWindowsgetDefaultBinDirgetDefaultExecutableNamegetJarFileNamegetJarFileNameFromURLgetLoggingLevelgetSystemPropertiesgetSystemPropertyhaveConsoleincreaseLoggingLevelisInteractiveisInteractivelevelFromVerbositymaybeWritesetLoggingLevelverbosityFromLevelwriteCommentwriteDebugwriteErrorwriteMessagewriteWarning