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

[email protected] Fri, 22 Oct 2010 01:40:33 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7163
          http://jython.svn.sourceforge.net/jython/?rev=7163&view=rev
Author:   zyasoft
Date:     2010-10-22 01:40:30 +0000 (Fri, 22 Oct 2010)

Log Message:
-----------
cPickle did not properly call import from Java, using null instead of
Py.None for globals and locals. Thanks Anselm Kruis for the patch!
Fixes #1648.

Modified Paths:
--------------
    trunk/jython/Lib/test/test_cpickle_jy.py
    trunk/jython/NEWS
    trunk/jython/src/org/python/modules/cPickle.java

Modified: trunk/jython/Lib/test/test_cpickle_jy.py
===================================================================
--- trunk/jython/Lib/test/test_cpickle_jy.py	2010-10-22 01:13:48 UTC (rev 7162)
+++ trunk/jython/Lib/test/test_cpickle_jy.py	2010-10-22 01:40:30 UTC (rev 7163)
@@ -2,6 +2,8 @@
 
 Made for Jython.
 """
+import __builtin__
+import sys
 import cPickle
 import pickle
 import unittest
@@ -70,6 +72,25 @@
         self.assertRaises(pickle.UnpicklingError, b_unpickler.load)
 
 
+    def testWithUserDefinedImport(self):
+        """test cPickle calling a user defined import function."""
+        # This tests the fix for http://bugs.jython.org/issue1665
+        # setup
+        original_import = __builtin__.__import__
+        def import_hook(name, _globals=None, locals=None, fromlist=None, level= -1):
+            return original_import(name, _globals, locals, fromlist, level)
+    
+        # test
+        __builtin__.__import__ = import_hook
+        try:
+            if "no_such_module" in sys.modules:
+                del sys.modules["no_such_module"]  # force cPickle to call __import__
+            self.assertRaises(ImportError, cPickle.loads, pickle.GLOBAL + "no_such_module\n" + "no_such_class\n")
+        finally:
+            __builtin__.__import__ = original_import
+
+
+
 def test_main():
     test_support.run_unittest(CPickleTestCase)
 

Modified: trunk/jython/NEWS
===================================================================
--- trunk/jython/NEWS	2010-10-22 01:13:48 UTC (rev 7162)
+++ trunk/jython/NEWS	2010-10-22 01:40:30 UTC (rev 7163)
@@ -2,7 +2,9 @@
 
 Jython 2.5.2rc2
   Bugs Fixed
+    - [ 1665 ] cPickle calls __import__ with illegal parameters
     - [ 1628 ] getpass.getpass echoes input
+    - Fix logic to detect that a console is interactive (related to #1133)
 
 Jython 2.5.2rc1
   Bugs Fixed
@@ -16,9 +18,8 @@
     - [ 1452 ] pydoc help() function fails because sys.executable is None in stand-alone Jython
     - [ 1568 ] sys.stdout.encoding returns wrong value in Windows with Jython 2.5.1 (fixed on Java 6 only)
     - [ 1647 ] zxJDBC does not handle NVARCHAR
+    -  SocketServer module now supports ephemeral server ports (by using port  0); see discussion for #1660
 
-   SocketServer module now supports ephemeral server ports (by using port  0); see discussion for #1660
-
 Jython 2.5.2b2
   Bugs Fixed
     - [ 1327 ] Classloaders cannot GC, which exhausts permgen (partial  bug fix)

Modified: trunk/jython/src/org/python/modules/cPickle.java
===================================================================
--- trunk/jython/src/org/python/modules/cPickle.java	2010-10-22 01:13:48 UTC (rev 7162)
+++ trunk/jython/src/org/python/modules/cPickle.java	2010-10-22 01:40:30 UTC (rev 7163)
@@ -2245,7 +2245,7 @@
 
     private static PyObject importModule(String name) {
         PyObject fromlist = new PyTuple(Py.newString("__doc__"));
-        return __builtin__.__import__(name, null, null, fromlist);
+        return __builtin__.__import__(name, Py.None, Py.None, fromlist);
     }
 
     private static PyObject getJavaFunc(String name, String methodName) {


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

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev