Commit 12e2ec98 authored by Julien Muchembled's avatar Julien Muchembled

ERP5Type: code clean-up

parent dee51dcb
...@@ -56,10 +56,9 @@ class OrderedPickler(Pickler): ...@@ -56,10 +56,9 @@ class OrderedPickler(Pickler):
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() item_list = obj.items()
key_list.sort() # Order keys item_list.sort()
obj_items = map(lambda x: (x, obj[x]), key_list) # XXX Make it lazy in the future self._batch_setitems(iter(item_list))
self._batch_setitems(obj_items)
dispatch[DictionaryType] = save_dict dispatch[DictionaryType] = save_dict
if not PyStringMap is None: if not PyStringMap is None:
......
...@@ -20,44 +20,13 @@ from base64 import encodestring ...@@ -20,44 +20,13 @@ from base64 import encodestring
from cStringIO import StringIO from cStringIO import StringIO
from ZODB.serialize import referencesf from ZODB.serialize import referencesf
from ZODB.ExportImport import TemporaryFile from ZODB.ExportImport import TemporaryFile
from pickle import Pickler, EMPTY_DICT, MARK, DICT
from cPickle import loads, dumps
from types import TupleType from types import TupleType
from types import StringType
from types import DictionaryType
from OFS import ObjectManager, XMLExportImport from OFS import ObjectManager, XMLExportImport
from ..XMLExportImport import OrderedPickler
from logging import getLogger from logging import getLogger
log = getLogger(__name__) log = getLogger(__name__)
# Jython has PyStringMap; it's a dict subclass with string keys
try:
from org.python.core import PyStringMap
except ImportError:
PyStringMap = None
# Ordered pickles
class OrderedPickler(Pickler):
dispatch = Pickler.dispatch.copy()
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)
item_list = obj.items() # New version by JPS for sorting
item_list.sort(key=lambda x: x[0]) # New version by JPS for sorting
self._batch_setitems(item_list.__iter__())
dispatch[DictionaryType] = save_dict
if not PyStringMap is None:
dispatch[PyStringMap] = save_dict
def reorderPickle(jar, p): def reorderPickle(jar, p):
try: try:
from ZODB._compat import Unpickler, Pickler from ZODB._compat import Unpickler, Pickler
......
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