Package org.python.core

Examples of org.python.core.PyObject$ConversionException


    public void setVariable(String name, Object value) throws Exception {
        if (mPySimulator == null) {
            logAndThrowException("Python simulator instance not loaded");
        }
        try {
            PyObject pyValue = (value instanceof PyObject) ? (PyObject) value : Py.java2py(value);
            mPySimulator.__setattr__(new PyString(name), pyValue);
            return;
        } catch (PyException e) {
            logAndThrowException("Error while setting value of " + name + " variable of Python simulator instance", e);
        }
View Full Code Here


    public Object invoke(String method, Object[] arguments) throws Exception {
        if (mPySimulator == null) {
            logAndThrowException("Python simulator instance not loaded");
        }
        try {
            PyObject pyMethod = mPySimulator.__getattr__(new PyString(method));
            return pyMethod._jcall(arguments);
        } catch (PyException e) {
            logAndThrowException("Error while invoking " + method + " method of Python simulator instance", e);
        }
        return null; // not executed
    }
View Full Code Here

    @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
        return new PythonSearchScript((PyCode) compiledScript, vars, lookup);
    }

    @Override public Object execute(Object compiledScript, Map<String, Object> vars) {
        PyObject pyVars = Py.java2py(vars);
        interp.setLocals(pyVars);
        PyObject ret = interp.eval((PyCode) compiledScript);
        if (ret == null) {
            return null;
        }
        return ret.__tojava__(Object.class);
    }
View Full Code Here

            pyVars.__setitem__(name, Py.java2py(value));
        }

        @Override public Object run() {
            interp.setLocals(pyVars);
            PyObject ret = interp.eval(code);
            if (ret == null) {
                return null;
            }
            return ret.__tojava__(Object.class);
        }
View Full Code Here

            pyVars.__setitem__(name, Py.java2py(value));
        }

        @Override public Object run() {
            interp.setLocals(pyVars);
            PyObject ret = interp.eval(code);
            if (ret == null) {
                return null;
            }
            return ret.__tojava__(Object.class);
        }
View Full Code Here

  }

  protected Object get(String name) {
    //Bug 2208873: Don't use _ip.get(String, Object) since it
    //doesn't handle null well
    PyObject val = _ip.get(name);
    return val != null ? Py.tojava(val, Object.class): null;
  }
View Full Code Here

  //helper classes//
  /** The global scope. */
  private class Variables extends PyStringMap {
    public synchronized PyObject __finditem__(String key) {
      PyObject pyo = super.__finditem__(key);

      if (pyo == null) { // use "null" without "Py.None", because we override __finditem__
        Object val = getFromNamespace(key);
        if (val != UNDEFINED)
          return Py.java2py(val);
View Full Code Here

     @exception IllegalActionException If there is any error in calling the
     *   postfire() method defined by the script.
     */
    public boolean postfire() throws IllegalActionException {
        boolean defaultResult = super.postfire();
        PyObject postfireResult = _invokeMethod("postfire", null);

        if (postfireResult != null) {
            return postfireResult.__nonzero__();
        } else {
            return defaultResult;
        }
    }
View Full Code Here

     @exception IllegalActionException If there is any error in calling the
     *   prefire() method.
     */
    public boolean prefire() throws IllegalActionException {
        boolean defaultResult = super.prefire();
        PyObject prefireResult = _invokeMethod("prefire", null);

        if (prefireResult != null) {
            return prefireResult.__nonzero__();
        } else {
            return defaultResult;
        }
    }
View Full Code Here

     *  defined in the script.
     */
    private PyObject _createObject() throws IllegalActionException {
        // create an instance by using the __call__ method
        // of the Main class object
        PyObject object = _class.__call__();

        if (object == null) {
            throw new IllegalActionException(this,
                    "Error in creating an instance of the Main class "
                            + "defined in the script.");
        }

        // set up access to this actor
        // first create an attribute "actor" on the object
        // the PyObject class does not allow adding a new attribute to the
        // object
        object.__setattr__("actor", new PyJavaInstance(this));

        // give the object access to attributes and ports of this actor
        Iterator attributes = attributeList().iterator();

        while (attributes.hasNext()) {
            Attribute attribute = (Attribute) attributes.next();
            String mangledName = _mangleName(attribute.getName());

            if (_debugging) {
                _debug("set up reference to attribute \"" + attribute.getName()
                        + "\" as \"" + mangledName + "\"");
            }

            object.__setattr__(new PyString(mangledName), new PyJavaInstance(
                    attribute));
        }

        Iterator ports = portList().iterator();

        while (ports.hasNext()) {
            Port port = (Port) ports.next();
            String mangledName = _mangleName(port.getName());

            if (_debugging) {
                _debug("set up reference to port \"" + port.getName()
                        + "\" as \"" + mangledName + "\"");
            }

            object.__setattr__(new PyString(mangledName), new PyJavaInstance(
                    port));
        }

        // populate the method map
        for (int i = 0; i < _METHOD_NAMES.length; ++i) {
            String methodName = _METHOD_NAMES[i];
            PyMethod method = null;

            try {
                method = (PyMethod) object.__findattr__(methodName);
            } catch (ClassCastException ex) {
                // the object has an attribute with the methodName but
                // is not a method, ignore
            }

View Full Code Here

TOP

Related Classes of org.python.core.PyObject$ConversionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.