Message4996
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));
} |
|
Date |
User |
Action |
Args |
2009-08-06 13:14:24 | emblemparade | set | messageid: <1249564464.1.0.847540297573.issue1426@psf.upfronthosting.co.za> |
2009-08-06 13:14:24 | emblemparade | set | recipients:
+ emblemparade |
2009-08-06 13:14:24 | emblemparade | link | issue1426 messages |
2009-08-06 13:14:23 | emblemparade | create | |
|