public class MiniPython extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
MiniPython.Client
Provide platform behaviour
|
class |
MiniPython.ExecutionError
Encapsulates what would be an Exception in Python.
|
Constructor and Description |
---|
MiniPython() |
Modifier and Type | Method and Description |
---|---|
void |
addModule(String name,
Object object)
Makes methods on the methods Object available to the Python
|
Object |
callMethod(String name,
Object... args)
Calls a method in Python and returns the result
|
void |
clear()
Removes all internal state.
|
void |
setClient(MiniPython.Client client)
Callbacks to use for specific behaviour
|
void |
setCode(InputStream stream)
Reads and executes code from the supplied stream
The stream provided must satisfy reads completely (eg if 27 bytes is
asked for then that number should be returned in the read() call unless
end of file is reached.)
|
void |
signalError(String exctype,
String message)
Call this method when your callbacks need to halt execution due to an
error
This method will do the internal bookkeeping necessary in order to
provide diagnostics to the original caller and then throw an
ExecutionError which you should not catch.
|
void |
signalError(String exctype,
String message,
Throwable cause)
Call this method when your callbacks need to halt execution due to an
error
This method will do the internal bookkeeping necessary in order to
provide diagnostics to the original caller and then throw an
ExecutionError which you should not catch.
|
static String |
toPyReprString(Object o)
Same as toPyString except strings are quoted and backslash escaped.
|
static String |
toPyString(Object o)
Returns a string representing the object using Python nomenclature where
possible
For example `null` is returned as `None`, `true` as `True` etc.
|
static String |
toPyTypeString(Object o)
Returns a string representing the type of the object using Python
nomenclature where possible
For example `null` is returned as `NoneType`, `true` as `bool`, `Map` as
`dict` etc.
|
public void clear()
public void setCode(InputStream stream) throws IOException, MiniPython.ExecutionError
stream
- The stream is not closed and you can have additional content
after the jmp.IOException
- Passed on from read() calls on the streamEOFException
- When the stream is truncatedMiniPython.ExecutionError
- Any issues from executing the codepublic Object callMethod(String name, Object... args) throws MiniPython.ExecutionError
name
- Global method nameargs
- Variable list of arguments that it takesMiniPython.ExecutionError
- On any issues encounteredpublic void signalError(String exctype, String message) throws MiniPython.ExecutionError
exctype
- Best practise is to use the name of a Python exception (eg
"TypeError")message
- Text describing the error.MiniPython.ExecutionError
- Always thrownpublic void signalError(String exctype, String message, Throwable cause) throws MiniPython.ExecutionError
exctype
- Best practise is to use the name of a Python exception (eg
"TypeError")message
- Text describing the error.cause
- The underlying reason why this exception is being causedMiniPython.ExecutionError
- Always thrownpublic static String toPyString(Object o)
o
- Object to stringify. Can be null.public static String toPyReprString(Object o)
o
- Object to stringify. Can be null.public static String toPyTypeString(Object o)
o
- Object whose type to stringify, or a Class or nullpublic void setClient(MiniPython.Client client)
client
- Replaces existing client with this onepublic void addModule(String name, Object object)
name
- Module name in the Python environmentobject
- Object to introspect looking for methods