本文整理汇总了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);
}
}
}