From: <pj...@us...> - 2011-03-24 20:12:52
|
Revision: 7266 http://jython.svn.sourceforge.net/jython/?rev=7266&view=rev Author: pjenvey Date: 2011-03-24 20:12:46 +0000 (Thu, 24 Mar 2011) Log Message: ----------- fix zipimporter subclasses not getting a __dict__ test from Yuji Yamano (thanks) Modified Paths: -------------- trunk/jython/Lib/test/test_zipimport_jy.py trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/zipimporter.derived Modified: trunk/jython/Lib/test/test_zipimport_jy.py =================================================================== --- trunk/jython/Lib/test/test_zipimport_jy.py 2011-03-24 20:11:52 UTC (rev 7265) +++ trunk/jython/Lib/test/test_zipimport_jy.py 2011-03-24 20:12:46 UTC (rev 7266) @@ -1,8 +1,8 @@ import unittest import sys import java.lang.Package - from test import test_support +from zipimport import zipimporter class SyspathZipimportTest(unittest.TestCase): def setUp(self): @@ -10,7 +10,7 @@ sys.path.insert(0, test_support.findfile("syspath_import.jar")) # TODO confirm that package is unloaded via a phantom ref or something like that - + def tearDown(self): sys.path = self.orig_path @@ -31,6 +31,17 @@ from syspathpkg import module self.assertEquals(module.__name__, 'syspathpkg.module') + def test_zipimporter_subclass(self): + class MyJavaClass(zipimporter): + def __init__(self): + zipimporter.__init__(self, test_support.findfile('zipdir.zip')) + self.bar = "bar" + + # Previously failed with AttributeError: 'MyJavaClass' object + # has no attribute 'bar' + obj = MyJavaClass() + self.assertTrue(isinstance(obj, zipimporter)) + def test_main(): test_support.run_unittest(SyspathZipimportTest) Modified: trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2011-03-24 20:11:52 UTC (rev 7265) +++ trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2011-03-24 20:12:46 UTC (rev 7266) @@ -16,9 +16,33 @@ private PyObject[]slots; + private PyObject dict; + + public PyObject fastGetDict() { + return dict; + } + + public PyObject getDict() { + return dict; + } + + public void setDict(PyObject newDict) { + if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { + dict=newDict; + } else { + throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); + } + } + + public void delDict() { + // deleting an object's instance dict makes it grow a new one + dict=new PyStringMap(); + } + public zipimporterDerived(PyType subtype) { super(subtype); slots=new PyObject[subtype.getNumSlots()]; + dict=subtype.instDict(); } public PyString __str__() { Modified: trunk/jython/src/templates/zipimporter.derived =================================================================== --- trunk/jython/src/templates/zipimporter.derived 2011-03-24 20:11:52 UTC (rev 7265) +++ trunk/jython/src/templates/zipimporter.derived 2011-03-24 20:12:46 UTC (rev 7266) @@ -1,4 +1,4 @@ base_class: zipimporter -want_dict: false +want_dict: true ctr: incl: object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |