org.python.core.PyTuple Java Examples
The following examples show how to use
org.python.core.PyTuple.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JythonScriptEngine.java From spork with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: JythonUtils.java From AndroidRobot with Apache License 2.0 | 6 votes |
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; /* */ }
Example #3
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object time_string_from_date(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return Time.strftime("%H:%M:%S", timeTuple); }
Example #4
Source File: JythonUtils.java From spork with Apache License 2.0 | 5 votes |
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); }
Example #5
Source File: PythonOperator.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@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; }
Example #6
Source File: FrmMain.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Delete variables */ public void delVariables() { PythonInteractiveInterpreter interp = this.consoleDock.getInterpreter(); PyStringMap locals = (PyStringMap) interp.getLocals(); PyList items = locals.items(); String name; for (Object a : items) { PyTuple at = (PyTuple) a; name = at.__getitem__(0).toString(); if (!this.loadObjects.contains(name)) { locals.__delitem__(name); } } }
Example #7
Source File: PythonStreamExecutionEnvironment.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static void registerJythonSerializers(StreamExecutionEnvironment env) { env.registerTypeWithKryoSerializer(PyBoolean.class, PyBooleanSerializer.class); env.registerTypeWithKryoSerializer(PyFloat.class, PyFloatSerializer.class); env.registerTypeWithKryoSerializer(PyInteger.class, PyIntegerSerializer.class); env.registerTypeWithKryoSerializer(PyLong.class, PyLongSerializer.class); env.registerTypeWithKryoSerializer(PyString.class, PyStringSerializer.class); env.registerTypeWithKryoSerializer(PyUnicode.class, PyObjectSerializer.class); env.registerTypeWithKryoSerializer(PyTuple.class, PyObjectSerializer.class); env.registerTypeWithKryoSerializer(PyObjectDerived.class, PyObjectSerializer.class); env.registerTypeWithKryoSerializer(PyInstance.class, PyObjectSerializer.class); }
Example #8
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object date_as_string(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return Time.strftime("%Y-%m-%d %H:%M:%S", timeTuple); }
Example #9
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object year(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(0); }
Example #10
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object time_from_date(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return (timeTuple.__getitem__(3).asInt() * MINS_IN_HOUR * SECS_IN_MIN * MILLISECS_IN_SEC) + (timeTuple.__getitem__(4).asInt() * SECS_IN_MIN * MILLISECS_IN_SEC) + (timeTuple.__getitem__(5).asInt() * MILLISECS_IN_SEC); }
Example #11
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object weekday_name(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return Time.strftime("%A", timeTuple); }
Example #12
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object month_name(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return Time.strftime("%B", timeTuple); }
Example #13
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object weekday(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(6); }
Example #14
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object second(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(5); }
Example #15
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object minute(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(4); }
Example #16
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object hour(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(3); }
Example #17
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object day(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(2); }
Example #18
Source File: TimeUtilities.java From constellation with Apache License 2.0 | 5 votes |
public Object month(Object time_ms) throws ScriptException { if (nullCheck(time_ms)) { return time_ms; } PyLong time = new PyLong(((Number) time_ms).longValue() / 1000); PyTuple timeTuple = Time.gmtime(time); return timeTuple.__getitem__(1); }
Example #19
Source File: FlightTelemetry.java From hazelcast-jet-demos with Apache License 2.0 | 4 votes |
PyList getAsList() { PyList list = new PyList(); PyTuple metric = new PyTuple(metricName, new PyTuple(timestamp, metricValue)); list.add(metric); return list; }
Example #20
Source File: AndroidRobot.java From sikuli-monkey with MIT License | 4 votes |
public void longPress(int x, int y) { PyTuple point = new PyTuple(new PyInteger(x), new PyInteger(y)); _device.drag(new PyObject[] { point, point, new PyInteger(2), new PyInteger(2) }, null); }
Example #21
Source File: JythonScriptEngine.java From spork with Apache License 2.0 | 4 votes |
/** * 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; }