本文整理汇总了Java中org.python.core.PyTuple.get方法的典型用法代码示例。如果您正苦于以下问题:Java PyTuple.get方法的具体用法?Java PyTuple.get怎么用?Java PyTuple.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.PyTuple
的用法示例。
在下文中一共展示了PyTuple.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadAvailableLexers
import org.python.core.PyTuple; //导入方法依赖的package包/类
public List<LexerInfo> loadAvailableLexers(PyGateway gateway) {
PythonInterpreter interpreter = gateway.getInterpreter();
// Simple use Pygments as you would in Python
interpreter.exec(""
+ "from pygments.lexers import get_all_lexers\n"
+ "result = get_all_lexers()");
PyGenerator result = (PyGenerator) interpreter.get("result");
ArrayList<LexerInfo> infos = Lists.newArrayList();
for (Object o : result) {
PyTuple tuple = (PyTuple) o;
String name = (String) tuple.get(0);
List<String> aliases = Lists.newArrayListWithCapacity(3);
for (Object alias : (PyTuple) tuple.get(1)) {
String str = (String) alias;
aliases.add(str);
}
LexerInfo info = new LexerInfo(name, aliases);
infos.add(info);
}
return infos;
}
示例2: getParamsFromVariables
import org.python.core.PyTuple; //导入方法依赖的package包/类
@Override
protected Map<String, Object> getParamsFromVariables() throws IOException {
PyFrame frame = Py.getFrame();
@SuppressWarnings("unchecked")
List<PyTuple> locals = ((PyStringMap) frame.getLocals()).items();
Map<String, Object> vars = new HashMap<String, Object>();
for (PyTuple item : locals) {
String key = (String) item.get(0);
Object obj = item.get(1);
if (obj != null) {
String value = item.get(1).toString();
vars.put(key, value);
}
}
return vars;
}
示例3: registerFunctions
import org.python.core.PyTuple; //导入方法依赖的package包/类
@Override
public void registerFunctions(String path, String namespace, PigContext pigContext)
throws IOException {
Interpreter.setMain(false);
Interpreter.init(path, pigContext);
pigContext.scriptJars.add(getJarPath(PythonInterpreter.class));
PythonInterpreter pi = Interpreter.interpreter;
@SuppressWarnings("unchecked")
List<PyTuple> locals = ((PyStringMap) pi.getLocals()).items();
namespace = (namespace == null) ? "" : namespace + NAMESPACE_SEPARATOR;
try {
for (PyTuple item : locals) {
String key = (String) item.get(0);
Object value = item.get(1);
FuncSpec funcspec = null;
if (!key.startsWith("__") && !key.equals("schemaFunction")
&& !key.equals("outputSchema")
&& !key.equals("outputSchemaFunction")
&& (value instanceof PyFunction)
&& (((PyFunction)value).__findattr__("schemaFunction")== null)) {
PyObject obj = ((PyFunction)value).__findattr__("outputSchema");
if(obj != null) {
Utils.getSchemaFromString(obj.toString());
}
funcspec = new FuncSpec(JythonFunction.class.getCanonicalName() + "('"
+ path + "','" + key +"')");
pigContext.registerFunction(namespace + key, funcspec);
LOG.info("Register scripting UDF: " + namespace + key);
}
}
} catch (ParserException pe) {
throw new IOException(
"Error parsing schema for script function from the decorator",
pe);
}
pigContext.addScriptFile(path);
Interpreter.setMain(true);
}
示例4: getModuleState
import org.python.core.PyTuple; //导入方法依赖的package包/类
/**
* get the state of modules currently loaded
* @return a map of module name to module file (absolute path)
*/
private static Map<String, String> getModuleState() {
// determine the current module state
Map<String, String> files = new HashMap<String, String>();
PyStringMap modules = (PyStringMap) Py.getSystemState().modules;
for (PyObject kvp : modules.iteritems().asIterable()) {
PyTuple tuple = (PyTuple) kvp;
String name = tuple.get(0).toString();
Object value = tuple.get(1);
// inspect the module to determine file location and status
try {
Object fileEntry = null;
Object loader = null;
if (value instanceof PyJavaPackage ) {
fileEntry = ((PyJavaPackage) value).__file__;
} else if (value instanceof PyObject) {
// resolved through the filesystem (or built-in)
PyObject dict = ((PyObject) value).getDict();
if (dict != null) {
fileEntry = dict.__finditem__("__file__");
loader = dict.__finditem__("__loader__");
} // else built-in
} // else some system module?
if (fileEntry != null) {
File file = resolvePyModulePath(fileEntry.toString(), loader);
if (file.exists()) {
String apath = file.getAbsolutePath();
if (apath.endsWith(".jar") || apath.endsWith(".zip")) {
// jar files are simple added to the pigContext
files.put(apath, apath);
} else {
// determine the relative path that the file should have in the jar
int pos = apath.lastIndexOf(File.separatorChar + name.replace('.', File.separatorChar));
if (pos > 0) {
files.put(apath.substring(pos), apath);
} else {
files.put(apath, apath);
}
}
} else {
LOG.warn("module file does not exist: " + name + ", " + file);
}
} // else built-in
} catch (Exception e) {
LOG.warn("exception while retrieving module state: " + value, e);
}
}
return files;
}
示例5: getModuleState
import org.python.core.PyTuple; //导入方法依赖的package包/类
/**
* get the state of modules currently loaded
* @return a map of module name to module file (absolute path)
*/
private static Map<String, String> getModuleState() {
// determine the current module state
Map<String, String> files = new HashMap<String, String>();
PyStringMap modules = (PyStringMap) Py.getSystemState().modules;
for (PyObject kvp : modules.iteritems().asIterable()) {
PyTuple tuple = (PyTuple) kvp;
String name = tuple.get(0).toString();
Object value = tuple.get(1);
// inspect the module to determine file location and status
try {
Object fileEntry = null;
Object loader = null;
if (value instanceof PyJavaPackage ) {
fileEntry = ((PyJavaPackage) value).__file__;
} else if (value instanceof PyObject) {
// resolved through the filesystem (or built-in)
PyObject dict = ((PyObject) value).getDict();
if (dict != null) {
fileEntry = dict.__finditem__("__file__");
loader = dict.__finditem__("__loader__");
} // else built-in
} // else some system module?
if (fileEntry != null) {
File file = resolvePyModulePath(fileEntry.toString(), loader);
if (file.exists()) {
String apath = file.getAbsolutePath();
if (apath.endsWith(".jar") || apath.endsWith(".zip")) {
// jar files are simple added to the pigContext
files.put(apath, apath);
} else {
// determine the relative path that the file should have in the jar
int pos = apath.lastIndexOf(File.separatorChar + name.replace('.', File.separatorChar));
if (pos > 0) {
files.put(apath.substring(pos + 1), apath);
} else {
files.put(apath, apath);
}
}
} else {
LOG.warn("module file does not exist: " + name + ", " + file);
}
} // else built-in
} catch (Exception e) {
LOG.warn("exception while retrieving module state: " + value, e);
}
}
return files;
}
示例6: getModuleState
import org.python.core.PyTuple; //导入方法依赖的package包/类
/**
* get the state of modules currently loaded
* @return a map of module name to module file (absolute path)
*/
private static Map<String, String> getModuleState() {
// determine the current module state
Map<String, String> files = new HashMap<String, String>();
PyStringMap modules = (PyStringMap) Py.getSystemState().modules;
for (PyObject kvp : modules.iteritems().asIterable()) {
PyTuple tuple = (PyTuple) kvp;
String name = tuple.get(0).toString();
Object value = tuple.get(1);
// inspect the module to determine file location and status
try {
Object fileEntry = null;
if (value instanceof PyJavaPackage ) {
fileEntry = ((PyJavaPackage) value).__file__;
} else if (value instanceof PyObject) {
// resolved through the filesystem (or built-in)
PyObject dict = ((PyObject) value).getDict();
if (dict != null) {
fileEntry = dict.__finditem__("__file__");
} // else built-in
} // else some system module?
if (fileEntry != null) {
File file = new File(fileEntry.toString());
if (file.exists()) {
String apath = file.getAbsolutePath();
if (apath.endsWith(".jar") || apath.endsWith(".zip")) {
// jar files are simple added to the pigContext
files.put(apath, apath);
} else {
// determine the relative path that the file should have in the jar
int pos = apath.lastIndexOf(File.separatorChar + name.replace('.', File.separatorChar));
if (pos > 0) {
files.put(apath.substring(pos), apath);
} else {
files.put(apath, apath);
}
}
} else {
LOG.warn("module file does not exist: " + name + ", " + file);
}
} // else built-in
} catch (Exception e) {
LOG.warn("exception while retrieving module state: " + value, e);
}
}
return files;
}