Message4996

Author emblemparade
Recipients emblemparade
Date 2009-08-06.13:14:22
SpamBayes Score 2.5781383e-05
Marked as misclassified No
Message-id <1249564464.1.0.847540297573.issue1426@psf.upfronthosting.co.za>
In-reply-to
Content
On second look, three more fixes are needed to take account of the
context. First, in these two methods:

    private PyCode compileScript(String script, ScriptContext context)
throws ScriptException {
        try {
            String filename = (String)
context.getAttribute(ScriptEngine.FILENAME);
            List<Integer> scopes = context.getScopes();
            for (int scope : scopes) {
            	this.context.setBindings(context.getBindings(scope), scope);
            }
            if (filename == null) {
                return interp.compile(script);
            } else {
                return interp.compile(script, filename);
            }
        } catch (PyException pye) {
            throw scriptException(pye);
        }
    }

    private PyCode compileScript(Reader reader, ScriptContext context)
throws ScriptException {
        try {
            String filename = (String)
context.getAttribute(ScriptEngine.FILENAME);
            List<Integer> scopes = context.getScopes();
            for (int scope : scopes) {
            	this.context.setBindings(context.getBindings(scope), scope);
            }
            if (filename == null) {
                return interp.compile(reader);
            } else {
                return interp.compile(reader, filename);
            }
        } catch (PyException pye) {
            throw scriptException(pye);
        }
    }

Two problems with my patch: it is not thread-safe. Also, it alters the
engine's context and does not return it to its original value. I will
try to think of a way to make it better.

Finally, this method must be overridden to allow the engine context to
change:

    public void setContext(ScriptContext context) {
    	super.setContext(context);
    	interp.setLocals(new PyScriptEngineScope(this, context));
    }
History
Date User Action Args
2009-08-06 13:14:24emblemparadesetmessageid: <1249564464.1.0.847540297573.issue1426@psf.upfronthosting.co.za>
2009-08-06 13:14:24emblemparadesetrecipients: + emblemparade
2009-08-06 13:14:24emblemparadelinkissue1426 messages
2009-08-06 13:14:23emblemparadecreate