From: <zy...@us...> - 2010-08-09 21:24:28
|
Revision: 7088 http://jython.svn.sourceforge.net/jython/?rev=7088&view=rev Author: zyasoft Date: 2010-08-09 21:24:20 +0000 (Mon, 09 Aug 2010) Log Message: ----------- Added support for find_global in cPickle. This fixes #1632. Thanks Alex Gr?\195?\182nholm for the patch! Modified Paths: -------------- trunk/jython/ACKNOWLEDGMENTS trunk/jython/Lib/test/test_cpickle_jy.py trunk/jython/NEWS trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/ACKNOWLEDGMENTS =================================================================== --- trunk/jython/ACKNOWLEDGMENTS 2010-08-09 20:58:24 UTC (rev 7087) +++ trunk/jython/ACKNOWLEDGMENTS 2010-08-09 21:24:20 UTC (rev 7088) @@ -90,6 +90,7 @@ Jonathan Feinberg Justin Deoliveira Costantino Cerbo + Alex Gr\xF6nholm Local Variables: mode: indented-text Modified: trunk/jython/Lib/test/test_cpickle_jy.py =================================================================== --- trunk/jython/Lib/test/test_cpickle_jy.py 2010-08-09 20:58:24 UTC (rev 7087) +++ trunk/jython/Lib/test/test_cpickle_jy.py 2010-08-09 21:24:20 UTC (rev 7088) @@ -5,6 +5,7 @@ import cPickle import pickle import unittest +from StringIO import StringIO from test import test_support class MyClass(object): @@ -34,7 +35,41 @@ m4 = iter(m3.foo).next() self.assertEqual(m4.foo, s2) + def test_find_global(self): + class A(object): + def __init__(self, x, y): + self.x = x + self.y = y + + def __eq__(self, other): + if isinstance(other, A) and self.x == other.x and self.y == other.y: + return True + return False + + class B(object): + def __init__(self, x, y): + self.x = x + self.y = y + + def restrictive_find_global(module, clsname): + if clsname == 'A': + return A + else: + raise pickle.UnpicklingError("Cannot load class", module, clsname) + + a = A("python", "C") + a_pickled = cPickle.dumps(a, 2) + a_unpickler = cPickle.Unpickler(StringIO(a_pickled)) + a_unpickler.find_global = restrictive_find_global + self.assertEqual(a_unpickler.load(), a) + + b_pickled = cPickle.dumps(B("jython", "java"), 2) + b_unpickler = cPickle.Unpickler(StringIO(b_pickled)) + b_unpickler.find_global = restrictive_find_global + self.assertRaises(pickle.UnpicklingError, b_unpickler.load) + + def test_main(): test_support.run_unittest(CPickleTestCase) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-08-09 20:58:24 UTC (rev 7087) +++ trunk/jython/NEWS 2010-08-09 21:24:20 UTC (rev 7088) @@ -2,6 +2,7 @@ Jython 2.5.2b2 Bugs Fixed + - [ 1632 ] cPickle.Unpickler does not allow assignment of find_global - [ 1395 ] PyList.indexOf() and PyTuple.indexOf() do not function properly - [ 1373 ] Jython ClassLoader getResource does not work - [ 1506 ] Jython applies PEP263 pattern for determining source-code encoding on noncomments Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2010-08-09 20:58:24 UTC (rev 7087) +++ trunk/jython/src/org/python/modules/cPickle.java 2010-08-09 21:24:20 UTC (rev 7088) @@ -1573,6 +1573,7 @@ * persistent_load(). */ public PyObject persistent_load = null; + public PyObject find_global = null; private PyObject mark = new PyString("spam"); @@ -1982,12 +1983,11 @@ final private PyObject find_class(String module, String name) { - PyObject fc = dict.__finditem__("find_global"); - if (fc != null) { - if (fc == Py.None) + if (find_global != null) { + if (find_global == Py.None) throw new PyException(UnpicklingError, "Global and instance pickles are not supported."); - return fc.__call__(new PyString(module), new PyString(name)); + return find_global.__call__(new PyString(module), new PyString(name)); } PyObject modules = Py.getSystemState().modules; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |