[Zope3-checkins] CVS: Zope3/src/zope/xmlpickle - __init__.py:1.4
ppml.py:1.6 xmlpickle.py:1.4
Jim Fulton
jim at zope.com
Sun Sep 21 13:32:43 EDT 2003
Update of /cvs-repository/Zope3/src/zope/xmlpickle
In directory cvs.zope.org:/tmp/cvs-serv14034/src/zope/xmlpickle
Modified Files:
__init__.py ppml.py xmlpickle.py
Log Message:
Changed the way objects are xml-pickled to handle parent references.
=== Zope3/src/zope/xmlpickle/__init__.py 1.3 => 1.4 ===
--- Zope3/src/zope/xmlpickle/__init__.py:1.3 Tue May 6 15:58:44 2003
+++ Zope3/src/zope/xmlpickle/__init__.py Sun Sep 21 13:32:12 2003
@@ -21,3 +21,4 @@
"""
from xmlpickle import dumps, loads
+from xmlpickle import fromxml, toxml
=== Zope3/src/zope/xmlpickle/ppml.py 1.5 => 1.6 ===
--- Zope3/src/zope/xmlpickle/ppml.py:1.5 Wed Aug 20 10:49:58 2003
+++ Zope3/src/zope/xmlpickle/ppml.py Sun Sep 21 13:32:12 2003
@@ -12,6 +12,10 @@
##############################################################################
"""Provide conversion between Python pickles and XML."""
+# XXX This doesn't work properly for protocol 2 pickles yet; that
+# still needs to be dealt with. Particular issues that need to be
+# addressed involve supporting the changes for new-style objects.
+
import base64
import marshal
import re
@@ -26,6 +30,17 @@
BINPUT, LONG_BINPUT, STOP, MARK, BUILD, SETITEMS, SETITEM, \
BINPERSID, APPEND, APPENDS
+try:
+ from pickle import NEWTRUE, NEWFALSE
+except ImportError:
+ TRUE = INT + "01\n"
+ FALSE = INT + "00\n"
+ _bool_support = False
+else:
+ TRUE = NEWTRUE
+ FALSE = NEWFALSE
+ _bool_support = True
+
from cStringIO import StringIO
mdumps = marshal.dumps
@@ -199,7 +214,7 @@
# XXX use of a regular expression here seems to be brittle
-# due to fuzzy semantics of unicode "surogates".
+# due to fuzzy semantics of unicode "surrogates".
# Eventually, we should probably rewrite this as a C
# function.
@@ -387,16 +402,18 @@
class Persistent(Wrapper):
pass
-class none(Scalar):
- def __init__(self):
- pass
+class NamedScalar(Scalar):
+ def __init__(self, name):
+ self.name = name
def output(self, write, indent=0, strip=0):
- write(' '*indent+'<none/>')
+ write("%s<%s/>" % (' '*indent, self.name))
if not strip:
write('\n')
-none=none()
+none = NamedScalar("none")
+true = NamedScalar("true")
+false = NamedScalar("false")
class Reference(Scalar):
@@ -478,8 +495,26 @@
self.append(none)
dispatch[NONE] = load_none
+ if _bool_support:
+ def load_false(self):
+ self.append(false)
+ dispatch[NEWFALSE] = load_false
+
+ def load_true(self):
+ self.append(true)
+ dispatch[NEWTRUE] = load_true
+
def load_int(self):
- self.append(Int(int(self.readline()[:-1])))
+ s = self.readline()[:-1]
+ i = int(s)
+ if s[0] == "0":
+ if i == 1:
+ self.append(true)
+ return
+ elif i == 0 and s != "0": # s == "00"
+ self.append(false)
+ return
+ self.append(Int(i))
dispatch[INT] = load_int
def load_binint(self):
@@ -746,6 +781,12 @@
def none(self, tag, data, NONE_tuple = (NONE, )):
return NONE_tuple
+
+ def true(self, tag, data):
+ return TRUE,
+
+ def false(self, tag, data):
+ return FALSE,
def long(self, tag, data):
return ((LONG + ''.join(data[2:]).strip().encode('ascii') + 'L\n'), )
=== Zope3/src/zope/xmlpickle/xmlpickle.py 1.3 => 1.4 ===
--- Zope3/src/zope/xmlpickle/xmlpickle.py:1.3 Thu May 1 07:00:05 2003
+++ Zope3/src/zope/xmlpickle/xmlpickle.py Sun Sep 21 13:32:12 2003
@@ -73,7 +73,7 @@
_PicklerThatSortsDictItems(file, bin).dump(object)
return file.getvalue()
-def p2xml(p):
+def toxml(p):
"""Convert a standard Python pickle to xml
"""
u = ppml.ToXMLUnpickler(StringIO(p))
@@ -86,9 +86,9 @@
"""Serialize an object to XML
"""
p = _dumpsUsing_PicklerThatSortsDictItems(ob, 1)
- return p2xml(p)
+ return toxml(p)
-def xml2p(xml):
+def fromxml(xml):
"""Convert xml to a standard Python pickle
"""
handler = ppml.xmlPickler()
@@ -104,6 +104,6 @@
def loads(xml):
"""Create an object from serialized XML
"""
- pickle = xml2p(xml)
+ pickle = fromxml(xml)
ob = _standard_pickle_loads(pickle)
return ob
More information about the Zope3-Checkins
mailing list