org.python.core

Class imp


public class imp
extends java.lang.Object

Utility functions for "import" support.

Field Summary

static int
APIVersion

Method Summary

static PyModule
addModule(String name)
If the given name is found in sys.modules, the entry from there is returned.
static boolean
caseok(File file, String filename, int namelen)
static byte[]
compileSource(String name, File file, String sourceFilename, String compiledFilename)
static PyObject
createFromSource(String name, InputStream fp, String filename)
static String
defaultEmptyPathDirectory(String directoryName)
If directoryName is empty, return a correct directory name for a path.
static ClassLoader
getSyspathJavaLoader()
static void
importAll(String mod, PyFrame frame)
Called 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 PyObject
importName(String name, boolean top)
Import a module by name.
static PyObject
importName(String name, boolean top, PyObject modDict, PyObject fromlist)
Import a module by name.
static PyObject
importOne(String mod, PyFrame frame)
Called from jython generated code when a statement like "import spam" is executed.
static PyObject
importOneAs(String mod, PyFrame frame)
Called from jython generated code when a statement like "import spam as foo" is executed.
static PyObject
load(String name)
Load the module by name.
static PyObject
loadFromCompiled(String name, InputStream stream, String filename)

Field Details

APIVersion

public static final int APIVersion
Field Value:
12

Method Details

addModule

public static PyModule addModule(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

caseok

public static boolean caseok(File file,
                             String filename,
                             int namelen)

compileSource

public static byte[] compileSource(String name,
                                   File file,
                                   String sourceFilename,
                                   String compiledFilename)

createFromSource

public static PyObject createFromSource(String name,
                                        InputStream fp,
                                        String filename)

defaultEmptyPathDirectory

public static String defaultEmptyPathDirectory(String directoryName)
If directoryName is empty, return a correct directory name for a path. If directoryName is not an empty string, this method returns directoryName unchanged.

getSyspathJavaLoader

public static ClassLoader getSyspathJavaLoader()

importAll

public static void importAll(String mod,
                             PyFrame frame)
Called from jython generated code when a statement like "from spam.eggs import *" is executed.

importFrom

public 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.

importFromAs

public 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.

importName

public static PyObject importName(String name,
                                  boolean top)
Import a module by name.
Parameters:
name - the name of the package to import
top - if true, return the top module in the name, otherwise the last
Returns:
an imported module (Java or Python)

importName

public static PyObject importName(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 import
top - if true, return the top module in the name, otherwise the last
modDict - the __dict__ of an already imported module
Returns:
an imported module (Java or Python)

importOne

public static PyObject importOne(String mod,
                                 PyFrame frame)
Called from jython generated code when a statement like "import spam" is executed.

importOneAs

public static PyObject importOneAs(String mod,
                                   PyFrame frame)
Called from jython generated code when a statement like "import spam as foo" is executed.

load

public static PyObject load(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

loadFromCompiled

public static PyObject loadFromCompiled(String name,
                                        InputStream stream,
                                        String filename)

Jython homepage