Beispiel #1
0
my = foomu()
mutate.add_mutator(my)

f = foo()
f.a = UserList([4,5,6])
f.b = "abc"
#print f.a,f.b
x = xml_pickle.dumps(f)
#print x
g = xml_pickle.loads(x)
#print g.a,g.b
if g.__class__ != foo or g.a != f.a or g.b != f.b:
    raise "ERROR(7)"

mutate.remove_mutator(my)

# handcoded selfrefs from dqm that caused problems (even
# with xml_pickle-0.51)

s="""<?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject class="Spam" id="1111">
<attr name="lst" type="list" id="2222">
  <item type="PyObject" refid="1111" />
  <item type="list" refid="2222" />
</attr>
</PyObject>
"""
#print s
o2 = xml_pickle.loads(s)
Beispiel #2
0
mutate.add_mutator(my1)
mutate.add_mutator(my2)

u = UserList(['aaa','bbb','ccc'])
print u

x = xml_pickle.dumps(u)
print x
del u

z = xml_pickle.loads(x)
print z

# remove custom mutators
mutate.remove_mutator(my1)
mutate.remove_mutator(my2)

#
# test 2 -- custom pickler, but builtin unpickler
#

# use same tagname as builtin so builtin can unpickle it
# (put text in body, even though builtin puts it in
# the value= ... just to show that builtin can find it either way)

print "*** TEST 2 ***"

my1 = mystring(StringType,"string",in_body=1)
my2 = mystring(UnicodeType,"string",in_body=1)
my = foomu()
mutate.add_mutator(my)

f = foo()
f.a = UserList([4,5,6])
f.b = "abc"
#print f.a,f.b
x = xml_pickle.dumps(f)
#print x
g = xml_pickle.loads(x)
#print g.a,g.b
if g.__class__ != foo or g.a != f.a or g.b != f.b:
    raise "ERROR(7)"

mutate.remove_mutator(my)

# handcoded selfrefs from dqm that caused problems (even
# with xml_pickle-0.51)

s="""<?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject class="Spam" id="1111">
<attr name="lst" type="list" id="2222">
  <item type="PyObject" refid="1111" />
  <item type="list" refid="2222" />
</attr>
</PyObject>
"""
#print s
o2 = xml_pickle.loads(s)