### Eclipse Workspace Patch 1.0 #P jython-trunk Index: src/org/python/jsr223/PyScriptEngineScope.java =================================================================== --- src/org/python/jsr223/PyScriptEngineScope.java (revision 7168) +++ src/org/python/jsr223/PyScriptEngineScope.java (working copy) @@ -5,6 +5,7 @@ import javax.script.ScriptContext; import javax.script.ScriptEngine; import org.python.core.Py; +import org.python.core.PyIterator; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; @@ -61,6 +62,12 @@ public PyObject __getitem__(PyObject key) { return super.__getitem__(key); } + + // to satisfy iterable + @ExposedMethod + public PyObject __iter__() { + return new ScopeIter(this); + } public PyObject __finditem__(PyObject key) { return __finditem__(key.asString()); @@ -96,4 +103,31 @@ throw Py.KeyError(key); context.removeAttribute(key, scope); } + + + public class ScopeIter extends PyIterator { + + private int _index; + + private PyObject _keys; + + private PyScriptEngineScope _scope; + + ScopeIter(PyScriptEngineScope scope) { + _scope = scope; + _keys = scope.scope_keys(); + _index = -1; + } + + @Override + public PyObject __iternext__() { + PyObject result = null; + _index++; + if (_index < _keys.__len__()) { + result = _scope.__finditem__(_keys.__getitem__(_index)); + } + return result; + } + } + } Index: tests/java/org/python/jsr223/ScriptEngineTest.java =================================================================== --- tests/java/org/python/jsr223/ScriptEngineTest.java (revision 7151) +++ tests/java/org/python/jsr223/ScriptEngineTest.java (working copy) @@ -206,4 +206,18 @@ Object newStringCapitalize = invocableEngine.invokeMethod("test", "capitalize"); assertEquals(newStringCapitalize, "Test"); } + + public void testPdb() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + // String from issue 1674 + String pdbString = "from pdb import set_trace; set_trace()"; + try { + pythonEngine.eval(pdbString); + fail("bdb.BdbQuit expected"); + } catch (ScriptException e) { + assertTrue(e.getMessage().startsWith("bdb.BdbQuit")); + } + } + }