-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathPythonPOSIXHandler.java
More file actions
88 lines (72 loc) · 2.18 KB
/
PythonPOSIXHandler.java
File metadata and controls
88 lines (72 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Copyright (c) Jython Developers */
package org.python.modules.posix;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.logging.Level;
import jnr.constants.platform.Errno;
import jnr.posix.POSIXHandler;
import org.python.core.imp;
import org.python.core.Options;
import org.python.core.PrePy;
import org.python.core.Py;
import org.python.core.PyObject;
/**
* Jython specific hooks for our underlying POSIX library.
*/
public class PythonPOSIXHandler implements POSIXHandler {
@Override
public void error(Errno error, String extraData) {
throw Py.OSError(error, Py.newStringOrUnicode(extraData));
}
@Override
public void error(Errno error, String methodName, String extraData) {
throw Py.OSError(error, Py.newStringOrUnicode(extraData));
}
@Override
public void unimplementedError(String methodName) {
if (methodName.startsWith("stat.")) {
// Ignore unimplemented FileStat methods
return;
}
throw Py.NotImplementedError(methodName);
}
@Override
public void warn(WARNING_ID id, String message, Object... data) {
}
@Override
public boolean isVerbose() {
// Verbose if the general threshold for logging is FINE or lower.
return PrePy.getLoggingLevel().intValue() <= Level.FINE.intValue();
}
@Override
public File getCurrentWorkingDirectory() {
return new File(Py.getSystemState().getCurrentWorkingDir());
}
@Override
public String[] getEnv() {
PyObject items = imp.load("os").__getattr__("environ").invoke("items");
String[] env = new String[items.__len__()];
int i = 0;
for (PyObject item : items.asIterable()) {
env[i++] = String.format("%s=%s", item.__getitem__(0), item.__getitem__(1));
}
return env;
}
@Override
public InputStream getInputStream() {
return System.in;
}
@Override
public PrintStream getOutputStream() {
return System.out;
}
@Override
public int getPID() {
return 0;
}
@Override
public PrintStream getErrorStream() {
return System.err;
}
}