From: <pj...@us...> - 2008-03-05 22:36:51
|
Revision: 4188 http://jython.svn.sourceforge.net/jython/?rev=4188&view=rev Author: pjenvey Date: 2008-03-05 14:36:49 -0800 (Wed, 05 Mar 2008) Log Message: ----------- fix importFrom hiding nested ImportErrors by moving the PyModule impHook logic into imp. also remove the magic that automatically imports a module when it's looked up via its parent package's __getattr__ Modified Paths: -------------- trunk/jython/src/org/python/core/PyModule.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/PyModule.java =================================================================== --- trunk/jython/src/org/python/core/PyModule.java 2008-03-04 23:49:26 UTC (rev 4187) +++ trunk/jython/src/org/python/core/PyModule.java 2008-03-05 22:36:49 UTC (rev 4188) @@ -148,21 +148,7 @@ } } - attr = super.__findattr__(name); - if (attr != null) { - return attr; - } - - if (__dict__ == null) { - return null; - } - - PyObject pyName = __dict__.__finditem__("__name__"); - if (pyName == null) { - return null; - } - - return impHook(pyName.__str__().toString() + '.' + name); + return super.__findattr__(name); } public void __setattr__(String name, PyObject value) { @@ -222,18 +208,4 @@ __dict__ = new PyStringMap(); } } - - private static PyObject impHook(String name) { - if (fromlist == null) { - fromlist = new PyTuple(Py.newString("__doc__")); - } - try { - return __builtin__.__import__(name, null, null, fromlist); - } catch (PyException pe) { - if (Py.matchException(pe, Py.ImportError)) { - return null; - } - throw pe; - } - } } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2008-03-04 23:49:26 UTC (rev 4187) +++ trunk/jython/src/org/python/core/imp.java 2008-03-05 22:36:49 UTC (rev 4188) @@ -22,6 +22,9 @@ public static final int APIVersion = 12; + /** A non-empty fromlist for __import__'ing sub-modules. */ + private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); + /** Synchronizes import operations */ public static final ReentrantLock importLock = new ReentrantLock(); @@ -772,6 +775,10 @@ for (int i = 0; i < names.length; i++) { PyObject submod = module.__findattr__(names[i]); if (submod == null) { + String submodName = mod + '.' + names[i]; + submod = __builtin__.__import__(submodName, null, null, nonEmptyFromlist); + } + if (submod == null) { if (module instanceof PyJavaPackage) { if (JavaImportHelper.tryAddPackage(mod + "." + names[i], null)) { submod = module.__findattr__(names[i]); @@ -855,7 +862,16 @@ continue; } else { try { - locals.__setitem__(sname, module.__getattr__(sname)); + PyObject value = module.__findattr__(sname); + if (value == null) { + PyObject nameObj = module.__findattr__("__name__"); + if (nameObj != null) { + String submodName = nameObj.__str__().toString() + '.' + sname; + value = __builtin__.__import__(submodName, null, null, + nonEmptyFromlist); + } + } + locals.__setitem__(sname, value); } catch (Exception exc) { continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |