Package org.python.core
Class imp
- java.lang.Object
-
- org.python.core.imp
-
public class imp extends java.lang.Object
Utility functions for "import" support.
-
-
Field Summary
Fields Modifier and Type Field Description static int
APIVersion
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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, int namelen)
static byte[]
compileSource(java.lang.String name, java.io.File file, java.lang.String sourceFilename, java.lang.String compiledFilename)
static PyObject
createFromSource(java.lang.String name, java.io.InputStream fp, java.lang.String filename)
static java.lang.String
defaultEmptyPathDirectory(java.lang.String directoryName)
IfdirectoryName
is empty, return a correct directory name for a path.static java.lang.ClassLoader
getSyspathJavaLoader()
static void
importAll(java.lang.String mod, PyFrame frame)
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)
Called from jython generated code when a stamenet like "from spam.eggs import foo, bar" is executed.static PyObject[]
importFromAs(java.lang.String mod, java.lang.String[] names, java.lang.String[] asnames, PyFrame frame)
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)
Import a module by name.static PyObject
importOne(java.lang.String mod, PyFrame frame)
Called from jython generated code when a statement like "import spam" is executed.static PyObject
importOneAs(java.lang.String mod, PyFrame frame)
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 filename)
-
-
-
Field Detail
-
APIVersion
public static final int APIVersion
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSyspathJavaLoader
public static java.lang.ClassLoader getSyspathJavaLoader()
-
addModule
public static PyModule addModule(java.lang.String name)
If the given name is found in sys.modules, the entry from there is returned. Otherwise a new PyModule is created for the name and added to sys.modules
-
compileSource
public static byte[] compileSource(java.lang.String name, java.io.File file, java.lang.String sourceFilename, java.lang.String compiledFilename)
-
cacheCompiledSource
public static java.lang.String cacheCompiledSource(java.lang.String sourceFilename, java.lang.String compiledFilename, byte[] compiledSource)
Stores the bytes in compiledSource in compiledFilename. If compiledFilename is null it's set to the results of makeCompiledFilename(sourcefileName) If sourceFilename is null or set to UNKNOWN_SOURCEFILE null is returned- Returns:
- the compiledFilename eventually used or null if a compiledFilename couldn't be determined of if an error was thrown while writing to the cache file.
-
createFromSource
public static PyObject createFromSource(java.lang.String name, java.io.InputStream fp, java.lang.String filename)
-
loadFromCompiled
public static PyObject loadFromCompiled(java.lang.String name, java.io.InputStream stream, java.lang.String filename)
-
defaultEmptyPathDirectory
public static java.lang.String defaultEmptyPathDirectory(java.lang.String directoryName)
IfdirectoryName
is empty, return a correct directory name for a path. IfdirectoryName
is not an empty string, this method returnsdirectoryName
unchanged.
-
caseok
public static boolean caseok(java.io.File file, java.lang.String filename, int namelen)
-
load
public static PyObject load(java.lang.String name)
Load the module by name. Upon loading the module it will be added to sys.modules.- Parameters:
name
- the name of the module to load- Returns:
- the loaded module
-
importName
public static PyObject importName(java.lang.String name, boolean top)
Import a module by name.- Parameters:
name
- the name of the package to importtop
- if true, return the top module in the name, otherwise the last- Returns:
- an imported module (Java or Python)
-
importName
public static PyObject importName(java.lang.String name, boolean top, PyObject modDict, PyObject fromlist)
Import a module by name. This is the default call for __builtin__.__import__.- Parameters:
name
- the name of the package to importtop
- if true, return the top module in the name, otherwise the lastmodDict
- the __dict__ of an already imported module- Returns:
- an imported module (Java or Python)
-
importOne
public static PyObject importOne(java.lang.String mod, PyFrame frame)
Called from jython generated code when a statement like "import spam" is executed.
-
importOneAs
public static PyObject importOneAs(java.lang.String mod, PyFrame frame)
Called from jython generated code when a statement like "import spam as foo" is executed.
-
importFrom
public static PyObject[] importFrom(java.lang.String mod, java.lang.String[] names, PyFrame frame)
Called from jython generated code when a stamenet like "from spam.eggs import foo, bar" is executed.
-
importFromAs
public static PyObject[] importFromAs(java.lang.String mod, java.lang.String[] names, java.lang.String[] asnames, PyFrame frame)
Called from jython generated code when a statement like "from spam.eggs import foo as spam" is executed.
-
importAll
public static void importAll(java.lang.String mod, PyFrame frame)
Called from jython generated code when a statement like "from spam.eggs import *" is executed.
-
-