public class imp
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
imp.CodeData
A bundle of a file name, the file's content and a last modified time, with no behaviour.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LEVEL |
static int |
NO_MTIME |
Modifier and Type | Method and Description |
---|---|
static PyModule |
addModule(java.lang.String name)
If the given name is found in sys.modules, the entry from there is returned.
|
static java.lang.String |
cacheCompiledSource(java.lang.String sourceFilename,
java.lang.String compiledFilename,
byte[] compiledSource)
Stores the bytes in compiledSource in compiledFilename.
|
static boolean |
caseok(java.io.File file,
java.lang.String filename)
Check that the canonical name of
file matches filename , case-sensitively,
even when the OS platform is case-insensitive. |
static byte[] |
compileSource(java.lang.String name,
java.io.File source)
Compile Python source in file to a class file represented by a byte array.
|
static byte[] |
compileSource(java.lang.String name,
java.io.File source,
java.lang.String filename)
Compile Python source in file to a class file represented by a byte array.
|
static byte[] |
compileSource(java.lang.String name,
java.io.File source,
java.lang.String sourceFilename,
java.lang.String compiledFilename)
Deprecated.
Use
compileSource(String, File, String) instead. |
static byte[] |
compileSource(java.lang.String name,
java.io.InputStream source,
java.lang.String filename)
Compile Python source to a class file represented by a byte array.
|
static byte[] |
compileSource(java.lang.String name,
java.io.InputStream source,
java.lang.String filename,
long mtime)
Compile Python source to a class file represented by a byte array.
|
static PyObject |
createFromCode(java.lang.String name,
PyCode c)
Returns a module with the given name whose contents are the results of running c.
|
static PyObject |
createFromCode(java.lang.String name,
PyCode c,
java.lang.String moduleLocation)
Return a Python module with the given
name whose attributes are the result of running
PyCode c . |
static PyObject |
createFromSource(java.lang.String name,
java.io.InputStream fp,
java.lang.String filename) |
static PyObject |
createFromSource(java.lang.String name,
java.io.InputStream fp,
java.lang.String filename,
java.lang.String outFilename) |
static PyObject |
createFromSource(java.lang.String name,
java.io.InputStream fp,
java.lang.String filename,
java.lang.String outFilename,
long mtime)
Compile Jython source (as an
InputStream ) to a module. |
static int |
getAPIVersion() |
static PyObject |
getImporter(PyObject p) |
static java.lang.ClassLoader |
getParentClassLoader()
Selects the parent class loader for Jython, to be used for dynamically loaded classes and
resources.
|
static java.lang.ClassLoader |
getSyspathJavaLoader() |
static void |
importAll(PyObject module,
PyFrame frame) |
static void |
importAll(java.lang.String mod,
PyFrame frame)
Deprecated.
|
static void |
importAll(java.lang.String mod,
PyFrame frame,
int level)
Called from jython generated code when a statement like "from spam.eggs import *" is
executed.
|
static PyObject[] |
importFrom(java.lang.String mod,
java.lang.String[] names,
PyFrame frame)
Deprecated.
use importFrom with level param.
|
static PyObject[] |
importFrom(java.lang.String mod,
java.lang.String[] names,
PyFrame frame,
int level)
Called from jython generated code when a statement like "from spam.eggs import foo, bar" is
executed.
|
static PyObject[] |
importFromAs(java.lang.String mod,
java.lang.String[] names,
PyFrame frame)
Deprecated.
use importFromAs with level param.
|
static PyObject[] |
importFromAs(java.lang.String mod,
java.lang.String[] names,
java.lang.String[] asnames,
PyFrame frame,
int level)
Called from jython generated code when a statement like "from spam.eggs import foo as spam"
is executed.
|
static PyObject |
importName(java.lang.String name,
boolean top)
Import a module by name.
|
static PyObject |
importName(java.lang.String name,
boolean top,
PyObject modDict,
PyObject fromlist,
int level)
Import a module by name.
|
static PyObject |
importOne(java.lang.String mod,
PyFrame frame)
Deprecated.
|
static PyObject |
importOne(java.lang.String mod,
PyFrame frame,
int level)
Called from jython generated code when a statement like "import spam" is executed.
|
static PyObject |
importOneAs(java.lang.String mod,
PyFrame frame)
Deprecated.
|
static PyObject |
importOneAs(java.lang.String mod,
PyFrame frame,
int level)
Called from jython generated code when a statement like "import spam as foo" is executed.
|
static PyObject |
load(java.lang.String name)
Load the module by name.
|
static PyObject |
loadFromCompiled(java.lang.String name,
java.io.InputStream stream,
java.lang.String sourceName,
java.lang.String compiledName) |
static java.lang.String |
makeCompiledFilename(java.lang.String filename)
Remove the last three characters of a file name and add the compiled suffix "$py.class".
|
static byte[] |
readCode(java.lang.String name,
java.io.InputStream fp,
boolean testing)
As
readCodeData(String, InputStream, boolean, long) but do not check last-modified
time and return only the class file bytes as an array. |
static byte[] |
readCode(java.lang.String name,
java.io.InputStream fp,
boolean testing,
long sourceLastModified)
As
readCodeData(String, InputStream, boolean, long) but return only the class file
bytes as an array. |
static imp.CodeData |
readCodeData(java.lang.String name,
java.io.InputStream fp,
boolean testing)
As
readCodeData(String, InputStream, boolean, long) but do not check last-modified
time. |
static imp.CodeData |
readCodeData(java.lang.String name,
java.io.InputStream fp,
boolean testing,
long sourceLastModified)
Create a
imp.CodeData object bundling the contents of a class file (given as a stream),
source-last-modified time supplied, and the name of the file taken from annotations on the
class. |
public static final int NO_MTIME
public static final int DEFAULT_LEVEL
public static java.lang.ClassLoader getSyspathJavaLoader()
public static java.lang.ClassLoader getParentClassLoader()
public static PyModule addModule(java.lang.String name)
PyModule
is created for the name and added to sys.modules
. Creating the
module does not execute the body of the module to initialise its attributes.name
- fully-qualified name of the modulePyModule
public static byte[] readCode(java.lang.String name, java.io.InputStream fp, boolean testing) throws java.io.IOException
readCodeData(String, InputStream, boolean, long)
but do not check last-modified
time and return only the class file bytes as an array.name
- of source file (used for identification in error/log messages)fp
- stream from which to read class file (closed when read)testing
- if true
, failures are signalled by a null
not an exceptionnull
on failure (if testing
).PyException
- ImportError
on API or last-modified time mismatchjava.io.IOException
- from read failurespublic static byte[] readCode(java.lang.String name, java.io.InputStream fp, boolean testing, long sourceLastModified) throws java.io.IOException
readCodeData(String, InputStream, boolean, long)
but return only the class file
bytes as an array.name
- of source file (used for identification in error/log messages)fp
- stream from which to read class file (closed when read)testing
- if true
, failures are signalled by a null
not an exceptionsourceLastModified
- time expected to match MTime
annotation in the class filenull
on failure (if testing
).PyException
- ImportError
on API or last-modified time mismatchjava.io.IOException
- from read failurespublic static imp.CodeData readCodeData(java.lang.String name, java.io.InputStream fp, boolean testing) throws java.io.IOException
readCodeData(String, InputStream, boolean, long)
but do not check last-modified
time.name
- of source file (used for identification in error/log messages)fp
- stream from which to read class file (closed when read)testing
- if true
, failures are signalled by a null
not an exceptionCodeData
bundle or null
on failure (if testing
).PyException
- ImportError
on API mismatchjava.io.IOException
- from read failurespublic static imp.CodeData readCodeData(java.lang.String name, java.io.InputStream fp, boolean testing, long sourceLastModified) throws java.io.IOException, PyException
imp.CodeData
object bundling the contents of a class file (given as a stream),
source-last-modified time supplied, and the name of the file taken from annotations on the
class. On the way, the method checks the API version annotation matches the current process,
and that the org.python.compiler.MTime
annotation matches the source-last-modified
time passed in.name
- of source file (used for identification in error/log messages)fp
- stream from which to read class file (closed when read)testing
- if true
, failures are signalled by a null
not an exceptionsourceLastModified
- time expected to match MTime
annotation in the class fileCodeData
bundle or null
on failure (if testing
).PyException
- ImportError
on API or last-modified time mismatchjava.io.IOException
- from read failurespublic static byte[] compileSource(java.lang.String name, java.io.File source)
name
- of module (class name will be name$py)source
- file containing the sourcepublic static byte[] compileSource(java.lang.String name, java.io.File source, java.lang.String filename)
name
- of module (class name will be name$py)source
- file containing the sourcefilename
- explicit source file name (or null
to use that in source)@Deprecated public static byte[] compileSource(java.lang.String name, java.io.File source, java.lang.String sourceFilename, java.lang.String compiledFilename)
compileSource(String, File, String)
instead.name
- of module (class name will be name$py)source
- file containing the sourcesourceFilename
- explicit source file name (or null
to use that in source)compiledFilename
- ignored (huh?)public static java.lang.String makeCompiledFilename(java.lang.String filename)
public static java.lang.String cacheCompiledSource(java.lang.String sourceFilename, java.lang.String compiledFilename, byte[] compiledSource)
public static byte[] compileSource(java.lang.String name, java.io.InputStream source, java.lang.String filename)
name
- of module (class name will be name$py)source
- open input stream (will be closed)filename
- of source (or null
if unknown)public static byte[] compileSource(java.lang.String name, java.io.InputStream source, java.lang.String filename, long mtime)
name
- of module (class name will be name$py)source
- open input stream (will be closed)filename
- of source (or null
if unknown)mtime
- last-modified time of source, to annotate classpublic static PyObject createFromSource(java.lang.String name, java.io.InputStream fp, java.lang.String filename)
public static PyObject createFromSource(java.lang.String name, java.io.InputStream fp, java.lang.String filename, java.lang.String outFilename)
public static PyObject createFromSource(java.lang.String name, java.io.InputStream fp, java.lang.String filename, java.lang.String outFilename, long mtime)
InputStream
) to a module.name
- of the module to create (class will be name$py)fp
- opened on the (Jython) source to compile (will be closed)filename
- of the source backing fp
(to embed in class as data)outFilename
- in which to write the compiled classmtime
- last modified time of the file backing fp
public static PyObject createFromCode(java.lang.String name, PyCode c)
public static PyObject createFromCode(java.lang.String name, PyCode c, java.lang.String moduleLocation)
name
whose attributes are the result of running
PyCode c
. If moduleLocation != null
it is used to set __file__
.
In normal circumstances, if c
comes from a local .py
file or compiled
$py.class
class the caller should should set moduleLocation
to something like
new File(moduleLocation).getAbsolutePath()
. If c
comes from a remote file or
is a JAR, moduleLocation
should be the full URI for that source or class.
name
- fully-qualified name of the modulec
- code supplying the modulemoduleLocation
- to become __file__
if not null
public static PyObject loadFromCompiled(java.lang.String name, java.io.InputStream stream, java.lang.String sourceName, java.lang.String compiledName)
public static boolean caseok(java.io.File file, java.lang.String filename)
file
matches filename
, case-sensitively,
even when the OS platform is case-insensitive. This is used to obtain as a check during
import on platforms (Windows) that may be case-insensitive regarding file open. It is assumed
that file
was derived from attempting to find filename
, so it returns
true
on a case-sensitive platform.
Algorithmically, we return true
if any of the following is true:
Options.caseok
is true
(default is false
).PlatformUtil.isCaseInsensitive()
)file
starts with filename
file
equals
filename
file
- to be testedfilename
- to be matchedfile
matches filename
public static PyObject load(java.lang.String name)
name
- the name of the module to loadpublic static PyObject importName(java.lang.String name, boolean top)
name
- the name of the package to importtop
- if true, return the top module in the name, otherwise the lastpublic static PyObject importName(java.lang.String name, boolean top, PyObject modDict, PyObject fromlist, int level)
__import__()
function
__builtin__.__import__
. Locks the import system while it operates.name
- the fully-qualified name of the package/module to importtop
- if true, return the top module in the name, otherwise the lastmodDict
- the __dict__ of the importing module (used for name in relative import)fromlist
- list of names being importedlevel
- 0=absolute, n>0=relative levels to go up, -1=try relative then absolute.@Deprecated public static PyObject importOne(java.lang.String mod, PyFrame frame)
public static PyObject importOne(java.lang.String mod, PyFrame frame, int level)
@Deprecated public static PyObject importOneAs(java.lang.String mod, PyFrame frame)
public static PyObject importOneAs(java.lang.String mod, PyFrame frame, int level)
@Deprecated public static PyObject[] importFrom(java.lang.String mod, java.lang.String[] names, PyFrame frame)
public static PyObject[] importFrom(java.lang.String mod, java.lang.String[] names, PyFrame frame, int level)
@Deprecated public static PyObject[] importFromAs(java.lang.String mod, java.lang.String[] names, PyFrame frame)
public static PyObject[] importFromAs(java.lang.String mod, java.lang.String[] names, java.lang.String[] asnames, PyFrame frame, int level)
public static void importAll(java.lang.String mod, PyFrame frame, int level)
@Deprecated public static void importAll(java.lang.String mod, PyFrame frame)
public static int getAPIVersion()