[Checkins] SVN: zope.xmlpickle/trunk/src/zope/xmlpickle/xmlpickle.py started removing 'from' imports
Thomas Lotze
tl at gocept.com
Wed Dec 15 09:01:38 EST 2010
Log message for revision 118932:
started removing 'from' imports
Changed:
U zope.xmlpickle/trunk/src/zope/xmlpickle/xmlpickle.py
-=-
Modified: zope.xmlpickle/trunk/src/zope/xmlpickle/xmlpickle.py
===================================================================
--- zope.xmlpickle/trunk/src/zope/xmlpickle/xmlpickle.py 2010-12-15 13:56:54 UTC (rev 118931)
+++ zope.xmlpickle/trunk/src/zope/xmlpickle/xmlpickle.py 2010-12-15 14:01:38 UTC (rev 118932)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2002 Zope Foundation and Contributors.
+# Copyright (c) 2002-2010 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -19,18 +19,19 @@
from cStringIO import StringIO
from cPickle import loads as _standard_pickle_loads
from pickle import \
- Pickler as _StandardPickler, \
MARK as _MARK, \
EMPTY_DICT as _EMPTY_DICT, \
DICT as _DICT, \
SETITEM as _SETITEM, \
SETITEMS as _SETITEMS
-
from zope.xmlpickle import ppml
+import pickle
-class _PicklerThatSortsDictItems(_StandardPickler):
+
+class _PicklerThatSortsDictItems(pickle.Pickler):
+
dispatch = {}
- dispatch.update(_StandardPickler.dispatch)
+ dispatch.update(pickle.Pickler.dispatch)
def save_dict(self, object):
d = id(object)
@@ -67,11 +68,13 @@
dispatch[dict] = save_dict
+
def _dumpsUsing_PicklerThatSortsDictItems(object, bin = 0):
file = StringIO()
_PicklerThatSortsDictItems(file, bin).dump(object)
return file.getvalue()
+
def toxml(p, index=0):
"""Convert a standard Python pickle to xml
@@ -95,7 +98,7 @@
>>> s = f.getvalue()
You can supply indexes to access individual pickles:
-
+
>>> print toxml(s).strip()
<?xml version="1.0" encoding="utf-8" ?>
<pickle>
@@ -138,13 +141,15 @@
r = ['<?xml version="1.0" encoding="utf-8" ?>\n']
xmlob.output(r.append)
return ''.join(r)
-
+
+
def dumps(ob):
"""Serialize an object to XML
"""
p = _dumpsUsing_PicklerThatSortsDictItems(ob, 1)
return toxml(p)
+
def fromxml(xml):
"""Convert xml to a standard Python pickle
"""
@@ -158,6 +163,7 @@
pickle = str(pickle)
return pickle
+
def loads(xml):
"""Create an object from serialized XML
"""
More information about the checkins
mailing list