From: Finn B. <bc...@us...> - 2000-11-29 19:39:31
|
Update of /cvsroot/jython/jython/org/python/util In directory slayer.i.sourceforge.net:/tmp/cvs-serv16099 Modified Files: PythonObjectInputStream.java Log Message: Removed the dependency of the PyClass.serializableProxies cache. Instead the module and class names are extracted from the proxy name. The module imported and the class is found as an attribute on the module. This matches the way cPickle find its classes. Index: PythonObjectInputStream.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/util/PythonObjectInputStream.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** PythonObjectInputStream.java 2000/10/17 19:17:20 1.4 --- PythonObjectInputStream.java 2000/11/29 19:39:27 1.5 *************** *** 20,31 **** clsName = clsName.substring(19, idx); //System.out.println("new:" + clsName); ! Class cls = (Class) PyClass.serializableProxies.get(clsName); ! if (cls != null) ! return cls; } try { return super.resolveClass(v); } catch (ClassNotFoundException exc) { ! PyObject m = imp.load(clsName.intern()); //System.out.println("m:" + m); Object cls = m.__tojava__(Class.class); --- 20,41 ---- clsName = clsName.substring(19, idx); //System.out.println("new:" + clsName); ! ! idx = clsName.indexOf('$'); ! if (idx >= 0) { ! String mod = clsName.substring(0, idx); ! clsName = clsName.substring(idx+1); ! ! PyObject module = importModule(mod); ! PyObject pycls = module.__getattr__(clsName.intern()); ! Object cls = pycls.__tojava__(Class.class); ! ! if (cls != null && cls != Py.NoConversion) ! return (Class) cls; ! } } try { return super.resolveClass(v); } catch (ClassNotFoundException exc) { ! PyObject m = importModule(clsName); //System.out.println("m:" + m); Object cls = m.__tojava__(Class.class); *************** *** 35,38 **** --- 45,75 ---- throw exc; } + } + + + 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; } } |