當前位置: 首頁>>代碼示例>>Java>>正文


Java Py類代碼示例

本文整理匯總了Java中org.python.core.Py的典型用法代碼示例。如果您正苦於以下問題:Java Py類的具體用法?Java Py怎麽用?Java Py使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Py類屬於org.python.core包,在下文中一共展示了Py類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupSystemState

import org.python.core.Py; //導入依賴的package包/類
/**
 * Call to ensure that an interpreter is set up and configured and
 * able to load the relevant bundles.
 */
public static synchronized void setupSystemState(String... bundleNames) {

	ClassLoader loader=null;
	if (configuredState==null) { // Relies on setupSystemState() being called early in the server startup.
		loader = createJythonClassLoader(PySystemState.class.getClassLoader());
		initializePythonPath(loader);
	}

PySystemState state = Py.getSystemState();
if (state==configuredState) return;

if (loader==null) {
	// Then someone else has changed the PySystemState
	// They will not have added our
		loader = createJythonClassLoader(state.getClassLoader());   // Don't clobber their working.
}
	state.setClassLoader(loader);

setJythonPaths(state);       // Tries to ensure that enough of jython is on the path
setSpgGeneratorPaths(state, bundleNames); // Adds the scripts directory from points
	Py.setSystemState(state);

	configuredState = state;
}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:29,代碼來源:JythonInterpreterManager.java

示例2: fdopen

import org.python.core.Py; //導入依賴的package包/類
public static PyObject fdopen(PyObject fd, String mode, int bufsize) {
    if (mode.length() == 0 || !"rwa".contains("" + mode.charAt(0))) {
        throw Py.ValueError(String.format("invalid file mode '%s'", mode));
    }
    RawIOBase rawIO = FileDescriptors.get(fd);
    if (rawIO.closed()) {
        throw badFD();
    }

    try {
        return new PyFile(rawIO, "<fdopen>", mode, bufsize);
    } catch (PyException pye) {
        if (!pye.match(Py.IOError)) {
            throw pye;
        }
        throw Py.OSError((Constant)Errno.EINVAL);
    }
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:19,代碼來源:PosixModule.java

示例3: fsync

import org.python.core.Py; //導入依賴的package包/類
/**
 * Internal fsync implementation.
 */
private static void fsync(PyObject fd, boolean metadata) {
    RawIOBase rawIO = FileDescriptors.get(fd);
    rawIO.checkClosed();
    Channel channel = rawIO.getChannel();
    if (!(channel instanceof FileChannel)) {
        throw Py.OSError(Errno.EINVAL);
    }

    try {
        ((FileChannel)channel).force(metadata);
    } catch (ClosedChannelException cce) {
        // In the rare case it's closed but the rawIO wasn't
        throw Py.ValueError("I/O operation on closed file");
    } catch (IOException ioe) {
        throw Py.OSError(ioe);
    }
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:21,代碼來源:PosixModule.java

示例4: unlink

import org.python.core.Py; //導入依賴的package包/類
public static void unlink(PyObject path) {
    String absolutePath = absolutePath(path);
    File file = new File(absolutePath);
    if (!file.delete()) {
        // Something went wrong, does stat raise an error?
        posix.stat(absolutePath);
        // It exists, is it a directory, or do we not have permissions?
        if (file.isDirectory()) {
            throw Py.OSError(Errno.EISDIR, path);
        }
        if (!file.canWrite()) {
            throw Py.OSError(Errno.EPERM, path);
        }
        throw Py.OSError("unlink(): an unknown error occured" + absolutePath);
    }
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:17,代碼來源:PosixModule.java

示例5: utime

import org.python.core.Py; //導入依賴的package包/類
public static void utime(PyObject path, PyObject times) {
    long[] atimeval;
    long[] mtimeval;

    if (times == Py.None) {
        atimeval = mtimeval = null;
    } else if (times instanceof PyTuple && times.__len__() == 2) {
        atimeval = extractTimeval(times.__getitem__(0));
        mtimeval = extractTimeval(times.__getitem__(1));
    } else {
        throw Py.TypeError("utime() arg 2 must be a tuple (atime, mtime)");
    }
    if (posix.utimes(absolutePath(path), atimeval, mtimeval) < 0) {
        throw errorFromErrno(path);
    }
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:17,代碼來源:PosixModule.java

示例6: parse

import org.python.core.Py; //導入依賴的package包/類
public void parse(PyObject[] args, String[] kws) {
    int nargs = args.length - kws.length;
    
    if (nargs < fixedArgs.length) {
        // TODO I need to verify these exceptions bubble up correctly
        throw Py.TypeError(String.format("Not enough arguments to %s(): %d provided, %d needed",
                funcname, nargs, fixedArgs.length));
    }

    // fixed arguments
    for (int i=0; i < fixedArgs.length; i++) {
        this.args.put(fixedArgs[i], args[i]);
    }

    // keyword arguments
    for (int i=0; i < kws.length; i++) {
        if (!this.keywordArgs.contains(kws[i])) {
            throw Py.TypeError(String.format("Unexpected keyword argument to %s(): %s",
                    funcname, kws[i]));
        }
        this.args.put(kws[i], args[nargs + i]);
    }
}
 
開發者ID:r1chardj0n3s,項目名稱:pycode-minecraft,代碼行數:24,代碼來源:ArgParser.java

示例7: callFunc

import org.python.core.Py; //導入依賴的package包/類
public static Object callFunc(Class<?> c, String funcName, Object... binds) {
	try {
		PyObject obj = ScriptManager.python.get(funcName);
		if (obj != null && obj instanceof PyFunction) {
			PyFunction func = (PyFunction) obj;
			PyObject[] objects = new PyObject[binds.length];
			for (int i = 0; i < binds.length; i++) {
				Object bind = binds[i];
				objects[i] = Py.java2py(bind);
			}
			return func.__call__(objects).__tojava__(c);
		} else
			return null;
	} catch (PyException ex) {
		ex.printStackTrace();
		return null;
	}
}
 
開發者ID:Jarinus,項目名稱:osrs-private-server,代碼行數:19,代碼來源:ScriptManager.java

示例8: stop

import org.python.core.Py; //導入依賴的package包/類
/**
 * Get rid of the interpreter.
 */
public void stop() {
	if (interp != null) {
		// PySystemState.exit(); // the big hammar' throws like Thor
		interp.cleanup();
		interp = null;
	}

	if (interpThread != null) {
		interpThread.interrupt();
		interpThread = null;
	}

	if (inputQueueThread != null) {
		inputQueueThread.interrupt();
		inputQueueThread = null;
	}

	thread.interruptAllThreads();
	Py.getSystemState()._systemRestart = true;
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:24,代碼來源:Python.java

示例9: completePackageName

import org.python.core.Py; //導入依賴的package包/類
/**
 * Complete package name
 *
 * @param target Target
 * @return Package names
 */
public List<String> completePackageName(String target) {
    String[] targetComponents = target.split("\\.");
    String base = targetComponents[0];
    PySystemState state = interp.getSystemState();
    PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__"));
    PyObject module = importer.__call__(Py.newString(base));
    if (targetComponents.length > 1) {
        for (int i = 1; i < targetComponents.length; i++) {
            module = module.__getattr__(targetComponents[i]);
        }
    }
    PyList plist = (PyList) module.__dir__();
    List<String> list = new ArrayList<>();
    String name;
    for (int i = 0; i < plist.__len__(); i++) {
        name = plist.get(i).toString();
        if (!name.startsWith("__")) {
            list.add(name);
        }
    }
    //list.add("*");

    return list;
}
 
開發者ID:meteoinfo,項目名稱:MeteoInfoMap,代碼行數:31,代碼來源:JIntrospect.java

示例10: enter

import org.python.core.Py; //導入依賴的package包/類
@Override
public Object enter( String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments ) throws NoSuchMethodException, ParsingException, ExecutionException
{
	entryPointName = toPythonStyle( entryPointName );
	PythonInterpreter pythonInterpreter = (PythonInterpreter) executionContext.getAttributes().get( JYTHON_INTERPRETER );
	Py.setSystemState( pythonInterpreter.getSystemState() );
	PyObject method = pythonInterpreter.get( entryPointName );
	if( method == null )
		throw new NoSuchMethodException( entryPointName );
	try
	{
		PyObject[] pythonArguments = Py.javas2pys( arguments );
		PyObject r = method.__call__( pythonArguments );
		return r.__tojava__( Object.class );
	}
	catch( Exception x )
	{
		throw JythonAdapter.createExecutionException( executable.getDocumentName(), 0, x );
	}
	finally
	{
		flush( pythonInterpreter, executionContext );
	}
}
 
開發者ID:tliron,項目名稱:scripturian,代碼行數:25,代碼來源:JythonAdapter.java

示例11: getList

import org.python.core.Py; //導入依賴的package包/類
public static List<Object> getList(ArgParser ap, int position)
/*     */   {
/* 169 */     PyObject arg = ap.getPyObject(position, Py.None);
/* 170 */     if (Py.isInstance(arg, PyNone.TYPE)) {
/* 171 */       return Collections.emptyList();
/*     */     }
/*     */
/* 174 */     List ret = Lists.newArrayList();
/* 175 */     PyList array = (PyList)arg;
/* 176 */     for (int x = 0; x < array.__len__(); x++) {
/* 177 */       PyObject item = array.__getitem__(x);
/*     */
/* 179 */       Class javaClass = (Class)PYOBJECT_TO_JAVA_OBJECT_MAP.get(item.getClass());
/* 180 */       if (javaClass != null) {
/* 181 */         ret.add(item.__tojava__(javaClass));
/*     */       }
/*     */     }
/* 184 */     return ret;
/*     */   }
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:20,代碼來源:JythonUtils.java

示例12: getMap

import org.python.core.Py; //導入依賴的package包/類
public static Map<String, Object> getMap(ArgParser ap, int position)
/*     */   {
/* 196 */     PyObject arg = ap.getPyObject(position, Py.None);
/* 197 */     if (Py.isInstance(arg, PyNone.TYPE)) {
/* 198 */       return Collections.emptyMap();
/*     */     }
/*     */
/* 201 */     Map ret = Maps.newHashMap();
/*     */
/* 203 */     PyDictionary dict = (PyDictionary)arg;
/* 204 */     PyList items = dict.items();
/* 205 */     for (int x = 0; x < items.__len__(); x++)
/*     */     {
/* 207 */       PyTuple item = (PyTuple)items.__getitem__(x);
/*     */
/* 209 */       String key = (String)item.__getitem__(0).__str__().__tojava__(String.class);
/* 210 */       PyObject value = item.__getitem__(1);
/*     */
/* 213 */       Class javaClass = (Class)PYOBJECT_TO_JAVA_OBJECT_MAP.get(value.getClass());
/* 214 */       if (javaClass != null) {
/* 215 */         ret.put(key, value.__tojava__(javaClass));
/*     */       }
/*     */     }
/* 218 */     return ret;
/*     */   }
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:26,代碼來源:JythonUtils.java

示例13: getCompiledCode

import org.python.core.Py; //導入依賴的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

示例14: getParamsFromVariables

import org.python.core.Py; //導入依賴的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

示例15: pigToPython

import org.python.core.Py; //導入依賴的package包/類
public static PyObject pigToPython(Object object) {
    if (object instanceof Tuple) {
        return pigTupleToPyTuple((Tuple) object);
    } else if (object instanceof DataBag) {
        PyList list = new PyList();
        for (Tuple bagTuple : (DataBag) object) {
            list.add(pigTupleToPyTuple(bagTuple));
        }
        return list;
    } else if (object instanceof Map<?, ?>) {
        PyDictionary newMap = new PyDictionary();
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
            newMap.put(entry.getKey(), pigToPython(entry.getValue()));
        }
        return newMap;
    } else if (object instanceof DataByteArray) {
        return Py.java2py(((DataByteArray) object).get());
    } else {
        return Py.java2py(object);
    }
}
 
開發者ID:sigmoidanalytics,項目名稱:spork-streaming,代碼行數:22,代碼來源:JythonUtils.java


注:本文中的org.python.core.Py類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。