Package org.python.core
Class imp
java.lang.Object
org.python.core.imp
Utility functions for "import" support.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic PyModuleIf the given name is found in sys.modules, the entry from there is returned.static StringcacheCompiledSource(String sourceFilename, String compiledFilename, byte[] compiledSource) Stores the bytes in compiledSource in compiledFilename.static booleanstatic byte[]compileSource(String name, File file, String sourceFilename, String compiledFilename) static PyObjectcreateFromSource(String name, InputStream fp, String filename) static StringdefaultEmptyPathDirectory(String directoryName) IfdirectoryNameis empty, return a correct directory name for a path.static ClassLoaderstatic voidCalled from jython generated code when a statement like "from spam.eggs import *" is executed.static PyObject[]importFrom(String mod, String[] names, PyFrame frame) Called from jython generated code when a stamenet like "from spam.eggs import foo, bar" is executed.static PyObject[]importFromAs(String mod, String[] names, String[] asnames, PyFrame frame) Called from jython generated code when a statement like "from spam.eggs import foo as spam" is executed.static PyObjectimportName(String name, boolean top) Import a module by name.static PyObjectimportName(String name, boolean top, PyObject modDict, PyObject fromlist) Import a module by name.static PyObjectCalled from jython generated code when a statement like "import spam" is executed.static PyObjectimportOneAs(String mod, PyFrame frame) Called from jython generated code when a statement like "import spam as foo" is executed.static PyObjectLoad the module by name.static PyObjectloadFromCompiled(String name, InputStream stream, String filename)
-
Field Details
-
APIVersion
public static final int APIVersion- See Also:
-
-
Method Details
-
getSyspathJavaLoader
-
addModule
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
-
cacheCompiledSource
public static String cacheCompiledSource(String sourceFilename, 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
-
loadFromCompiled
-
defaultEmptyPathDirectory
IfdirectoryNameis empty, return a correct directory name for a path. IfdirectoryNameis not an empty string, this method returnsdirectoryNameunchanged. -
caseok
-
load
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
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
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
Called from jython generated code when a statement like "import spam" is executed. -
importOneAs
Called from jython generated code when a statement like "import spam as foo" is executed. -
importFrom
Called from jython generated code when a stamenet like "from spam.eggs import foo, bar" is executed. -
importFromAs
Called from jython generated code when a statement like "from spam.eggs import foo as spam" is executed. -
importAll
Called from jython generated code when a statement like "from spam.eggs import *" is executed.
-