Search in sources :

Example 1 with PyStringMap

use of org.python.core.PyStringMap in project yamcs-studio by yamcs.

the class ExecutePythonScriptAction method dispose.

@Override
public void dispose() {
    if (interpreter != null) {
        PyObject o = interpreter.getLocals();
        if (o != null && o instanceof PyStringMap) {
            ((PyStringMap) o).clear();
        }
        o = state.getDict();
        if (o != null && o instanceof PyStringMap) {
            ((PyStringMap) o).clear();
        }
        state.close();
        state.cleanup();
        interpreter.close();
        interpreter.cleanup();
        interpreter = null;
        state = null;
    }
    super.dispose();
}
Also used : PyStringMap(org.python.core.PyStringMap) PyObject(org.python.core.PyObject)

Example 2 with PyStringMap

use of org.python.core.PyStringMap in project artisynth_core by artisynth.

the class NumericProbeBase method updateJythonVariables.

protected void updateJythonVariables(HashMap<String, NumericProbeVariable> variables, double time) {
    if (myJythonLocals != null) {
        PyStringMap map = myJythonLocals;
        for (Map.Entry<String, NumericProbeVariable> entry : variables.entrySet()) {
            NumericProbeVariable var = entry.getValue();
            map.__setitem__(new PyString(entry.getKey()), Py.java2py(var.getValue()));
        }
        map.__setitem__("t", Py.java2py(time));
    }
}
Also used : PyString(org.python.core.PyString) PyStringMap(org.python.core.PyStringMap) PyString(org.python.core.PyString) PyStringMap(org.python.core.PyStringMap)

Example 3 with PyStringMap

use of org.python.core.PyStringMap in project freemarker by apache.

the class JythonModelCache method create.

@Override
protected TemplateModel create(Object obj) {
    boolean asHash = false;
    boolean asSequence = false;
    JythonVersionAdapter versionAdapter = JythonVersionAdapterHolder.INSTANCE;
    if (versionAdapter.isPyInstance(obj)) {
        Object jobj = versionAdapter.pyInstanceToJava(obj);
        // FreeMarker-aware, Jython-wrapped Java objects are left intact
        if (jobj instanceof TemplateModel) {
            return (TemplateModel) jobj;
        }
        if (jobj instanceof Map) {
            asHash = true;
        }
        if (jobj instanceof Date) {
            return new DateModel((Date) jobj, BeansWrapper.getDefaultInstance());
        } else if (jobj instanceof Collection) {
            asSequence = true;
            // doesn't support sets.
            if (!(jobj instanceof List)) {
                obj = new ArrayList((Collection) jobj);
            }
        }
    }
    // If it's not a PyObject, first make a PyObject out of it.
    if (!(obj instanceof PyObject)) {
        obj = Py.java2py(obj);
    }
    if (asHash || obj instanceof PyDictionary || obj instanceof PyStringMap) {
        return JythonHashModel.FACTORY.create(obj, wrapper);
    }
    if (asSequence || obj instanceof PySequence) {
        return JythonSequenceModel.FACTORY.create(obj, wrapper);
    }
    if (obj instanceof PyInteger || obj instanceof PyLong || obj instanceof PyFloat) {
        return JythonNumberModel.FACTORY.create(obj, wrapper);
    }
    if (obj instanceof PyNone) {
        return null;
    }
    return JythonModel.FACTORY.create(obj, wrapper);
}
Also used : DateModel(freemarker.ext.beans.DateModel) ArrayList(java.util.ArrayList) PyFloat(org.python.core.PyFloat) TemplateModel(freemarker.template.TemplateModel) PyInteger(org.python.core.PyInteger) PyDictionary(org.python.core.PyDictionary) Date(java.util.Date) PyNone(org.python.core.PyNone) PyLong(org.python.core.PyLong) PyStringMap(org.python.core.PyStringMap) Collection(java.util.Collection) PyObject(org.python.core.PyObject) ArrayList(java.util.ArrayList) List(java.util.List) PySequence(org.python.core.PySequence) PyStringMap(org.python.core.PyStringMap) Map(java.util.Map) PyObject(org.python.core.PyObject)

Example 4 with PyStringMap

use of org.python.core.PyStringMap in project apex-malhar by apache.

the class PythonOperator method getBindings.

@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;
}
Also used : HashMap(java.util.HashMap) PyStringMap(org.python.core.PyStringMap) PyIterator(org.python.core.PyIterator) PyObject(org.python.core.PyObject) PyTuple(org.python.core.PyTuple) PyObject(org.python.core.PyObject)

Example 5 with PyStringMap

use of org.python.core.PyStringMap in project yamcs-studio by yamcs.

the class JythonScriptStore method dispose.

@Override
protected void dispose() {
    if (interp != null) {
        PyObject o = interp.getLocals();
        if (o != null && o instanceof PyStringMap) {
            ((PyStringMap) o).clear();
        }
        // o = state.getBuiltins();
        // if (o != null && o instanceof PyStringMap) {
        // ((PyStringMap)o).clear();
        // }
        o = state.getDict();
        if (o != null && o instanceof PyStringMap) {
            ((PyStringMap) o).clear();
        }
        state.close();
        state.cleanup();
        interp.close();
        interp.cleanup();
        interp = null;
        state = null;
    }
    code = null;
    super.dispose();
}
Also used : PyStringMap(org.python.core.PyStringMap) PyObject(org.python.core.PyObject)

Aggregations

PyStringMap (org.python.core.PyStringMap)5 PyObject (org.python.core.PyObject)4 DateModel (freemarker.ext.beans.DateModel)1 TemplateModel (freemarker.template.TemplateModel)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 PyDictionary (org.python.core.PyDictionary)1 PyFloat (org.python.core.PyFloat)1 PyInteger (org.python.core.PyInteger)1 PyIterator (org.python.core.PyIterator)1 PyLong (org.python.core.PyLong)1 PyNone (org.python.core.PyNone)1 PySequence (org.python.core.PySequence)1 PyString (org.python.core.PyString)1 PyTuple (org.python.core.PyTuple)1