Commit abad361f authored by Marius Gedminas's avatar Marius Gedminas

Try to push persistentclass along

Problem: in Python 2 object lives in sys.modules['__builtin__'].  In
Python 3 it lives in sys.modules['builtins'].  When we pickle object in
Python 2 and try to load it in Python 3, we end up getting a Broken
object placeholder because sys.modules['__builtin__'] is AWOL.

I'm not sure how persistentclass.txt manages to reproduce that purely in
Python 3, but that's what the new assertion failure I added reports.

Oh, I know: old pickle protocol!

    Python 3.3.0 (default, Sep 29 2012, 17:14:58)
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pickle
    >>> pickle.dumps(object)
    b'\x80\x03cbuiltins\nobject\nq\x00.'
    >>> pickle.dumps(object, 1)
    b'c__builtin__\nobject\nq\x00.'
    >>> pickle.loads(_)
    <class 'object'>

We need to find the mapping layer that handles __builtin__ in Python
3.3's pickle and make sure our own ZODB.broken.find_global can do the
same.
parent 9f93b7f5
...@@ -191,7 +191,10 @@ class PersistentMetaClass(type): ...@@ -191,7 +191,10 @@ class PersistentMetaClass(type):
__getstate__ = _p_MethodDescr(__getstate__) __getstate__ = _p_MethodDescr(__getstate__)
def __setstate__(self, state): def __setstate__(self, state):
self.__bases__, cdict = state bases, cdict = state
if self.__bases__ != bases:
# __getnewargs__ should've taken care of that
raise AssertionError(self.__bases__, '!=', bases)
cdict = dict([(k, v) for (k, v) in cdict.items() cdict = dict([(k, v) for (k, v) in cdict.items()
if not k.startswith('_p_')]) if not k.startswith('_p_')])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment