当前位置: 首页>>代码示例>>Java>>正文


Java PyStringMap类代码示例

本文整理汇总了Java中org.python.core.PyStringMap的典型用法代码示例。如果您正苦于以下问题:Java PyStringMap类的具体用法?Java PyStringMap怎么用?Java PyStringMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PyStringMap类属于org.python.core包,在下文中一共展示了PyStringMap类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeInterperter

import org.python.core.PyStringMap; //导入依赖的package包/类
public void initializeInterperter(PythonInterpreter interpreter)
{
	boolean localsUninitialized = interpreter.getLocals() == initialLocals;
	if(localsUninitialized)
	{
		PyStringMap locals = new PyStringMap();
		interpreter.setLocals(locals);
		interpreter.exec(scripts.get(PythonTransformationHelper.getImportStatements()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getIsEmptyDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getHasSelectedRowsStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueFromNestedColumnByIndexDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getRowIndexDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getVDefStatement()));
	}
	if(localsUninitialized ||(!libraryHasBeenLoaded || reloadLibrary))
	{
		importUserScripts(interpreter);
	}

}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:22,代码来源:PythonRepository.java

示例2: getParamsFromVariables

import org.python.core.PyStringMap; //导入依赖的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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:17,代码来源:JythonScriptEngine.java

示例3: adjustException

import org.python.core.PyStringMap; //导入依赖的package包/类
private static RuntimeException adjustException(ScriptException scriptException, String... scripts) {
	Throwable cause = scriptException.getCause();
	if (!(cause instanceof PyException)) {
		if (scripts.length == 0) {
			return new IllegalStateException(scriptException);
		} else {
			return new IllegalStateException(
					scriptException.getMessage() + "\nscript:" + joinStrings("\n", scripts), scriptException);
		}
	}

	PyException e = (PyException) cause;

	PyObject o = e.value.getDict();
	if (!(o instanceof PyStringMap)) {
		return e;
	}
	PyStringMap m = (PyStringMap) o;

	String message;
	if (e.value instanceof PyBaseException) {
		message = String.valueOf(((PyBaseException) e.value).getMessage());
	} else {
		message = scriptException.getMessage();
	}

	PyObject tlist = m.getMap().get("tlist");
	PyObject trace = m.getMap().get("trace");

	return new UroborosqlFormatterException(message, String.valueOf(tlist), String.valueOf(trace), e);
}
 
开发者ID:future-architect,项目名称:eclipse-uroborosql-formatter,代码行数:32,代码来源:PyEngine.java

示例4: getBindings

import org.python.core.PyStringMap; //导入依赖的package包/类
@Override
public Map<String, Object> getBindings()
{
  Map<String, Object> bindings = new HashMap<String, Object>();
  PyStringMap keyValueMap = (PyStringMap)interp.getLocals();
  PyIterator keyValueSet = (PyIterator)keyValueMap.iteritems();
  for (Object temp : keyValueSet) {
    PyTuple tempEntry = (PyTuple)temp;
    Iterator<PyObject> iter = tempEntry.iterator();
    bindings.put((String)iter.next().__tojava__(String.class), iter.next());
  }
  return bindings;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:14,代码来源:PythonOperator.java

示例5: invoke

import org.python.core.PyStringMap; //导入依赖的package包/类
@Override
public SwampScriptInvokationResult invoke(SwampBinding params) {
    try (PythonInterpreter interpreter = new PythonInterpreter()) {
        for (Entry<String, Object> entry : params.getVariableEntries()) {
            interpreter.set(entry.getKey(), entry.getValue());
        }

        final PyStringMap localVars = (PyStringMap) interpreter.getLocals();
        PyObject resultObject = Py.runCode(compiledScript, localVars, interpreter.getLocals());
        localVars.getMap().put(SCRIPT_RESULT, resultObject);

        return new PyMapWrapper(localVars);
    }
}
 
开发者ID:kibertoad,项目名称:swampmachine,代码行数:15,代码来源:PythonScript.java

示例6: testExecuteScript

import org.python.core.PyStringMap; //导入依赖的package包/类
@Test
public void testExecuteScript() throws Exception {
    reset(execInterpreter);
    final String script = "pass";
    Map<String, Value> scriptInputValues = new HashMap<>();
    Value value1 = ValueFactory.create("value1");
    Value value2 = ValueFactory.create("value2");
    scriptInputValues.put("input1", value1);
    scriptInputValues.put("input2", value2);
    Map<Object, PyObject> scriptOutputValues = new HashMap<>();
    PyObject pyObjectValue1 = (PyObject) ValueFactory.createPyObjectValue("value1", false);
    PyObject pyObjectValue2 = (PyObject) ValueFactory.createPyObjectValue("value2", false);
    scriptOutputValues.put("output1", pyObjectValue1);
    scriptOutputValues.put("output2", pyObjectValue2);
    when(execInterpreter.getLocals()).thenReturn(new PyStringMap(scriptOutputValues));
    when(execInterpreter.get(eq("output1"))).thenReturn(pyObjectValue1);
    when(execInterpreter.get(eq("output2"))).thenReturn(pyObjectValue2);
    Map<String, Serializable> expectedScriptOutputs = new HashMap<>();
    expectedScriptOutputs.put("output1", value1);
    expectedScriptOutputs.put("output2", value2);

    final Map<String, Value> outputs = scriptExecutor.executeScript(script, scriptInputValues);

    verify(execInterpreter).set(eq("input1"), eq((Value) pyObjectValue1));
    verify(execInterpreter).set(eq("input2"), eq((Value) pyObjectValue2));
    verify(execInterpreter).exec(script);
    Assert.assertEquals(expectedScriptOutputs, outputs);
}
 
开发者ID:CloudSlang,项目名称:cloud-slang,代码行数:29,代码来源:ScriptExecutorTest.java

示例7: registerFunctions

import org.python.core.PyStringMap; //导入依赖的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);
}
 
开发者ID:PonIC,项目名称:PonIC,代码行数:39,代码来源:JythonScriptEngine.java

示例8: getChildren

import org.python.core.PyStringMap; //导入依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
	if (!(object instanceof PyInstance))
		throw new IllegalArgumentException("object is not instance of PyInstance");
	PyInstance pyInstance = (PyInstance)object;
	PyList keys = null;
	if (pyInstance.__dict__ instanceof PyDictionary)
		keys = ((PyDictionary)pyInstance.__dict__).keys();
	if (pyInstance.__dict__ instanceof PyStringMap)
		keys = ((PyStringMap)pyInstance.__dict__).keys();
	if (keys == null)
		return null;		
	final PyObject pyDict = pyInstance.__dict__;
	int count = keys.__len__();
	ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
	PyObject obj;		
	for (int i = 0; i < count; ++i){
		final PyObject key = keys.__getitem__(i);
		Object name = (String)key.__tojava__(String.class);
		if ((name == Py.NoConversion) || (!(name instanceof String))) continue;
		obj = pyDict.__finditem__(key);
		list.add(
			new PyObjectAdapter(
					(String)name,
					new PyObjectPlace(){
						private PyObject myPlace = key;
						@Override
						public void set(PyObject newValue) {
							pyDict.__setitem__(myPlace, newValue);
						}
						@Override
						public PyObject get(){
							try{
								return pyDict.__finditem__(myPlace);
							} catch (Exception e){
								return null;
							}
						}
					}
			)
		);
	}
	return list;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:45,代码来源:PyInstanceWrapper.java

示例9: hasChildren

import org.python.core.PyStringMap; //导入依赖的package包/类
@Override
public boolean hasChildren(Object pyObject) {
	PyInstance pyInstance = (PyInstance)pyObject;
	return pyInstance.__dict__ instanceof PyDictionary ||
	       pyInstance.__dict__ instanceof PyStringMap;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:7,代码来源:PyInstanceWrapper.java

示例10: PyMapWrapper

import org.python.core.PyStringMap; //导入依赖的package包/类
public PyMapWrapper(PyStringMap map) {
    this.map = map.copy();
}
 
开发者ID:kibertoad,项目名称:swampmachine,代码行数:4,代码来源:PyMapWrapper.java

示例11: getModuleState

import org.python.core.PyStringMap; //导入依赖的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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:54,代码来源:JythonScriptEngine.java

示例12: initInterpreter

import org.python.core.PyStringMap; //导入依赖的package包/类
private void initInterpreter() {
    interpreter.setLocals(new PyStringMap());
}
 
开发者ID:CloudSlang,项目名称:score,代码行数:4,代码来源:PythonExecutor.java

示例13: getModuleState

import org.python.core.PyStringMap; //导入依赖的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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:54,代码来源:JythonScriptEngine.java

示例14: getModuleState

import org.python.core.PyStringMap; //导入依赖的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;
}
 
开发者ID:PonIC,项目名称:PonIC,代码行数:53,代码来源:JythonScriptEngine.java


注:本文中的org.python.core.PyStringMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。