Examples of PyString


Examples of org.python.core.PyString

        }

        // Scalars are marshalled to PyString.
        if(model instanceof TemplateScalarModel)
        {
            return new PyString(((TemplateScalarModel)model).getAsString());
        }
       
        // Numbers are wrapped to Python built-in numeric types.
        if(model instanceof TemplateNumberModel)
        {
View Full Code Here

Examples of org.python.core.PyString

        while ( declIter.hasNext( ) )
        {
            eachDecl = (Declaration) declIter.next( );

            dict.setdefault( new PyString( eachDecl.getIdentifier( ).intern( ) ),
                             Py.java2py( tuple.get( eachDecl ) ) );

            objectType = eachDecl.getObjectType( );

            if ( objectType instanceof ClassObjectType )
            {
                clazz = ((ClassObjectType) objectType).getType( );
                type = clazz.getName( );

                nestedClassPosition = type.indexOf( '$' );

                if ( nestedClassPosition != -1 )
                {
                    type = type.substring( 0,
                                           nestedClassPosition );
                    clazz = cl.loadClass( type );
                }

                if ( type.indexOf( "java.lang" ) == -1 )
                {
                    dotPosition = type.lastIndexOf( '.' );
                    if ( dotPosition != -1 )
                    {
                        type = type.substring( dotPosition + 1 );
                    }
                    dict.setdefault( new PyString( type.intern( ) ),
                                     Py.java2py( clazz ) );
                }
            }

            WorkingMemory workingMemory = tuple.getWorkingMemory( );

            dict.setdefault( new PyString( "drools".intern( ) ),
                             Py.java2py( new DefaultKnowledgeHelper( this.rule,
                                                                     tuple ) ) );

            Map appDataMap = workingMemory.getApplicationDataMap( );

            for ( Iterator keyIter = appDataMap.keySet( ).iterator( ); keyIter.hasNext( ); )
            {
                String key = (String) keyIter.next( );
                Object value = appDataMap.get( key );

                dict.setdefault( new PyString( key.intern( ) ),
                                 Py.java2py( value ) );

                clazz = value.getClass( );
                type = clazz.getName( );

                nestedClassPosition = type.indexOf( '$' );

                if ( nestedClassPosition != -1 )
                {
                    type = type.substring( 0,
                                           nestedClassPosition );
                    clazz = cl.loadClass( type );
                }

                if ( type.indexOf( "java.lang" ) == -1 )
                {
                    dotPosition = type.lastIndexOf( '.' );
                    if ( dotPosition != -1 )
                    {
                        type = type.substring( dotPosition + 1 );
                    }
                    dict.setdefault( new PyString( type.intern( ) ),
                                     Py.java2py( clazz ) );
                }
            }
        }
View Full Code Here

Examples of org.python.core.PyString

        if (cause instanceof PySyntaxError) {
            // set a clear syntax error message
            PySyntaxError syntaxError = (PySyntaxError) cause;
            try {
                PyString fileName, text;
                PyInteger lineNumber, columnNumber;
                if (syntaxError.value instanceof PyTuple) {
                    PyObject[] infos = ((PyTuple) ((PyTuple) syntaxError.value).getArray()[1]).getArray();
                    fileName = (PyString) infos[0];
                    lineNumber = (PyInteger) infos[1];
                    columnNumber = (PyInteger) infos[2];
                    text = (PyString) infos[3];
                } else {
                    fileName = (PyString) syntaxError.value.__getattr__(new PyString("filename"));
                    lineNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("lineno"));
                    columnNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("offset"));
                    text = (PyString) syntaxError.value.__getattr__(new PyString("text"));
                    message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;

                }
                message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;
                result.addStackTraceElement(new StackTraceElement("", "", fileName.toString(), Integer.parseInt(lineNumber.toString())));
                dumpStack = false;
            } catch (PyException pye) {
                message = "Python syntax error (Couldn't decode localization of error)";
            }
        } else if (cause instanceof PyException) {
            PyException pe = (PyException) cause;
            if (pe.value instanceof PyJavaInstance) {
                // check  if exception is UndeclaredThrowableException
                // in this case status is "failed" and message is taken from cause exception
                Object javaError = pe.value.__tojava__(Throwable.class);
                if (javaError != null && javaError != Py.NoConversion) {
                    if (javaError instanceof QTasteException) {
                        handleQTasteException((QTasteException) javaError, result);
                        message = result.getExtraResultDetails();
                    } else if (javaError instanceof UndeclaredThrowableException) {
                        result.setStatus(TestResult.Status.FAIL);
                        Throwable undeclaredThrowable = ((UndeclaredThrowableException) javaError).getCause();
                        if (undeclaredThrowable instanceof InvocationTargetException) {
                            message = getThrowableDescription(((InvocationTargetException) undeclaredThrowable).getCause());
                        } else {
                            message = getThrowableDescription(undeclaredThrowable);
                        }
                    } else if (javaError instanceof Throwable) {
                        message = getThrowableDescription((Throwable) javaError);
                    }
                }
            }
            if (message == null) {
                if (pe.type instanceof PyClass) {
                    String errorName = null, errorValue;
                    try {
                        PyObject doc = pe.value.__getattr__(new PyString("__doc__"));
                        if (doc != Py.None) {
                            errorName = doc.toString();
                            if (errorName.endsWith(".")) {
                                errorName = errorName.substring(0, errorName.length() - 1);
                            }
View Full Code Here

Examples of org.python.core.PyString

                Iterator<?> localIt = keys.iterator();
                while (localIt.hasNext()) {
                    Object oMap = localIt.next();
                    if (oMap instanceof String) {
                        String localKey = (String) oMap;
                        Object oValue = locals.get(new PyString(localKey));
                        DebugVariable debugVar = new DebugVariable(localKey.toString(),
                                oValue.getClass().toString(), oValue.toString());
                        debugVar = dumpPythonObject(oValue, debugVar);
                        debugVariables.add(debugVar);
                    }
View Full Code Here

Examples of org.python.core.PyString

        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

Examples of org.python.core.PyString

    public Object getVariable(String name) throws Exception {
        if (mPySimulator == null) {
            logAndThrowException("Python simulator instance not loaded");
        }
        try {
            return mPySimulator.__getattr__(new PyString(name));
        } catch (PyException e) {
            logAndThrowException("Error while getting value of " + name + " variable of Python simulator instance", e);
        }
        return null; // not executed
    }
View Full Code Here

Examples of org.python.core.PyString

    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

Examples of org.python.core.PyString

            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) {
View Full Code Here

Examples of org.python.core.PyString

        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.PyString

        pxFactory = pxf;
    }

    public void start() {
        final PySystemState pss = new PySystemState();
        pss.path.insert(0, new PyString(implementation.getLocation()));
        pss.path.insert(0, new PyString(getClass().getProtectionDomain().getCodeSource().getLocation().getFile()));
        python = new PythonInterpreter(null, pss);
        python.exec("from invoker import *");

        final List<PyObject> px = new ArrayList<PyObject>();
        for(final ComponentReference r: component.getReferences()) {
            final PythonEval pe = pxFactory.createProxy(PythonEval.class, (RuntimeEndpointReference)r.getEndpointReferences().get(0));
            px.add(Py.java2py(new PythonEval() {
                @Override
                public String eval(final String args) throws Exception {
                    final String v = pe.eval(args);
                    return v;
                }
            }));
        }
        final List<PyObject> pr = new ArrayList<PyObject>();
        for(final ComponentProperty p: component.getProperties()) {
            final String v = String.valueOf(p.getValue());
            pr.add(Py.java2py(new PythonProperty() {
                @Override
                public String eval() {
                    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
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.