[Jython-checkins] jython: #1896215 findResource(s) for SyspathJavaLoader
frank.wierzbicki
jython-checkins at python.org
Tue May 13 18:32:18 CEST 2014
http://hg.python.org/jython/rev/ab99e96d9192
changeset: 7245:ab99e96d9192
parent: 7242:d9c4641be70a
user: Richard Eckart de Castilho <richard.eckart at gmail.com>
date: Tue May 13 16:30:39 2014 +0000
summary:
#1896215 findResource(s) for SyspathJavaLoader
files:
ACKNOWLEDGMENTS | 1 +
NEWS | 6 +
src/org/python/core/SyspathJavaLoader.java | 52 ++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS
--- a/ACKNOWLEDGMENTS
+++ b/ACKNOWLEDGMENTS
@@ -105,6 +105,7 @@
Santoso Wijaya
Brandon Pedersen
Chris Simpson
+ Richard Eckart de Castilho
Local Variables:
mode: indented-text
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,11 @@
Jython NEWS
+Jython 2.7b3
+ Bugs Fixed
+
+ New Features
+ - [ 1896215 ] findResource(s) for SyspathJavaLoader
+
Jython 2.7b2
Bugs Fixed
- [ 1753 ] zlib doesn't call end() on compress and decompress
diff --git a/src/org/python/core/SyspathJavaLoader.java b/src/org/python/core/SyspathJavaLoader.java
--- a/src/org/python/core/SyspathJavaLoader.java
+++ b/src/org/python/core/SyspathJavaLoader.java
@@ -10,6 +10,10 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.zip.ZipEntry;
@@ -172,7 +176,55 @@
return null;
}
+ @Override
+ protected Enumeration<URL> findResources(String res)
+ throws IOException
+ {
+ List<URL> resources = new ArrayList<URL>();
+
+ PySystemState sys = Py.getSystemState();
+
+ if (res.charAt(0) == SLASH_CHAR) {
+ res = res.substring(1);
+ }
+ String entryRes = res;
+ if (File.separatorChar != SLASH_CHAR) {
+ res = res.replace(SLASH_CHAR, File.separatorChar);
+ entryRes = entryRes.replace(File.separatorChar, SLASH_CHAR);
+ }
+ PyList path = sys.path;
+ for (int i = 0; i < path.__len__(); i++) {
+ PyObject entry = replacePathItem(sys, i, path);
+ if (entry instanceof SyspathArchive) {
+ SyspathArchive archive = (SyspathArchive) entry;
+ ZipEntry ze = archive.getEntry(entryRes);
+ if (ze != null) {
+ try {
+ resources.add(new URL("jar:file:" + archive.asUriCompatibleString() + "!/" + entryRes));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ continue;
+ }
+ if (!(entry instanceof PyUnicode)) {
+ entry = entry.__str__();
+ }
+ String dir = sys.getPath(entry.toString());
+ try {
+ File resource = new File(dir, res);
+ if (!resource.exists()) {
+ continue;
+ }
+ resources.add(resource.toURI().toURL());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return Collections.enumeration(resources);
+ }
+
static PyObject replacePathItem(PySystemState sys, int idx, PyList paths) {
PyObject path = paths.__getitem__(idx);
if (path instanceof SyspathArchive) {
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list