From: <zy...@us...> - 2010-07-20 04:29:05
|
Revision: 7080 http://jython.svn.sourceforge.net/jython/?rev=7080&view=rev Author: zyasoft Date: 2010-07-20 04:28:59 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Fixes SyspathJavaLoader so that packages added to sys.path work with Java's standard resource loading (getResource, getResourceAsStream) methods. Resolves #1373. Thanks Justin Deoliveira and Costantino Cerbo for contributing this patch. Modified Paths: -------------- trunk/jython/ACKNOWLEDGMENTS trunk/jython/Lib/test/test_sys_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/SyspathJavaLoader.java Added Paths: ----------- trunk/jython/Lib/test/bug1373.jar Modified: trunk/jython/ACKNOWLEDGMENTS =================================================================== --- trunk/jython/ACKNOWLEDGMENTS 2010-07-20 03:50:50 UTC (rev 7079) +++ trunk/jython/ACKNOWLEDGMENTS 2010-07-20 04:28:59 UTC (rev 7080) @@ -88,6 +88,8 @@ Leonardo Soto James Robinson Jonathan Feinberg + Justin Deoliveira + Costantino Cerbo Local Variables: mode: indented-text Added: trunk/jython/Lib/test/bug1373.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/bug1373.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/jython/Lib/test/test_sys_jy.py =================================================================== --- trunk/jython/Lib/test/test_sys_jy.py 2010-07-20 03:50:50 UTC (rev 7079) +++ trunk/jython/Lib/test/test_sys_jy.py 2010-07-20 04:28:59 UTC (rev 7080) @@ -129,8 +129,25 @@ self.assertTrue('sys_jy_test_module' not in sys.modules, "sys.modules should be per PySystemState instance") +class SyspathResourceTest(unittest.TestCase): + def setUp(self): + self.orig_path = sys.path + sys.path.insert(0, test.test_support.findfile("bug1373.jar")) + + def tearDown(self): + sys.path = self.orig_path + + def test_resource_stream_from_syspath(self): + from pck import Main + self.assert_(Main.getResourceAsStream('Main.txt')) + + def test_resource_url_from_syspath(self): + from pck import Main + self.assert_(Main.getResource('Main.txt')) + + def test_main(): - test.test_support.run_unittest(SysTest, ShadowingTest) + test.test_support.run_unittest(SysTest, ShadowingTest, SyspathResourceTest) if __name__ == "__main__": test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-07-20 03:50:50 UTC (rev 7079) +++ trunk/jython/NEWS 2010-07-20 04:28:59 UTC (rev 7080) @@ -2,6 +2,7 @@ Jython 2.5.2b2 Bugs Fixed + - [ 1373 ] Jython ClassLoader getResource does not work - [ 1506 ] Jython applies PEP263 pattern for determining source-code encoding on noncomments - [ 1630 ] threading.Thread lacks __tojava__ method Modified: trunk/jython/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/jython/src/org/python/core/SyspathJavaLoader.java 2010-07-20 03:50:50 UTC (rev 7079) +++ trunk/jython/src/org/python/core/SyspathJavaLoader.java 2010-07-20 04:28:59 UTC (rev 7080) @@ -134,7 +134,7 @@ ZipEntry ze = archive.getEntry(entryRes); if (ze != null) { try { - return new URL("jar:" + entry.__str__().toString() + "!/" + entryRes); + return new URL("jar:file:" + entry.__str__().toString() + "!/" + entryRes); } catch (MalformedURLException e) { throw new RuntimeException(e); } @@ -143,7 +143,11 @@ } String dir = sys.getPath(entry.__str__().toString()); try { - return new File(dir, res).toURI().toURL(); + File resource = new File(dir, res); + if (!resource.exists()) { + continue; + } + return resource.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |