Examples of PyObject


Examples of org.python.core.PyObject

  //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

Examples of org.python.core.PyObject

     @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

Examples of org.python.core.PyObject

     @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

Examples of org.python.core.PyObject

     *  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

Examples of org.python.core.PyObject

     *  error in calling the method.
     */
    private PyObject _invokeMethod(String methodName, Object[] args)
            throws IllegalActionException {
        PyMethod method = (PyMethod) _methodMap.get(methodName);
        PyObject returnValue = null;

        if (method != null) {
            try {
                if ((args == null) || (args.length == 0)) {
                    returnValue = method.__call__();
View Full Code Here

Examples of org.python.core.PyObject

     @return The return value of the command, or null if there is none.
     *  @exception Exception If something goes wrong processing the command.
     */
    public String evaluateCommand(String command) throws Exception {
        try {
            PyObject results = _interpreter.eval(command);
            return results.toString();
        } catch (Throwable throwable) {
            return throwable.toString();
        }
    }
View Full Code Here

Examples of org.python.core.PyObject

        callable = c;
        operation = op;
    }

    String apply(final String req) {
        PyObject r = callable.__call__(new PyString(req));
        return r.toString();
    }
View Full Code Here

Examples of org.python.core.PyObject

                    return v;
                }
            }));
        }

        PyObject mkc = python.get("mkcomponent");
        callable = mkc.__call__(new PyString(component.getName()), new PyString(implementation.getScript()), new PyTuple(px.toArray(new PyObject[0])), new PyTuple(pr.toArray(new PyObject[0])));
    }
View Full Code Here

Examples of org.python.core.PyObject

    NonCoreContract parserContract = NonCoreContract
        .getNonCoreContract("bill-parser-" + extension);
    try {
      PythonInterpreter interpreter = new PythonInterpreter();
      interpreter.exec(parserContract.getChargeScript());
      PyObject parserClass = interpreter.get("Parser");
      parser = (BillParser) parserClass
          .__call__(
              PyJavaType.wrapJavaObject(new InputStreamReader(is,
                  "UTF-8"))).__tojava__(BillParser.class);
    } catch (UnsupportedEncodingException e) {
      throw new InternalException(e);
View Full Code Here

Examples of org.python.core.PyObject

    Object result = null;
    PythonInterpreter interp = new PythonInterpreter();
    try {
      interp.set("contract", this);
      interp.exec(chargeScript);
      PyObject function = interp.get(name);
      if (function == null) {
        throw new UserException("There isn't a function called " + name);
      }
      result = function.__call__(Py.javas2pys(args)).__tojava__(
          Object.class);
    } catch (Throwable e) {
      throw new UserException(HttpException.getStackTraceString(e));
    } finally {
      interp.cleanup();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.