SF.net SVN: jython:[7175] trunk/jython

[email protected] Fri, 24 Dec 2010 01:37:02 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7175
          http://jython.svn.sourceforge.net/jython/?rev=7175&view=rev
Author:   pjenvey
Date:     2010-12-24 01:37:01 +0000 (Fri, 24 Dec 2010)

Log Message:
-----------
special case type objects in the jsr223 Scope assignment as we don't want their
proxy objects
fixes #1681

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	2010-12-24 00:34:31 UTC (rev 7174)
+++ trunk/jython/NEWS	2010-12-24 01:37:01 UTC (rev 7175)
@@ -4,6 +4,7 @@
   Bugs Fixed
     - [ 1674 ] PDB crashes under the JSR-223 scripting engine
     - [ 1680 ] jython -c option is not parsed right
+    - [ 1681 ] JSR-223, Jython 2.5.2 and implementing Java Interfaces from Python
       
 Jython 2.5.2rc2
   Bugs Fixed

Modified: trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java
===================================================================
--- trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java	2010-12-24 00:34:31 UTC (rev 7174)
+++ trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java	2010-12-24 01:37:01 UTC (rev 7175)
@@ -104,7 +104,9 @@
         int scope = context.getAttributesScope(key);
         if (scope == -1)
             scope = ScriptContext.ENGINE_SCOPE;
-        context.setAttribute(key, value.__tojava__(Object.class), scope);
+        context.setAttribute(key,
+                             value instanceof PyType ? value : value.__tojava__(Object.class),
+                             scope);
     }
 
     @ExposedMethod

Modified: trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java
===================================================================
--- trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java	2010-12-24 00:34:31 UTC (rev 7174)
+++ trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java	2010-12-24 01:37:01 UTC (rev 7175)
@@ -249,5 +249,18 @@
         pythonEngine.eval("arepr = `var_a`");
         assertEquals("4", pythonEngine.get("arepr"));
     }
+
+    public void testIssue1681() throws ScriptException{
+        ScriptEngineManager manager = new ScriptEngineManager();
+        ScriptEngine pythonEngine = manager.getEngineByName("python");
+        pythonEngine.eval("import PythonCallable\n" +
+                          "class MyPythonCallable(PythonCallable):\n" +
+                          "    def getAString(self): return 'a string'\n\n" +
+                          "result = MyPythonCallable().getAString()\n" +
+                          "test = MyPythonCallable()\n" +
+                          "result2 = test.getAString()");
+        assertEquals("a string", pythonEngine.get("result"));
+        assertEquals("a string", pythonEngine.get("result2"));
+    }
     
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl