Esempio n. 1
0
        XMLP_Mutator.__init__(self,type(foo()),'foomu')

    # careful -- type(foo) == InstanceType == "everything" :-)
    def wants_obj(self,obj):
        return obj.__class__ == foo
    
    def mutate(self,obj):
        # a tricky self-ref
        obj.breakage = obj
        return XMLP_Mutated(obj)

    def unmutate(self,mobj):
        return mobj.obj

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
Esempio n. 2
0
    def mutate(self,obj):
        print "** mystring.mutate()"
        return XMLP_Mutated(obj)

    def unmutate(self,mobj):
        print "** mystring.unmutate()"
        return mobj.obj
    
# test1 -- use our custom handler to pickle & unpickle
# (here we fold two types to a single tagname)

print "*** TEST 1 ***"
my1 = mystring(StringType,"MyString",in_body=1)
my2 = mystring(UnicodeType,"MyString",in_body=1)

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)
        XMLP_Mutator.__init__(self,type(foo()),'foomu')

    # careful -- type(foo) == InstanceType == "everything" :-)
    def wants_obj(self,obj):
        return obj.__class__ == foo
    
    def mutate(self,obj):
        # a tricky self-ref
        obj.breakage = obj
        return XMLP_Mutated(obj)

    def unmutate(self,mobj):
        return mobj.obj

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