| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Jython
Revision: 5229
Author: leosoto
Date: 20 Aug 2008 23:23:28
Changes:Fixing #1095 for old-style classes. Thanks to Anselm Kruls for the patch.
Files:| ... | ...@@ -201,10 +201,19 @@ | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | public PyObject __findattr_ex__(String name) { |
| 204 | return __findattr__(name, false); | |
| 204 | return __findattr_ex__(name, false); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | public PyObject __findattr__(String name, boolean stopAtJava) { |
| 208 | try { | |
| 209 | return __findattr_ex__(name, stopAtJava); | |
| 210 | } catch (PyException exc) { | |
| 211 | if (Py.matchException(exc, Py.AttributeError)) return null; | |
| 212 | throw exc; | |
| 213 | } | |
| 214 | } | |
| 215 | ||
| 216 | protected PyObject __findattr_ex__(String name, boolean stopAtJava) { | |
| 208 | 217 | PyObject result = ifindlocal(name); |
| 209 | 218 | if (result != null) |
| 210 | 219 | return result; |
| ... | ...@@ -234,12 +243,7 @@ | |
| 234 | 243 | if (getter == null) |
| 235 | 244 | return null; |
| 236 | 245 | |
| 237 | try { | |
| 238 | return getter.__call__(this, new PyString(name)); | |
| 239 | } catch (PyException exc) { | |
| 240 | if (Py.matchException(exc, Py.AttributeError)) return null; | |
| 241 | throw exc; | |
| 242 | } | |
| 246 | return getter.__call__(this, new PyString(name)); | |
| 243 | 247 | } |
| 244 | 248 | |
| 245 | 249 | public boolean isCallable() { |
| ... | ...@@ -326,16 +326,34 @@ | |
| 326 | 326 | def __getattr__(self, name): |
| 327 | 327 | raise BarAttributeError |
| 328 | 328 | |
| 329 | class BarClassic: | |
| 330 | def __getattr__(self, name): | |
| 331 | raise BarAttributeError | |
| 332 | ||
| 329 | 333 | class Foo(object): |
| 330 | 334 | def __getattr__(self, name): |
| 331 | 335 | raise AttributeError("Custom message") |
| 336 | ||
| 337 | class FooClassic: | |
| 338 | def __getattr__(self, name): | |
| 339 | raise AttributeError("Custom message") | |
| 340 | ||
| 332 | 341 | self.assertRaises(BarAttributeError, lambda: Bar().x) |
| 342 | self.assertRaises(BarAttributeError, lambda: BarClassic().x) | |
| 343 | ||
| 333 | 344 | try: |
| 334 | 345 | Foo().x |
| 335 | 346 | self.assert_(False) # Previous line should raise AttributteError |
| 336 | 347 | except AttributeError, e: |
| 337 | 348 | self.assertEquals("Custom message", str(e)) |
| 338 | 349 | |
| 350 | try: | |
| 351 | FooClassic().x | |
| 352 | self.assert_(False) # Previous line should raise AttributteError | |
| 353 | except AttributeError, e: | |
| 354 | self.assertEquals("Custom message", str(e)) | |
| 355 | ||
| 356 | ||
| 339 | 357 | def test_main(): |
| 340 | 358 | test_support.run_unittest(TestDescrTestCase, |
| 341 | 359 | SubclassDescrTestCase, |