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


Java PyCode类代码示例

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


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

示例1: execute

import org.python.core.PyCode; //导入依赖的package包/类
public void execute( ExecutionContext executionContext ) throws ParsingException, ExecutionException
{
	PythonInterpreter pythonInterpreter = adapter.getPythonInterpreter( executionContext, executable );

	try
	{
		PyCode pythonCode = this.pythonCode;
		if( pythonCode != null )
			pythonInterpreter.exec( pythonCode );
		else
			// We're using a stream because PythonInterpreter does not
			// expose a string-based method that also accepts a filename.
			pythonInterpreter.execfile( new ByteArrayInputStream( sourceCode.getBytes() ), executable.getDocumentName() );
	}
	catch( Exception x )
	{
		throw JythonAdapter.createExecutionException( executable.getDocumentName(), startLineNumber, x );
	}
	finally
	{
		JythonAdapter.flush( pythonInterpreter, executionContext );
	}
}
 
开发者ID:tliron,项目名称:scripturian,代码行数:24,代码来源:JythonProgram.java

示例2: populateSelection

import org.python.core.PyCode; //导入依赖的package包/类
private void populateSelection() {
	List<Table> tables = new ArrayList<Table>();
	Worksheet worksheet = workspace.getWorksheet(worksheetId);
	CloneTableUtils.getDatatable(worksheet.getDataTable(), workspace.getFactory().getHTable(hTableId), tables, SuperSelectionManager.DEFAULT_SELECTION);
	String selectionId = Thread.currentThread().getId() + this.superSelectionName;
	PythonRepository repo = PythonRepository.getInstance();
	PythonInterpreter interpreter = repo.interpreter;
	repo.initializeInterperter(interpreter);
	PyCode code = null;
	try {
		code = getCompiledCode(pythonCode, interpreter, selectionId);
		interpreter.getLocals().__setitem__("selection", interpreter.get("selection"+selectionId));
		
	
		for (Table t : tables) {
			for (Row r : t.getRows(0, t.getNumRows(), SuperSelectionManager.DEFAULT_SELECTION)) {
				if (code == null)
					selectedRowsCache.put(r, onError);
				else
					selectedRowsCache.put(r, evaluatePythonExpression(r, code, interpreter));
			}
		}
	} catch(Exception e) {
		logger.error("Unable to populate selection");
	}
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:27,代码来源:MiniSelection.java

示例3: getCompiledCode

import org.python.core.PyCode; //导入依赖的package包/类
private PyCode getCompiledCode(String pythonCode, PythonInterpreter interpreter, String selectionId) throws IOException {

		String trimmedSelectionCode = pythonCode.trim();
		Worksheet worksheet = workspace.getWorksheet(worksheetId);
		if (trimmedSelectionCode.isEmpty()) {
			trimmedSelectionCode = "return False";
		}
		String selectionMethodStmt = PythonTransformationHelper
				.getPythonSelectionMethodDefinitionState(worksheet,
						trimmedSelectionCode,selectionId);


		logger.debug("Executing PySelection\n" + selectionMethodStmt);

		// Prepare the Python interpreter
		PythonRepository repo = PythonRepository.getInstance();

		repo.compileAndAddToRepositoryAndExec(interpreter, selectionMethodStmt);
		PyObject locals = interpreter.getLocals();
		locals.__setitem__("workspaceid", new PyString(workspace.getId()));
		locals.__setitem__("selectionName", new PyString(superSelectionName));
		locals.__setitem__("command", Py.java2py(this));
		return repo.getSelectionCode();
	}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:25,代码来源:MiniSelection.java

示例4: initialize

import org.python.core.PyCode; //导入依赖的package包/类
private void initialize()
{
	scripts = new ConcurrentHashMap<String, PyCode>();

	
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getImportStatements());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getRowIndexDefStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getGetValueDefStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getGetValueFromNestedColumnByIndexDefStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getIsEmptyDefStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getHasSelectedRowsStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getVDefStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getTransformStatement());
	compileAndAddToRepository(interpreter, PythonTransformationHelper.getSelectionStatement());
	initializeInterperter(interpreter);
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:17,代码来源:PythonRepository.java

示例5: PythonScriptExecutorPool

import org.python.core.PyCode; //导入依赖的package包/类
public PythonScriptExecutorPool(GameScriptingEngine gameScriptingEngine, int poolSize) {
	this.gameScriptingEngine = gameScriptingEngine;
	executors = new ArrayBlockingQueue<ScriptExecutor<PyCode>>(poolSize);

	for (int i = 0; i < poolSize; i++) {
		executors.offer(new PythonScriptExecutor(this));
	}
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:9,代码来源:PythonScriptExecutorPool.java

示例6: preCompileScript

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public int preCompileScript(String scriptContent) throws InsufficientCompilersException {
	ScriptExecutor<PyCode> executor = executors.poll();
	if (executor == null) {
		throw new InsufficientCompilersException();
	}
	GameScript<PyCode> script = executor.compile(scriptContent);
	executor.release();
	scripts.put(script.getId(), script);
	return script.getId();
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:12,代码来源:PythonScriptExecutorPool.java

示例7: execute

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public ScriptExecutionTask<?> execute(int scriptId, ScriptBindings scriptBindings,
		ScriptInvocationListener invocationListener) {
	ScriptExecutor<PyCode> executor = allocateExecutor();
	if (executor == null) {
		throw new ScriptExecutorUnavailableException(scriptId);
	}
	return new ScriptExecutionTask<PyCode>(gameScriptingEngine, executor, scripts.get(scriptId), scriptBindings,
			invocationListener);
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:11,代码来源:PythonScriptExecutorPool.java

示例8: release

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public void release(ScriptExecutor<PyCode> executor) {
	try {
		executors.put(executor);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:9,代码来源:PythonScriptExecutorPool.java

示例9: allocateExecutor

import org.python.core.PyCode; //导入依赖的package包/类
private ScriptExecutor<PyCode> allocateExecutor() {
	try {
		return executors.take();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:9,代码来源:PythonScriptExecutorPool.java

示例10: compile

import org.python.core.PyCode; //导入依赖的package包/类
/** Parse and compile script file
 *
 *  @param path Path to add to search path, or <code>null</code>
 *  @param name Name of script (file name, URL)
 *  @param stream Stream for the script content
 *  @return {@link Script}
 *  @throws Exception on error
 */
public Script compile(final String path, final String name, final InputStream stream) throws Exception
{
    if (path != null)
        addToPythonPath(path);
    final long start = System.currentTimeMillis();
    final PyCode code = python.compile(new InputStreamReader(stream), name);
    final long end = System.currentTimeMillis();
    logger.log(Level.FINE, "Time to compile {0}: {1} ms", new Object[] { name, (end - start) });
    return new JythonScript(this, name, code);
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:19,代码来源:JythonScriptSupport.java

示例11: JythonScript

import org.python.core.PyCode; //导入依赖的package包/类
/** Parse and compile script file
 *
 *  @param support {@link JythonScriptSupport} that will execute this script
 *  @param name Name of script (file name, URL)
 *  @param code Compiled code
 */
public JythonScript(final JythonScriptSupport support, final String name, final PyCode code)
{
    this.support = support;
    this.name = name;
    this.code = code;
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:13,代码来源:JythonScript.java

示例12: testInterpreter

import org.python.core.PyCode; //导入依赖的package包/类
private void testInterpreter(final PythonInterpreter python) throws Exception
{
    // Run on new threads to get fresh thread-locals
    final ExecutorService new_executor = Executors.newCachedThreadPool();

    final String script = "import sys\nresult = sys.path";
    final Callable<String> test_run = () ->
    {
        // System.out.println("Executing on " + Thread.currentThread().getName());
        final PyCode code = python.compile(script);
        python.exec(code);
        return python.get("result").toString();
    };

    final List<Future<String>> futures = new ArrayList<>();
    final long end = System.currentTimeMillis() + 1000L;
    while (System.currentTimeMillis() < end)
    {
        for (int i=0; i<50; ++i)
            futures.add(new_executor.submit(test_run));
        for (Future<String> future : futures)
        {
            final String result = future.get();
            //System.out.println(result);
            assertThat(result, containsString("always"));
            assertThat(result, containsString("special"));
        }
        futures.clear();
    }
    new_executor.shutdown();
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:32,代码来源:JythonTest.java

示例13: parseScript

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public PythonScript parseScript(Reader reader) {
    try (PythonInterpreter interp = new PythonInterpreter()) {
        PyCode compiledCode = interp.compile(reader);
        PythonScript activeScript = new PythonScript(compiledCode);
        return activeScript;
    }
}
 
开发者ID:kibertoad,项目名称:swampmachine,代码行数:9,代码来源:PythonScriptParser.java

示例14: evaluatePythonExpression

import org.python.core.PyCode; //导入依赖的package包/类
private boolean evaluatePythonExpression(Row r, PyCode code, PythonInterpreter interpreter) {
	evalColumns.clear();
	try {
		ArrayList<Node> nodes = new ArrayList<Node>(r.getNodes());
		Node node = nodes.get(0);
		interpreter.getLocals().__setitem__("nodeid", new PyString(node.getId()));
		PyObject output = interpreter.eval(code);
		return PythonTransformationHelper.getPyObjectValueAsBoolean(output);
	}catch(Exception e) {
		return onError;
	}

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

示例15: compileAndAddToRepositoryAndExec

import org.python.core.PyCode; //导入依赖的package包/类
public PyCode compileAndAddToRepositoryAndExec(PythonInterpreter interpreter, String statement)
{
	PyCode py  = null;
	if(!scripts.containsKey(statement))
	{
		py = compileAndAddToRepository(interpreter,statement);
		
	}
	else
		py = scripts.get(statement);
	interpreter.exec(py);
	return py;
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:14,代码来源:PythonRepository.java


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