From: <le...@us...> - 2008-08-21 03:23:30
|
Revision: 5229 http://jython.svn.sourceforge.net/jython/?rev=5229&view=rev Author: leosoto Date: 2008-08-21 03:23:28 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Fixing #1095 for old-style classes. Thanks to Anselm Kruls for the patch. Modified Paths: -------------- trunk/jython/Lib/test/test_descr_jy.py trunk/jython/src/org/python/core/PyInstance.java Modified: trunk/jython/Lib/test/test_descr_jy.py =================================================================== --- trunk/jython/Lib/test/test_descr_jy.py 2008-08-21 02:58:24 UTC (rev 5228) +++ trunk/jython/Lib/test/test_descr_jy.py 2008-08-21 03:23:28 UTC (rev 5229) @@ -326,16 +326,34 @@ def __getattr__(self, name): raise BarAttributeError + class BarClassic: + def __getattr__(self, name): + raise BarAttributeError + class Foo(object): def __getattr__(self, name): raise AttributeError("Custom message") + + class FooClassic: + def __getattr__(self, name): + raise AttributeError("Custom message") + self.assertRaises(BarAttributeError, lambda: Bar().x) + self.assertRaises(BarAttributeError, lambda: BarClassic().x) + try: Foo().x self.assert_(False) # Previous line should raise AttributteError except AttributeError, e: self.assertEquals("Custom message", str(e)) + try: + FooClassic().x + self.assert_(False) # Previous line should raise AttributteError + except AttributeError, e: + self.assertEquals("Custom message", str(e)) + + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, Modified: trunk/jython/src/org/python/core/PyInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyInstance.java 2008-08-21 02:58:24 UTC (rev 5228) +++ trunk/jython/src/org/python/core/PyInstance.java 2008-08-21 03:23:28 UTC (rev 5229) @@ -201,10 +201,19 @@ } public PyObject __findattr_ex__(String name) { - return __findattr__(name, false); + return __findattr_ex__(name, false); } public PyObject __findattr__(String name, boolean stopAtJava) { + try { + return __findattr_ex__(name, stopAtJava); + } catch (PyException exc) { + if (Py.matchException(exc, Py.AttributeError)) return null; + throw exc; + } + } + + protected PyObject __findattr_ex__(String name, boolean stopAtJava) { PyObject result = ifindlocal(name); if (result != null) return result; @@ -234,12 +243,7 @@ if (getter == null) return null; - try { - return getter.__call__(this, new PyString(name)); - } catch (PyException exc) { - if (Py.matchException(exc, Py.AttributeError)) return null; - throw exc; - } + return getter.__call__(this, new PyString(name)); } public boolean isCallable() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |