Commit f3a5bd3b authored by Jean-Paul Smets's avatar Jean-Paul Smets

bugfixes


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