From: <pj...@us...> - 2011-01-22 21:25:04
|
Revision: 7188 http://jython.svn.sourceforge.net/jython/?rev=7188&view=rev Author: pjenvey Date: 2011-01-22 21:24:58 +0000 (Sat, 22 Jan 2011) Log Message: ----------- add more missing dict-like methods to the jsr223 scope. fixes the warning module under jsr223 fixes #1698 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/NEWS 2011-01-22 21:24:58 UTC (rev 7188) @@ -3,6 +3,7 @@ Jython 2.5.2 Bugs Fixed - [ 1667 ] thread.local subclasses with constructor params fail + - [ 1698 ] warnings module fails under JSR-223 Jython 2.5.2rc3 Bugs Fixed Modified: trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2011-01-22 21:24:58 UTC (rev 7188) @@ -75,7 +75,47 @@ return new ScopeIterator(this); } + @ExposedMethod(defaults = "Py.None") + final PyObject scope_get(PyObject keyObj, PyObject defaultObj) { + String key = keyObj.asString(); + int scope = context.getAttributesScope(key); + return scope == -1 ? defaultObj : Py.java2py(context.getAttribute(key, scope)); + } + + @ExposedMethod + final boolean scope_has_key(PyObject key) { + return context.getAttributesScope(key.asString()) != -1; + } + @Override + public boolean __contains__(PyObject obj) { + return scope___contains__(obj); + } + + @ExposedMethod + final boolean scope___contains__(PyObject obj) { + return scope_has_key(obj); + } + + @ExposedMethod(defaults = "Py.None") + final PyObject scope_setdefault(PyObject keyObj, PyObject failObj) { + PyObject result; + String key = keyObj.asString(); + int scope = context.getAttributesScope(key); + if (scope == -1) { + scope = ScriptContext.ENGINE_SCOPE; + context.setAttribute(key, + failObj instanceof PyType + ? failObj : failObj.__tojava__(Object.class), + scope); + result = failObj; + } else { + result = Py.java2py(context.getAttribute(key, scope)); + } + return result; + } + + @Override public String toString() { return getDictionary().toString(); } Modified: trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java =================================================================== --- trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2011-01-22 21:24:58 UTC (rev 7188) @@ -263,5 +263,13 @@ assertEquals("a string", pythonEngine.get("result")); assertEquals("a string", pythonEngine.get("result2")); } + + public void testIssue1698() throws ScriptException{ + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("import warnings"); + // Would previously fail + pythonEngine.eval("warnings.warn('test')"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |