Update of /cvsroot/jython/jython/org/python/modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv10876
Modified Files:
cPickle.java
Log Message:
find_class(): Use the __import__ method for importing modules.
This matches the behaviour from CPython's cPickle.
Index: cPickle.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/modules/cPickle.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** cPickle.java 2000/10/20 09:52:21 1.11
--- cPickle.java 2000/11/29 18:57:09 1.12
***************
*** 350,354 ****
static {
! PyObject excModule = imp.load("cPickle_exceptions");
PickleError = excModule.__getattr__("PickleError");
--- 350,354 ----
static {
! PyObject excModule = importModule("cPickle_exceptions");
PickleError = excModule.__getattr__("PickleError");
***************
*** 506,510 ****
imp.importName("__builtin__", true);
! PyModule copyreg = (PyModule)imp.importName("copy_reg", true);
dispatch_table = (PyDictionary)copyreg.__getattr__("dispatch_table");
--- 506,510 ----
imp.importName("__builtin__", true);
! PyModule copyreg = (PyModule)importModule("copy_reg");
dispatch_table = (PyDictionary)copyreg.__getattr__("dispatch_table");
***************
*** 1790,1802 ****
}
! PyObject env = null;
! try {
! env = imp.importName(module.intern(), false);
! } catch (PyException ex) {
! ex.printStackTrace();
throw new PyException(Py.SystemError,
"Failed to import class " + name + " from module " + module);
}
! return env.__getattr__(name.intern());
}
--- 1790,1804 ----
}
! PyObject modules = Py.getSystemState().modules;
! PyObject mod = modules.__finditem__(module.intern());
! if (mod == null) {
! mod = importModule(module);
! }
! PyObject global = mod.__findattr__(name.intern());
! if (global == null) {
throw new PyException(Py.SystemError,
"Failed to import class " + name + " from module " + module);
}
! return global;
}
***************
*** 1985,1988 ****
--- 1987,2017 ----
stack[stackTop++] = val;
}
+ }
+
+
+ private static PyObject importModule(String name) {
+ PyFrame frame = Py.getFrame();
+ if (frame == null)
+ return null;
+ PyObject globals = frame.f_globals;
+
+ PyObject builtins = frame.f_builtins;
+ if (builtins == null)
+ builtins = Py.getSystemState().builtins;
+
+ PyObject silly_list = new PyTuple(new PyString[] {
+ Py.newString("__doc__"),
+ });
+
+ PyObject __import__ = builtins.__finditem__("__import__");
+ if (__import__ == null)
+ return null;
+
+ PyObject module = __import__.__call__(new PyObject[] {
+ Py.newString(name),
+ globals,
+ globals,
+ silly_list } );
+ return module;
}
}
|