Commit 4698ec94 authored by Tim Peters's avatar Tim Peters

get_pickle_metadata(): This did crazy stuff if the ZODB pickle

started with a pickle GLOBAL opcode.  Curiously, it handled the
case of starting with a MARK GLOBAL opcode *sequence* fine.
parent cccb242e
...@@ -34,6 +34,15 @@ analyze.py produced spurious "len of unsized object" messages when ...@@ -34,6 +34,15 @@ analyze.py produced spurious "len of unsized object" messages when
finding a data record for an object uncreation or version abort. These finding a data record for an object uncreation or version abort. These
no longer appear. no longer appear.
fsdump.py's get_pickle_metadata() function (which is used by several
tools) was confused about what to do when the ZODB pickle started with
a pickle GLOBAL opcode. It actually loaded the class then, which it
intends never to do, leading to stray messages on stdout when the class
wasn't available, and leading to a strange return value even when it was
available (the repr of the type object was returned as "the module name",
and an empty string was returned as "the class name"). This has been
repaired.
What's new in ZODB3 3.3 beta 2 What's new in ZODB3 3.3 beta 2
============================== ==============================
......
from cPickle import Unpickler
from cStringIO import StringIO
import md5
import struct
from ZODB.FileStorage import FileIterator from ZODB.FileStorage import FileIterator
from ZODB.FileStorage.format \ from ZODB.FileStorage.format \
import TRANS_HDR, TRANS_HDR_LEN, DATA_HDR, DATA_HDR_LEN import TRANS_HDR, TRANS_HDR_LEN, DATA_HDR, DATA_HDR_LEN
...@@ -5,23 +10,27 @@ from ZODB.TimeStamp import TimeStamp ...@@ -5,23 +10,27 @@ from ZODB.TimeStamp import TimeStamp
from ZODB.utils import u64 from ZODB.utils import u64
from ZODB.tests.StorageTestBase import zodb_unpickle from ZODB.tests.StorageTestBase import zodb_unpickle
from cPickle import Unpickler
from cStringIO import StringIO
import md5
import struct
import types
def get_pickle_metadata(data): def get_pickle_metadata(data):
# ZODB's data records contain two pickles. The first is the class # ZODB's data records contain two pickles. The first is the class
# of the object, the second is the object. We're only trying to # of the object, the second is the object. We're only trying to
# pick apart the first here, to extract the module and class names. # pick apart the first here, to extract the module and class names.
if data.startswith('(c'): # pickle MARK GLOBAL sequence if data.startswith('(c'): # pickle MARK GLOBAL opcode sequence
global_prefix = 2
elif data.startswith('c'): # pickle GLOBAL opcode
global_prefix = 1
else:
global_prefix = 0
if global_prefix:
# Don't actually unpickle a class, because it will attempt to # Don't actually unpickle a class, because it will attempt to
# load the class. Just break open the pickle and get the # load the class. Just break open the pickle and get the
# module and class from it. # module and class from it. The module and the class names are
# given by newline-terminated strings following the GLOBAL opcode.
modname, classname, rest = data.split('\n', 2) modname, classname, rest = data.split('\n', 2)
modname = modname[2:] # strip leading '(c' modname = modname[global_prefix:] # strip GLOBAL opcode
return modname, classname return modname, classname
# Else there are a bunch of other possible formats.
f = StringIO(data) f = StringIO(data)
u = Unpickler(f) u = Unpickler(f)
try: try:
...@@ -29,8 +38,8 @@ def get_pickle_metadata(data): ...@@ -29,8 +38,8 @@ def get_pickle_metadata(data):
except Exception, err: except Exception, err:
print "Error", err print "Error", err
return '', '' return '', ''
if isinstance(class_info, types.TupleType): if isinstance(class_info, tuple):
if isinstance(class_info[0], types.TupleType): if isinstance(class_info[0], tuple):
modname, classname = class_info[0] modname, classname = class_info[0]
else: else:
modname, classname = class_info modname, classname = class_info
......
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