Commit 7263b5c6 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Make sure we produce canonical pickles


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@998 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 19a9d287
......@@ -31,11 +31,35 @@ from Acquisition import aq_base, aq_inner
from cStringIO import StringIO
from email.MIMEBase import MIMEBase
from email import Encoders
import pickle
from pickle import Pickler
from xml.sax.saxutils import escape, unescape
from zLOG import LOG
class OrderedPickler(Pickler):
def save_dict(self, obj):
write = self.write
if self.bin:
write(EMPTY_DICT)
else: # proto 0 -- can't use EMPTY_DICT
write(MARK + DICT)
self.memoize(obj)
key_list = obj.keys()
key_list.sort() # Order keys
obj_items = map(lambda x: (x, obj[x]), obj) # XXX Make it lazy in the future
self._batch_setitems(obj_items)
# ERP5 specific pickle function - produces ordered pickles
def dumps(obj, protocol=None, bin=None):
file = StringIO()
OrderedPickler(file, protocol, bin).dump(obj)
return file.getvalue()
def Base_asXML(object, ident=0):
"""
Generate an xml text corresponding to the content of this object
......
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