本文整理匯總了Java中org.python.core.PyObject.__setitem__方法的典型用法代碼示例。如果您正苦於以下問題:Java PyObject.__setitem__方法的具體用法?Java PyObject.__setitem__怎麽用?Java PyObject.__setitem__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.python.core.PyObject
的用法示例。
在下文中一共展示了PyObject.__setitem__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEnviron
import org.python.core.PyObject; //導入方法依賴的package包/類
/**
* Initialize the environ dict from System.getenv. environ may be empty when the
* security policy doesn't grant us access.
*/
private static PyObject getEnviron() {
PyObject environ = new PyDictionary();
Map<String, String> env;
try {
env = System.getenv();
} catch (SecurityException se) {
return environ;
}
for (Map.Entry<String, String> entry : env.entrySet()) {
environ.__setitem__(Py.newString(entry.getKey()), Py.newString(entry.getValue()));
}
return environ;
}
示例2: classDictInit
import org.python.core.PyObject; //導入方法依賴的package包/類
public static void classDictInit(PyObject dict) {
// only expose the open flags we support
dict.__setitem__("O_RDONLY", Py.newInteger(O_RDONLY));
dict.__setitem__("O_WRONLY", Py.newInteger(O_WRONLY));
dict.__setitem__("O_RDWR", Py.newInteger(O_RDWR));
dict.__setitem__("O_APPEND", Py.newInteger(O_APPEND));
dict.__setitem__("O_SYNC", Py.newInteger(O_SYNC));
dict.__setitem__("O_CREAT", Py.newInteger(O_CREAT));
dict.__setitem__("O_TRUNC", Py.newInteger(O_TRUNC));
dict.__setitem__("O_EXCL", Py.newInteger(O_EXCL));
// os.access flags
dict.__setitem__("F_OK", Py.newInteger(F_OK));
dict.__setitem__("X_OK", Py.newInteger(X_OK));
dict.__setitem__("W_OK", Py.newInteger(W_OK));
dict.__setitem__("R_OK", Py.newInteger(R_OK));
// Successful termination
dict.__setitem__("EX_OK", Py.Zero);
boolean nativePosix = posix.isNative();
dict.__setitem__("_native_posix", Py.newBoolean(nativePosix));
dict.__setitem__("_posix_impl", Py.java2py(posix));
dict.__setitem__("environ", getEnviron());
dict.__setitem__("error", Py.OSError);
dict.__setitem__("stat_result", PyStatResult.TYPE);
// Faster call paths
dict.__setitem__("lstat", new LstatFunction());
dict.__setitem__("stat", new StatFunction());
// Hide from Python
Hider.hideFunctions(PosixModule.class, dict, os, nativePosix);
dict.__setitem__("classDictInit", null);
dict.__setitem__("__init__", null);
dict.__setitem__("getPOSIX", null);
dict.__setitem__("getOSName", null);
dict.__setitem__("badFD", null);
// Hide __doc__s
PyList keys = (PyList)dict.invoke("keys");
for (Iterator<?> it = keys.listIterator(); it.hasNext();) {
String key = (String)it.next();
if (key.startsWith("__doc__")) {
it.remove();
dict.__setitem__(key, null);
}
}
dict.__setitem__("__all__", keys);
dict.__setitem__("__name__", new PyString(os.getModuleName()));
dict.__setitem__("__doc__", __doc__);
}
示例3: putenv
import org.python.core.PyObject; //導入方法依賴的package包/類
public static void putenv(String key, String value) {
// XXX: Consider deprecating putenv/unsetenv
// import os; os.environ[key] = value
PyObject environ = imp.load("os").__getattr__("environ");
environ.__setitem__(key, new PyString(value));
}
示例4: hideFunctions
import org.python.core.PyObject; //導入方法依賴的package包/類
/**
* Hide module level functions defined in the PosixModule dict not applicable to this
* OS, identified by the PosixModule.Hide annotation.
*
* @param cls the PosixModule class
* @param dict the PosixModule module dict
* @param os the underlying OS
* @param native whether the underlying posix is native
*/
public static void hideFunctions(Class<?> cls, PyObject dict, OS os, boolean isNative) {
PosixImpl posixImpl = isNative ? PosixImpl.NATIVE : PosixImpl.JAVA;
for (Method method: cls.getDeclaredMethods()) {
if (isHidden(method, os, posixImpl)) {
dict.__setitem__(method.getName(), null);
}
}
}