• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PyCode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: compileAndAddToRepository

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


示例17: resetLibrary

import org.python.core.PyCode; //导入依赖的package包/类
public synchronized void resetLibrary()
{
	libraryScripts = new ConcurrentHashMap<String, PyCode>();
	fileNameTolastTimeRead = new ConcurrentHashMap<String,Long>();		
	libraryHasBeenLoaded = false;

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


示例18: runJythonScript

import org.python.core.PyCode; //导入依赖的package包/类
/**
 * Runs the given PyCode, optionally in a thread.
 * @param code The already compiled PyCode object.
 * @param path The path to the script file.
 * @param async Boolean indicating whether to run the script in a separate thread or not. If 
 * true, the execution is asynchronous and the call returns immediately.
 */
public void runJythonScript(final PyCode code, String path, boolean async) {
    if (currentScripts.size() < maxScripts) {
        Thread run = new ScriptRunnable(code, path);

        if (async) {
            run.start();
        } else {
            run.run();
        }
    } else {
        EventManager.instance.post(Events.POST_NOTIFICATION, I18n.bundle.format("notif.script.max", maxScripts));
    }
}
 
开发者ID:langurmonkey,项目名称:gaiasky,代码行数:21,代码来源:JythonFactory.java


示例19: notify

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public void notify(Events event, Object... data) {
    switch (event) {
    case RUN_SCRIPT_PYCODE:
        PyCode code = (PyCode) data[0];
        String path = (String) data[1];
        boolean async = true;
        if (data.length > 1)
            async = (Boolean) data[2];
        runJythonScript(code, path, async);
        break;
    case RUN_SCRIPT_PATH:
        path = (String) data[0];
        FileHandle file = Gdx.files.internal(path);
        String string = file.readString();
        async = true;
        if (data.length > 1)
            async = (Boolean) data[1];
        runJythonScript(string, path, async);
        break;
    case CANCEL_SCRIPT_CMD:
        String pathToCancel = currentScripts.keySet().iterator().next();
        cancelScript(pathToCancel);
        break;
    }

}
 
开发者ID:langurmonkey,项目名称:gaiasky,代码行数:28,代码来源:JythonFactory.java


示例20: compile

import org.python.core.PyCode; //导入依赖的package包/类
@Override
public GameScript<PyCode> compile(String script) {
	return new GlobalGameScript<PyCode>(pythonInterpreter.compile(script));
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:5,代码来源:PythonScriptExecutor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Explosion类代码示例发布时间:2022-05-22
下一篇:
Java P类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap