Index: src/org/python/core/SyspathJavaLoader.java =================================================================== --- src/org/python/core/SyspathJavaLoader.java (revision 6914) +++ src/org/python/core/SyspathJavaLoader.java (working copy) @@ -9,6 +9,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.StringTokenizer; import java.util.zip.ZipEntry; @@ -39,6 +40,15 @@ return ret; } + return (InputStream) find(res,false); + } + + protected URL findResource(String res) { + return (URL) find(res, true); + } + + private Object find(String res, boolean asURL) { + PySystemState sys = Py.getSystemState(); if (res.charAt(0) == SLASH_CHAR) { res = res.substring(1); } @@ -56,7 +66,12 @@ ZipEntry ze = archive.getEntry(entryRes); if (ze != null) { try { - return archive.getInputStream(ze); + if (asURL) { + return new URL("jar:file:"+archive.asString()+"!/"+ze.getName()); + } + else { + return archive.getInputStream(ze); + } } catch (IOException e) { ; } @@ -65,7 +80,15 @@ } String dir = sys.getPath(entry.__str__().toString()); try { - return new BufferedInputStream(new FileInputStream(new File(dir, res))); + File f = new File(dir, res); + FileInputStream fin = new FileInputStream(f); + if (asURL) { + return new BufferedInputStream(fin); + } + else { + fin.close(); + return f.toURL(); + } } catch (IOException e) { continue; } Index: Lib/test/test_syspathresource_jy.py =================================================================== --- Lib/test/test_syspathresource_jy.py (revision 0) +++ Lib/test/test_syspathresource_jy.py (revision 0) @@ -0,0 +1,27 @@ +import unittest +import sys + +from test import test_support + +class SyspathResourceTest(unittest.TestCase): + def setUp(self): + self.orig_path = sys.path + sys.path.insert(0, 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_support.run_unittest(SyspathResourceTest) + +if __name__ == "__main__": + test_main() +