本文整理汇总了Java中org.python.core.PyTuple类的典型用法代码示例。如果您正苦于以下问题:Java PyTuple类的具体用法?Java PyTuple怎么用?Java PyTuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PyTuple类属于org.python.core包,在下文中一共展示了PyTuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getJavaObject
import org.python.core.PyTuple; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
if (!(pyObject instanceof PyTuple))
throw new IllegalArgumentException("pyObject is not instance of PyTuple");
PyTuple pyTuple = (PyTuple) pyObject;
int count = (pyTuple.__len__());
ArrayList list = new ArrayList(count);
PyObject obj = null;
PyObjectWrapper wrapper = null;
for (int i = 0; i < count; ++i){
obj = pyTuple.__getitem__(i);
wrapper = PyObjectWrappersManager.getWrapper(obj.getClass());
list.add(wrapper.getJavaObject(obj));
}
return list;
}
示例3: PyObjectWrappersManager
import org.python.core.PyTuple; //导入依赖的package包/类
protected PyObjectWrappersManager(){
PyObjectWrappersManager.wrappers.put(PyInteger.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(Integer.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(PyFloat.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Float.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Double.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(PyLong.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(Long.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(BigInteger.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(PyString.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(String.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(PyList.class, new PyListWrapper());
PyObjectWrappersManager.wrappers.put(PyDictionary.class, new PyDictionaryWrapper());
PyObjectWrappersManager.wrappers.put(PyTuple.class, new PyTupleWrapper());
PyObjectWrappersManager.wrappers.put(PyInstance.class, new PyInstanceWrapper());
}
示例4: utime
import org.python.core.PyTuple; //导入依赖的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);
}
}
示例5: getMap
import org.python.core.PyTuple; //导入依赖的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;
/* */ }
示例6: 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;
}
示例7: getChildren
import org.python.core.PyTuple; //导入依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyTuple))
throw new IllegalArgumentException("object is not instance of PyTuple");
final PyTuple pyTuple = (PyTuple) object;
int count = (pyTuple.__len__());
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
for (int i = 0; i < count; ++i){
final int place = i;
list.add(
new PyObjectAdapter(
String.valueOf(i),
new PyObjectPlace(){
private int myPlace = place;
@Override
public void set(PyObject newValue) {
}
@Override
public PyObject get(){
try{
return pyTuple.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}
示例8: getNewValue
import org.python.core.PyTuple; //导入依赖的package包/类
/**
* Accepts List<PyObject> as parameter of newValue.
* Returns PyList
*/
@Override
public PyObject getNewValue(Object newValue) {
if (!(newValue instanceof List)){
throw new IllegalArgumentException("newValue is not instance of List");
}
List list = (List)newValue;
PyObject[] elements = new PyObject[list.size()];
for (int i = 0; i < list.size(); ++i){
if (!(list.get(i) instanceof PyObject))
throw new IllegalArgumentException("value of the list is not instance of PyObject");
elements[i] = (PyObject)list.get(i);
}
return new PyTuple(elements);
}
示例9: rmdir
import org.python.core.PyTuple; //导入依赖的package包/类
public static void rmdir(PyObject path) {
File file = new File(absolutePath(path));
if (!file.exists()) {
throw Py.OSError(Errno.ENOENT, path);
} else if (!file.isDirectory()) {
throw Py.OSError(Errno.ENOTDIR, path);
} else if (!file.delete()) {
PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't delete directory"),
path);
throw new PyException(Py.OSError, args);
}
}
示例10: if
import org.python.core.PyTuple; //导入依赖的package包/类
@Hide(OS.NT)
public static PyObject wait$() {
int[] status = new int[1];
int pid = posix.wait(status);
if (pid < 0) {
throw errorFromErrno();
}
return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0]));
}
示例11: waitpid
import org.python.core.PyTuple; //导入依赖的package包/类
public static PyObject waitpid(int pid, int options) {
int[] status = new int[1];
pid = posix.waitpid(pid, status, options);
if (pid < 0) {
throw errorFromErrno();
}
return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0]));
}
示例12: _get_shell_commands
import org.python.core.PyTuple; //导入依赖的package包/类
/**
* Helper function for the subprocess module, returns the potential shell commands for
* this OS.
*
* @return a tuple of lists of command line arguments. E.g. (['/bin/sh', '-c'])
*/
public static PyObject _get_shell_commands() {
String[][] commands = os.getShellCommands();
PyObject[] commandsTup = new PyObject[commands.length];
int i = 0;
for (String[] command : commands) {
PyList args = new PyList();
for (String arg : command) {
args.append(new PyString(arg));
}
commandsTup[i++] = args;
}
return new PyTuple(commandsTup);
}
示例13: getBindings
import org.python.core.PyTuple; //导入依赖的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;
}
示例14: pigTupleToPyTuple
import org.python.core.PyTuple; //导入依赖的package包/类
public static PyTuple pigTupleToPyTuple(Tuple tuple) {
PyObject[] pyTuple = new PyObject[tuple.size()];
int i = 0;
for (Object object : tuple.getAll()) {
pyTuple[i++] = pigToPython(object);
}
return new PyTuple(pyTuple);
}
示例15: 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);
}