}
throw Py.ImportError("No module named " + name);
}
public static PyObject load_module(String name, PyObject file, PyObject filename, PyTuple data) {
PyObject mod = Py.None;
int type = ((PyInteger) data.__getitem__(2).__int__()).getValue();
while (mod == Py.None) {
Object o = file.__tojava__(InputStream.class);
if (o == Py.NoConversion) {
throw Py.TypeError("must be a file-like object");
}
switch (type) {
case PY_SOURCE:
try {
mod = org.python.core.imp.createFromSource(name.intern(), FileUtil.readBytes((InputStream) o),
filename.toString());
} catch (IOException e1) {
throw Py.IOError(e1);
}
break;
case PY_COMPILED:
try {
mod = org.python.core.imp.loadFromCompiled(name.intern(), FileUtil.readBytes((InputStream) o),
filename.toString());
} catch (IOException e) {
throw Py.IOError(e);
}
break;
case PKG_DIRECTORY:
PyModule m = org.python.core.imp.addModule(name);
m.__dict__.__setitem__("__path__", new PyList(new PyObject[] { filename }));
m.__dict__.__setitem__("__file__", filename);
ModuleInfo mi = findFromSource(name, filename, true);
type = mi.type;
file = mi.file;
filename = new PyString(mi.filename);
break;
default:
throw Py.ImportError("No module named " + name);
}
}
PyObject modules = Py.getSystemState().modules;
modules.__setitem__(name.intern(), mod);
return mod;
}