Skip to content

Commit b6844ec

Browse files
committed
ClasspathPyImporter implements get_data(); addresses #2058.
1 parent 54da709 commit b6844ec

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/org/python/core/ClasspathPyImporter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.io.InputStream;
66
import java.util.Map;
77

8+
import org.python.core.util.FileUtil;
9+
import org.python.core.util.StringUtil;
810
import org.python.core.util.importer;
911
import org.python.expose.ExposedMethod;
1012
import org.python.expose.ExposedNew;
@@ -40,6 +42,17 @@ final void ClasspathPyImporter___init__(PyObject[] args, String[] kwds) {
4042
this.path = path;
4143
}
4244

45+
public String get_data(String path) {
46+
InputStream is = entries.get(makeEntry(path.replace("__pyclasspath__/", "")));
47+
byte[] data;
48+
try {
49+
data = FileUtil.readBytes(is);
50+
} catch (IOException ioe) {
51+
throw Py.IOError(ioe);
52+
}
53+
return StringUtil.fromBytes(data);
54+
}
55+
4356
/**
4457
* Find the module for the fully qualified name.
4558
*

src/org/python/core/util/importer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public importer() {
3939
searchOrder = makeSearchOrder();
4040
}
4141

42+
public abstract String get_data(String path);
43+
4244
/**
4345
* Returns the separator between directories and files used by this type of importer.
4446
*/

0 commit comments

Comments
 (0)